Changeset View
Changeset View
Standalone View
Standalone View
test/functional/wallet_balance.py
Show First 20 Lines • Show All 99 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
# First argument of getbalance must be set to "*" | # First argument of getbalance must be set to "*" | ||||
assert_raises_rpc_error(-32, "dummy first argument must be excluded or set to \"*\"", | assert_raises_rpc_error(-32, "dummy first argument must be excluded or set to \"*\"", | ||||
self.nodes[1].getbalance, "") | self.nodes[1].getbalance, "") | ||||
self.log.info( | self.log.info( | ||||
"Test getbalance and getunconfirmedbalance with unconfirmed inputs") | "Test getbalance and getunconfirmedbalance with unconfirmed inputs") | ||||
# getbalance without any arguments includes unconfirmed transactions, | def test_balances(*, fee_node_1=0): | ||||
# but not untrusted transactions | # getbalance without any arguments includes unconfirmed transactions, but not untrusted transactions | ||||
assert_equal(self.nodes[0].getbalance(), Decimal( | # change from node 0's send | ||||
'9.99')) # change from node 0's send | assert_equal(self.nodes[0].getbalance(), Decimal('9.99')) | ||||
assert_equal(self.nodes[1].getbalance(), Decimal( | # change from node 1's send | ||||
'29.99')) # change from node 1's send | assert_equal( | ||||
self.nodes[1].getbalance(), | |||||
Decimal('30') - fee_node_1) | |||||
# Same with minconf=0 | # Same with minconf=0 | ||||
assert_equal(self.nodes[0].getbalance(minconf=0), Decimal('9.99')) | assert_equal(self.nodes[0].getbalance(minconf=0), Decimal('9.99')) | ||||
assert_equal(self.nodes[1].getbalance(minconf=0), Decimal('29.99')) | assert_equal( | ||||
self.nodes[1].getbalance( | |||||
minconf=0), | |||||
Decimal('30') - | |||||
fee_node_1) | |||||
# getbalance with a minconf incorrectly excludes coins that have been spent more recently than the minconf blocks ago | # getbalance with a minconf incorrectly excludes coins that have been spent more recently than the minconf blocks ago | ||||
# TODO: fix getbalance tracking of coin spentness depth | # TODO: fix getbalance tracking of coin spentness depth | ||||
assert_equal(self.nodes[0].getbalance(minconf=1), Decimal('0')) | assert_equal(self.nodes[0].getbalance(minconf=1), Decimal('0')) | ||||
assert_equal(self.nodes[1].getbalance(minconf=1), Decimal('0')) | assert_equal(self.nodes[1].getbalance(minconf=1), Decimal('0')) | ||||
# getunconfirmedbalance | # getunconfirmedbalance | ||||
# output of node 1's spend | # output of node 1's spend | ||||
assert_equal(self.nodes[0].getunconfirmedbalance(), Decimal('60')) | assert_equal(self.nodes[0].getunconfirmedbalance(), 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 | # Doesn't include output of node 0's send since it was spent | ||||
assert_equal(self.nodes[1].getunconfirmedbalance(), Decimal('0')) | assert_equal(self.nodes[1].getunconfirmedbalance(), Decimal('0')) | ||||
assert_equal(self.nodes[1].getwalletinfo()[ | |||||
"unconfirmed_balance"], Decimal('0')) | |||||
test_balances(fee_node_1=Decimal('0.01')) | |||||
# In the original Core version of this test, Node 1 would've bumped | # In the original Core version of this test, Node 1 would've bumped | ||||
# the fee by 0.01 here to resend, but this is BCH, so it has 0.01 BCH | # the fee by 0.01 here to resend, but this is BCH, so it has 0.01 BCH | ||||
# left to spend on goods and services | # left to spend on goods and services | ||||
self.sync_all() | self.sync_all() | ||||
self.log.info( | self.log.info( | ||||
"Test getbalance and getunconfirmedbalance with conflicted unconfirmed inputs") | "Test getbalance and getunconfirmedbalance with conflicted unconfirmed inputs") | ||||
test_balances(fee_node_1=Decimal('0.01')) | |||||
# output of node 1's send | # output of node 1's send | ||||
assert_equal(self.nodes[0].getwalletinfo()[ | assert_equal(self.nodes[0].getwalletinfo()[ | ||||
"unconfirmed_balance"], Decimal('60')) | "unconfirmed_balance"], Decimal('60')) | ||||
assert_equal(self.nodes[0].getunconfirmedbalance(), Decimal('60')) | assert_equal(self.nodes[0].getunconfirmedbalance(), Decimal('60')) | ||||
# Doesn't include output of node 0's send since it was spent | # Doesn't include output of node 0's send since it was spent | ||||
assert_equal(self.nodes[1].getwalletinfo()[ | assert_equal(self.nodes[1].getwalletinfo()[ | ||||
"unconfirmed_balance"], Decimal('0')) | "unconfirmed_balance"], Decimal('0')) | ||||
Show All 40 Lines |