diff --git a/test/functional/wallet_abandonconflict.py b/test/functional/wallet_abandonconflict.py --- a/test/functional/wallet_abandonconflict.py +++ b/test/functional/wallet_abandonconflict.py @@ -138,9 +138,11 @@ # Unconfirmed received funds that are not in mempool also shouldn't show # up in unconfirmed balance. Note that the transactions stored in the wallet # are not necessarily in the node's mempool. - unconfbalance = self.nodes[0].getunconfirmedbalance( - ) + self.nodes[0].getbalance() - assert_equal(unconfbalance, newbalance) + balances = self.nodes[0].getbalances()['mine'] + assert_equal( + balances['untrusted_pending'] + + balances['trusted'], + newbalance) # Unconfirmed transactions which are not in the mempool should also # not be in listunspent assert txABC2 not in [utxo["txid"] diff --git a/test/functional/wallet_address_types.py b/test/functional/wallet_address_types.py --- a/test/functional/wallet_address_types.py +++ b/test/functional/wallet_address_types.py @@ -65,12 +65,9 @@ connect_nodes(self.nodes[i], self.nodes[j]) self.sync_all() - def get_balances(self, confirmed=True): - """Return a list of confirmed or unconfirmed balances.""" - if confirmed: - return [self.nodes[i].getbalance() for i in range(4)] - else: - return [self.nodes[i].getunconfirmedbalance() for i in range(4)] + def get_balances(self, key='trusted'): + """Return a list of balances.""" + return [self.nodes[i].getbalances()['mine'][key] for i in range(4)] def test_address(self, node, address, multisig, typ): """Run sanity checks on an address.""" @@ -239,7 +236,7 @@ self.nodes[from_node].sendmany("", sends) self.sync_mempools() - unconf_balances = self.get_balances(False) + unconf_balances = self.get_balances('untrusted_pending') self.log.debug( "Check unconfirmed balances: {}".format(unconf_balances)) assert_equal(unconf_balances[from_node], 0) diff --git a/test/functional/wallet_balance.py b/test/functional/wallet_balance.py --- a/test/functional/wallet_balance.py +++ b/test/functional/wallet_balance.py @@ -124,8 +124,7 @@ assert_raises_rpc_error(-32, "dummy first argument must be excluded or set to \"*\"", self.nodes[1].getbalance, "") - self.log.info( - "Test getbalance and getunconfirmedbalance with unconfirmed inputs") + self.log.info("Test balances with unconfirmed inputs") # Before `test_balance()`, we have had two nodes with a balance of 50 # each and then we: @@ -165,6 +164,22 @@ # replaced. def test_balances(*, fee_node_1=0): + # getbalances + expected_balances_0 = {'mine': {'immature': Decimal('0E-8'), + # change from node 0's send + 'trusted': Decimal('9.99'), + 'untrusted_pending': Decimal('60.0')}, + 'watchonly': {'immature': Decimal('5000'), + 'trusted': Decimal('50.0'), + 'untrusted_pending': Decimal('0E-8')}} + expected_balances_1 = {'mine': {'immature': Decimal('0E-8'), + # node 1's send had an unsafe input + 'trusted': Decimal('0E-8'), + # Doesn't include output of node + # 0's send since it was spent + 'untrusted_pending': Decimal('30.0') - fee_node_1}} + assert_equal(self.nodes[0].getbalances(), expected_balances_0) + assert_equal(self.nodes[1].getbalances(), expected_balances_1) # getbalance without any arguments includes unconfirmed transactions, but not untrusted transactions # change from node 0's send assert_equal(self.nodes[0].getbalance(), Decimal('9.99')) @@ -180,18 +195,14 @@ # getunconfirmedbalance # output of node 1's spend assert_equal(self.nodes[0].getunconfirmedbalance(), Decimal('60')) - assert_equal(self.nodes[0].getbalances()['mine'] - ['untrusted_pending'], Decimal('60')) - assert_equal(self.nodes[0].getwalletinfo()[ - "unconfirmed_balance"], Decimal('60')) # Doesn't include output of node 0's send since it was spent assert_equal( self.nodes[1].getunconfirmedbalance(), Decimal('30') - fee_node_1) - assert_equal( - self.nodes[1].getbalances()['mine']['untrusted_pending'], - Decimal('30') - fee_node_1) + # getwalletinfo.unconfirmed_balance + assert_equal(self.nodes[0].getwalletinfo()[ + "unconfirmed_balance"], Decimal('60')) assert_equal( self.nodes[1].getwalletinfo()["unconfirmed_balance"], Decimal('30') - fee_node_1) @@ -204,7 +215,7 @@ self.sync_all() self.log.info( - "Test getbalance and getunconfirmedbalance with conflicted unconfirmed inputs") + "Test getbalance and getbalances.mine.untrusted_pending with conflicted unconfirmed inputs") test_balances(fee_node_1=Decimal('0.01')) self.nodes[1].generatetoaddress(1, ADDRESS_WATCHONLY) @@ -212,9 +223,15 @@ # balances are correct after the transactions are confirmed # node 1's send plus change from node 0's send - assert_equal(self.nodes[0].getbalance(), Decimal('69.99')) - assert_equal(self.nodes[1].getbalance(), Decimal( - '29.99')) # change from node 0's send + balance_node0 = Decimal('69.99') + # change from node 0's send + balance_node1 = Decimal('29.99') + assert_equal(self.nodes[0].getbalances()[ + 'mine']['trusted'], balance_node0) + assert_equal(self.nodes[1].getbalances()[ + 'mine']['trusted'], balance_node1) + assert_equal(self.nodes[0].getbalance(), balance_node0) + assert_equal(self.nodes[1].getbalance(), balance_node1) # Send total balance away from node 1 txs = create_transactions(self.nodes[1], self.nodes[0].getnewaddress( @@ -233,13 +250,13 @@ # check mempool transactions count for wallet unconfirmed balance after # dynamically loading the wallet. - before = self.nodes[1].getunconfirmedbalance() + before = self.nodes[1].getbalances()['mine']['untrusted_pending'] dst = self.nodes[1].getnewaddress() self.nodes[1].unloadwallet('') self.nodes[0].sendtoaddress(dst, 0.1) self.sync_all() self.nodes[1].loadwallet('') - after = self.nodes[1].getunconfirmedbalance() + after = self.nodes[1].getbalances()['mine']['untrusted_pending'] assert_equal(before + Decimal('0.1'), after) # Create 3 more wallet txs, where the last is not accepted to the