aboutsummaryrefslogtreecommitdiff
path: root/test/functional/wallet_balance.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/wallet_balance.py')
-rwxr-xr-xtest/functional/wallet_balance.py36
1 files changed, 25 insertions, 11 deletions
diff --git a/test/functional/wallet_balance.py b/test/functional/wallet_balance.py
index a5f9a047ed..8efa66a856 100755
--- a/test/functional/wallet_balance.py
+++ b/test/functional/wallet_balance.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
-# Copyright (c) 2018-2019 The Bitcoin Core developers
+# Copyright (c) 2018-2020 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test the wallet balance RPC methods."""
@@ -107,7 +107,7 @@ class WalletTest(BitcoinTestFramework):
# First argument of getbalance must be set to "*"
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:
@@ -148,6 +148,18 @@ class WalletTest(BitcoinTestFramework):
def test_balances(*, fee_node_1=0):
+ # getbalances
+ expected_balances_0 = {'mine': {'immature': Decimal('0E-8'),
+ 'trusted': Decimal('9.99'), # change from node 0's send
+ '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'),
+ 'trusted': Decimal('0E-8'), # node 1's send had an unsafe input
+ 'untrusted_pending': Decimal('30.0') - fee_node_1}} # Doesn't include output of node 0's send since it was spent
+ 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
assert_equal(self.nodes[0].getbalance(), Decimal('9.99')) # change from node 0's send
assert_equal(self.nodes[1].getbalance(), Decimal('0')) # node 1's send had an unsafe input
@@ -160,11 +172,9 @@ class WalletTest(BitcoinTestFramework):
assert_equal(self.nodes[1].getbalance(minconf=1), Decimal('0'))
# getunconfirmedbalance
assert_equal(self.nodes[0].getunconfirmedbalance(), Decimal('60')) # output of node 1's spend
- assert_equal(self.nodes[0].getbalances()['mine']['untrusted_pending'], Decimal('60'))
- assert_equal(self.nodes[0].getwalletinfo()["unconfirmed_balance"], Decimal('60'))
-
assert_equal(self.nodes[1].getunconfirmedbalance(), Decimal('30') - fee_node_1) # Doesn't include output of node 0's send since it was spent
- 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)
test_balances(fee_node_1=Decimal('0.01'))
@@ -174,15 +184,19 @@ class WalletTest(BitcoinTestFramework):
self.nodes[0].sendrawtransaction(txs[1]['hex']) # sending on both nodes is faster than waiting for propagation
self.sync_all()
- self.log.info("Test getbalance and getunconfirmedbalance with conflicted unconfirmed inputs")
+ self.log.info("Test getbalance and getbalances.mine.untrusted_pending with conflicted unconfirmed inputs")
test_balances(fee_node_1=Decimal('0.02'))
self.nodes[1].generatetoaddress(1, ADDRESS_WATCHONLY)
self.sync_all()
# balances are correct after the transactions are confirmed
- assert_equal(self.nodes[0].getbalance(), Decimal('69.99')) # node 1's send plus change from node 0's send
- assert_equal(self.nodes[1].getbalance(), Decimal('29.98')) # change from node 0's send
+ balance_node0 = Decimal('69.99') # node 1's send plus change from node 0's send
+ balance_node1 = Decimal('29.98') # change from node 0's send
+ 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(), Decimal('29.97'), [Decimal('0.01')])
@@ -200,13 +214,13 @@ class WalletTest(BitcoinTestFramework):
# 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