Changeset View
Changeset View
Standalone View
Standalone View
test/functional/wallet_balance.py
Show All 11 Lines | |||||
FAR_IN_THE_FUTURE = 2000000000 | FAR_IN_THE_FUTURE = 2000000000 | ||||
def create_transactions(node, address, amt, fees): | def create_transactions(node, address, amt, fees): | ||||
# Create and sign raw transactions from node to address for amt. | # Create and sign raw transactions from node to address for amt. | ||||
# Creates a transaction for each fee and returns an array | # Creates a transaction for each fee and returns an array | ||||
# of the raw transactions. | # of the raw transactions. | ||||
utxos = [u for u in node.listunspent(0) if u['spendable']] | utxos = [u for u in node.listunspent(0) if u["spendable"]] | ||||
# Create transactions | # Create transactions | ||||
inputs = [] | inputs = [] | ||||
ins_total = 0 | ins_total = 0 | ||||
for utxo in utxos: | for utxo in utxos: | ||||
inputs.append({"txid": utxo["txid"], "vout": utxo["vout"]}) | inputs.append({"txid": utxo["txid"], "vout": utxo["vout"]}) | ||||
ins_total += utxo['amount'] | ins_total += utxo["amount"] | ||||
if ins_total >= amt + max(fees): | if ins_total >= amt + max(fees): | ||||
break | break | ||||
# make sure there was enough utxos | # make sure there was enough utxos | ||||
assert ins_total >= amt + max(fees) | assert ins_total >= amt + max(fees) | ||||
txs = [] | txs = [] | ||||
for fee in fees: | for fee in fees: | ||||
outputs = {address: amt} | outputs = {address: amt} | ||||
# prevent 0 change output | # prevent 0 change output | ||||
if ins_total > amt + fee: | if ins_total > amt + fee: | ||||
outputs[node.getrawchangeaddress()] = ins_total - amt - fee | outputs[node.getrawchangeaddress()] = ins_total - amt - fee | ||||
raw_tx = node.createrawtransaction(inputs, outputs, 0) | raw_tx = node.createrawtransaction(inputs, outputs, 0) | ||||
raw_tx = node.signrawtransactionwithwallet(raw_tx) | raw_tx = node.signrawtransactionwithwallet(raw_tx) | ||||
assert_equal(raw_tx['complete'], True) | assert_equal(raw_tx["complete"], True) | ||||
txs.append(raw_tx) | txs.append(raw_tx) | ||||
return txs | return txs | ||||
class WalletTest(BitcoinTestFramework): | class WalletTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.num_nodes = 2 | self.num_nodes = 2 | ||||
self.setup_clean_chain = True | self.setup_clean_chain = True | ||||
self.extra_args = [ | self.extra_args = [ | ||||
# Limit mempool descendants as a hack to have wallet txs rejected | # Limit mempool descendants as a hack to have wallet txs rejected | ||||
# from the mempool. This will no longer work after wellington, so | # from the mempool. This will no longer work after wellington, so | ||||
# move the activation in the future for this test. | # move the activation in the future for this test. | ||||
['-limitdescendantcount=3', | [ | ||||
f'-wellingtonactivationtime={FAR_IN_THE_FUTURE}', | "-limitdescendantcount=3", | ||||
f"-wellingtonactivationtime={FAR_IN_THE_FUTURE}", | |||||
], | ], | ||||
[], | [], | ||||
] | ] | ||||
# whitelist peers to speed up tx relay / mempool sync | # whitelist peers to speed up tx relay / mempool sync | ||||
for args in self.extra_args: | for args in self.extra_args: | ||||
args.append("-whitelist=noban@127.0.0.1") | args.append("-whitelist=noban@127.0.0.1") | ||||
def skip_test_if_missing_module(self): | def skip_test_if_missing_module(self): | ||||
self.skip_if_no_wallet() | self.skip_if_no_wallet() | ||||
def run_test(self): | def run_test(self): | ||||
if not self.options.descriptors: | if not self.options.descriptors: | ||||
# Tests legacy watchonly behavior which is not present (and does | # Tests legacy watchonly behavior which is not present (and does | ||||
# not need to be tested) in descriptor wallets | # not need to be tested) in descriptor wallets | ||||
self.nodes[0].importaddress(ADDRESS_WATCHONLY) | self.nodes[0].importaddress(ADDRESS_WATCHONLY) | ||||
# Check that nodes don't own any UTXOs | # Check that nodes don't own any UTXOs | ||||
assert_equal(len(self.nodes[0].listunspent()), 0) | assert_equal(len(self.nodes[0].listunspent()), 0) | ||||
assert_equal(len(self.nodes[1].listunspent()), 0) | assert_equal(len(self.nodes[1].listunspent()), 0) | ||||
self.log.info("Check that only node 0 is watching an address") | self.log.info("Check that only node 0 is watching an address") | ||||
assert 'watchonly' in self.nodes[0].getbalances() | assert "watchonly" in self.nodes[0].getbalances() | ||||
assert 'watchonly' not in self.nodes[1].getbalances() | assert "watchonly" not in self.nodes[1].getbalances() | ||||
self.log.info("Mining blocks ...") | self.log.info("Mining blocks ...") | ||||
self.generate(self.nodes[0], 1) | self.generate(self.nodes[0], 1) | ||||
self.generate(self.nodes[1], 1) | self.generate(self.nodes[1], 1) | ||||
self.generatetoaddress(self.nodes[1], 101, ADDRESS_WATCHONLY) | self.generatetoaddress(self.nodes[1], 101, ADDRESS_WATCHONLY) | ||||
if not self.options.descriptors: | if not self.options.descriptors: | ||||
# Tests legacy watchonly behavior which is not present (and does not | # Tests legacy watchonly behavior which is not present (and does not | ||||
# need to be tested) in descriptor wallets | # need to be tested) in descriptor wallets | ||||
assert_equal(self.nodes[0].getbalances()['mine']['trusted'], | assert_equal(self.nodes[0].getbalances()["mine"]["trusted"], 50000000) | ||||
50000000) | assert_equal(self.nodes[0].getwalletinfo()["balance"], 50000000) | ||||
assert_equal(self.nodes[0].getwalletinfo()['balance'], 50000000) | assert_equal(self.nodes[1].getbalances()["mine"]["trusted"], 50000000) | ||||
assert_equal(self.nodes[1].getbalances()['mine']['trusted'], | |||||
50000000) | assert_equal( | ||||
self.nodes[0].getbalances()["watchonly"]["immature"], 5000000000 | |||||
assert_equal(self.nodes[0].getbalances()['watchonly']['immature'], | ) | ||||
5000000000) | assert "watchonly" not in self.nodes[1].getbalances() | ||||
assert 'watchonly' not in self.nodes[1].getbalances() | |||||
assert_equal(self.nodes[0].getbalance(), 50000000) | assert_equal(self.nodes[0].getbalance(), 50000000) | ||||
assert_equal(self.nodes[1].getbalance(), 50000000) | assert_equal(self.nodes[1].getbalance(), 50000000) | ||||
self.log.info("Test getbalance with different arguments") | self.log.info("Test getbalance with different arguments") | ||||
assert_equal(self.nodes[0].getbalance("*"), 50000000) | assert_equal(self.nodes[0].getbalance("*"), 50000000) | ||||
assert_equal(self.nodes[0].getbalance("*", 1), 50000000) | assert_equal(self.nodes[0].getbalance("*", 1), 50000000) | ||||
assert_equal(self.nodes[0].getbalance(minconf=1), 50000000) | assert_equal(self.nodes[0].getbalance(minconf=1), 50000000) | ||||
if not self.options.descriptors: | if not self.options.descriptors: | ||||
assert_equal(self.nodes[0].getbalance(minconf=0, | assert_equal( | ||||
include_watchonly=True), | self.nodes[0].getbalance(minconf=0, include_watchonly=True), 100_000_000 | ||||
100_000_000) | ) | ||||
assert_equal(self.nodes[0].getbalance("*", 1, True), 100_000_000) | assert_equal(self.nodes[0].getbalance("*", 1, True), 100_000_000) | ||||
else: | else: | ||||
assert_equal(self.nodes[0].getbalance(minconf=0, | assert_equal( | ||||
include_watchonly=True), | self.nodes[0].getbalance(minconf=0, include_watchonly=True), 50_000_000 | ||||
50_000_000) | ) | ||||
assert_equal(self.nodes[0].getbalance("*", 1, True), 50_000_000) | assert_equal(self.nodes[0].getbalance("*", 1, True), 50_000_000) | ||||
assert_equal( | assert_equal( | ||||
self.nodes[1].getbalance( | self.nodes[1].getbalance(minconf=0, include_watchonly=True), 50000000 | ||||
minconf=0, | ) | ||||
include_watchonly=True), | |||||
50000000) | |||||
# Send 40 BTC from 0 to 1 and 60 BTC from 1 to 0. | # Send 40 BTC from 0 to 1 and 60 BTC from 1 to 0. | ||||
txs = create_transactions( | txs = create_transactions( | ||||
self.nodes[0], self.nodes[1].getnewaddress(), 40000000, [Decimal('10000')]) | self.nodes[0], self.nodes[1].getnewaddress(), 40000000, [Decimal("10000")] | ||||
self.nodes[0].sendrawtransaction(txs[0]['hex']) | ) | ||||
self.nodes[0].sendrawtransaction(txs[0]["hex"]) | |||||
# sending on both nodes is faster than waiting for propagation | # sending on both nodes is faster than waiting for propagation | ||||
self.nodes[1].sendrawtransaction(txs[0]['hex']) | self.nodes[1].sendrawtransaction(txs[0]["hex"]) | ||||
self.sync_all() | self.sync_all() | ||||
txs = create_transactions(self.nodes[1], self.nodes[0].getnewaddress(), 60000000, [ | txs = create_transactions( | ||||
Decimal('10000'), Decimal('20000')]) | self.nodes[1], | ||||
self.nodes[1].sendrawtransaction(txs[0]['hex']) | self.nodes[0].getnewaddress(), | ||||
60000000, | |||||
[Decimal("10000"), Decimal("20000")], | |||||
) | |||||
self.nodes[1].sendrawtransaction(txs[0]["hex"]) | |||||
# sending on both nodes is faster than waiting for propagation | # sending on both nodes is faster than waiting for propagation | ||||
self.nodes[0].sendrawtransaction(txs[0]['hex']) | self.nodes[0].sendrawtransaction(txs[0]["hex"]) | ||||
self.sync_all() | self.sync_all() | ||||
# 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( | ||||
self.nodes[1].getbalance, "") | -32, | ||||
'dummy first argument must be excluded or set to "*"', | |||||
self.nodes[1].getbalance, | |||||
"", | |||||
) | |||||
self.log.info("Test balances with unconfirmed inputs") | self.log.info("Test balances with unconfirmed inputs") | ||||
# Before `test_balance()`, we have had two nodes with a balance of 50 | # Before `test_balance()`, we have had two nodes with a balance of 50 | ||||
# each and then we: | # each and then we: | ||||
# | # | ||||
# 1) Sent 40 from node A to node B with fee 0.01 | # 1) Sent 40 from node A to node B with fee 0.01 | ||||
# 2) Sent 60 from node B to node A with fee 0.01 | # 2) Sent 60 from node B to node A with fee 0.01 | ||||
Show All 26 Lines | def run_test(self): | ||||
# 2) Sent 10 from node B to node A with fee 0.01 | # 2) Sent 10 from node B to node A with fee 0.01 | ||||
# | # | ||||
# Then our node would report a confirmed balance of 40 + 50 - 10 = 80 | # Then our node would report a confirmed balance of 40 + 50 - 10 = 80 | ||||
# BTC, which is more than would be available if transaction 1 were | # BTC, which is more than would be available if transaction 1 were | ||||
# replaced. | # replaced. | ||||
def test_balances(*, fee_node_1=0): | def test_balances(*, fee_node_1=0): | ||||
# getbalances | # getbalances | ||||
expected_balances_0 = {'mine': {'immature': Decimal('0E-2'), | expected_balances_0 = { | ||||
"mine": { | |||||
"immature": Decimal("0E-2"), | |||||
# change from node 0's send | # change from node 0's send | ||||
'trusted': Decimal('9990000'), | "trusted": Decimal("9990000"), | ||||
'untrusted_pending': Decimal('60000000.0')}, | "untrusted_pending": Decimal("60000000.0"), | ||||
'watchonly': {'immature': Decimal('5000000000'), | }, | ||||
'trusted': Decimal('50000000.0'), | "watchonly": { | ||||
'untrusted_pending': Decimal('0E-2')}} | "immature": Decimal("5000000000"), | ||||
expected_balances_1 = {'mine': {'immature': Decimal('0E-2'), | "trusted": Decimal("50000000.0"), | ||||
"untrusted_pending": Decimal("0E-2"), | |||||
}, | |||||
} | |||||
expected_balances_1 = { | |||||
"mine": { | |||||
"immature": Decimal("0E-2"), | |||||
# node 1's send had an unsafe input | # node 1's send had an unsafe input | ||||
'trusted': Decimal('0E-2'), | "trusted": Decimal("0E-2"), | ||||
# Doesn't include output of node | # Doesn't include output of node | ||||
# 0's send since it was spent | # 0's send since it was spent | ||||
'untrusted_pending': Decimal('30000000.0') - fee_node_1}} | "untrusted_pending": Decimal("30000000.0") - fee_node_1, | ||||
} | |||||
} | |||||
if self.options.descriptors: | if self.options.descriptors: | ||||
del expected_balances_0["watchonly"] | del expected_balances_0["watchonly"] | ||||
assert_equal(self.nodes[0].getbalances(), expected_balances_0) | assert_equal(self.nodes[0].getbalances(), expected_balances_0) | ||||
assert_equal(self.nodes[1].getbalances(), expected_balances_1) | assert_equal(self.nodes[1].getbalances(), expected_balances_1) | ||||
# getbalance without any arguments includes unconfirmed transactions, but not untrusted transactions | # getbalance without any arguments includes unconfirmed transactions, but not untrusted transactions | ||||
# change from node 0's send | # change from node 0's send | ||||
assert_equal(self.nodes[0].getbalance(), Decimal('9990000')) | assert_equal(self.nodes[0].getbalance(), Decimal("9990000")) | ||||
# node 1's send had an unsafe input | # node 1's send had an unsafe input | ||||
assert_equal(self.nodes[1].getbalance(), Decimal('0')) | assert_equal(self.nodes[1].getbalance(), Decimal("0")) | ||||
# Same with minconf=0 | # Same with minconf=0 | ||||
assert_equal( | assert_equal(self.nodes[0].getbalance(minconf=0), Decimal("9990000")) | ||||
self.nodes[0].getbalance( | assert_equal(self.nodes[1].getbalance(minconf=0), Decimal("0")) | ||||
minconf=0), | |||||
Decimal('9990000')) | |||||
assert_equal(self.nodes[1].getbalance(minconf=0), Decimal('0')) | |||||
# 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( | assert_equal(self.nodes[0].getunconfirmedbalance(), Decimal("60000000")) | ||||
self.nodes[0].getunconfirmedbalance(), | |||||
Decimal('60000000')) | |||||
# 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( | assert_equal( | ||||
self.nodes[1].getunconfirmedbalance(), | self.nodes[1].getunconfirmedbalance(), Decimal("30000000") - fee_node_1 | ||||
Decimal('30000000') - fee_node_1) | ) | ||||
# getwalletinfo.unconfirmed_balance | # getwalletinfo.unconfirmed_balance | ||||
assert_equal(self.nodes[0].getwalletinfo()[ | assert_equal( | ||||
"unconfirmed_balance"], Decimal('60000000')) | self.nodes[0].getwalletinfo()["unconfirmed_balance"], | ||||
Decimal("60000000"), | |||||
) | |||||
assert_equal( | assert_equal( | ||||
self.nodes[1].getwalletinfo()["unconfirmed_balance"], | self.nodes[1].getwalletinfo()["unconfirmed_balance"], | ||||
Decimal('30000000') - fee_node_1) | Decimal("30000000") - fee_node_1, | ||||
) | |||||
test_balances(fee_node_1=Decimal('10000')) | test_balances(fee_node_1=Decimal("10000")) | ||||
# 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 XEC, so it has 10000 XEC | # the fee by 0.01 here to resend, but this is XEC, so it has 10000 XEC | ||||
# 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 getbalances.mine.untrusted_pending with conflicted unconfirmed inputs") | "Test getbalance and getbalances.mine.untrusted_pending with conflicted" | ||||
test_balances(fee_node_1=Decimal('10000')) | " unconfirmed inputs" | ||||
) | |||||
test_balances(fee_node_1=Decimal("10000")) | |||||
self.generatetoaddress(self.nodes[1], 1, ADDRESS_WATCHONLY) | self.generatetoaddress(self.nodes[1], 1, ADDRESS_WATCHONLY) | ||||
# balances are correct after the transactions are confirmed | # balances are correct after the transactions are confirmed | ||||
# node 1's send plus change from node 0's send | # node 1's send plus change from node 0's send | ||||
balance_node0 = Decimal('69990000') | balance_node0 = Decimal("69990000") | ||||
# change from node 0's send | # change from node 0's send | ||||
balance_node1 = Decimal('29990000') | balance_node1 = Decimal("29990000") | ||||
assert_equal(self.nodes[0].getbalances()[ | assert_equal(self.nodes[0].getbalances()["mine"]["trusted"], balance_node0) | ||||
'mine']['trusted'], balance_node0) | assert_equal(self.nodes[1].getbalances()["mine"]["trusted"], balance_node1) | ||||
assert_equal(self.nodes[1].getbalances()[ | |||||
'mine']['trusted'], balance_node1) | |||||
assert_equal(self.nodes[0].getbalance(), balance_node0) | assert_equal(self.nodes[0].getbalance(), balance_node0) | ||||
assert_equal(self.nodes[1].getbalance(), balance_node1) | assert_equal(self.nodes[1].getbalance(), balance_node1) | ||||
# Send total balance away from node 1 | # Send total balance away from node 1 | ||||
txs = create_transactions(self.nodes[1], self.nodes[0].getnewaddress( | txs = create_transactions( | ||||
), Decimal('29970000'), [Decimal('10000')]) | self.nodes[1], | ||||
self.nodes[1].sendrawtransaction(txs[0]['hex']) | self.nodes[0].getnewaddress(), | ||||
Decimal("29970000"), | |||||
[Decimal("10000")], | |||||
) | |||||
self.nodes[1].sendrawtransaction(txs[0]["hex"]) | |||||
self.generatetoaddress(self.nodes[1], 2, ADDRESS_WATCHONLY) | self.generatetoaddress(self.nodes[1], 2, ADDRESS_WATCHONLY) | ||||
# 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 | ||||
# getbalance with minconf=3 should still show the old balance | # getbalance with minconf=3 should still show the old balance | ||||
assert_equal(self.nodes[1].getbalance(minconf=3), Decimal('0')) | assert_equal(self.nodes[1].getbalance(minconf=3), Decimal("0")) | ||||
# getbalance with minconf=2 will show the new balance. | # getbalance with minconf=2 will show the new balance. | ||||
assert_equal(self.nodes[1].getbalance(minconf=2), Decimal('10000')) | assert_equal(self.nodes[1].getbalance(minconf=2), Decimal("10000")) | ||||
# check mempool transactions count for wallet unconfirmed balance after | # check mempool transactions count for wallet unconfirmed balance after | ||||
# dynamically loading the wallet. | # dynamically loading the wallet. | ||||
before = self.nodes[1].getbalances()['mine']['untrusted_pending'] | before = self.nodes[1].getbalances()["mine"]["untrusted_pending"] | ||||
dst = self.nodes[1].getnewaddress() | dst = self.nodes[1].getnewaddress() | ||||
self.nodes[1].unloadwallet(self.default_wallet_name) | self.nodes[1].unloadwallet(self.default_wallet_name) | ||||
self.nodes[0].sendtoaddress(dst, 100000) | self.nodes[0].sendtoaddress(dst, 100000) | ||||
self.sync_all() | self.sync_all() | ||||
self.nodes[1].loadwallet(self.default_wallet_name) | self.nodes[1].loadwallet(self.default_wallet_name) | ||||
after = self.nodes[1].getbalances()['mine']['untrusted_pending'] | after = self.nodes[1].getbalances()["mine"]["untrusted_pending"] | ||||
assert_equal(before + Decimal('100000'), after) | assert_equal(before + Decimal("100000"), after) | ||||
# Create 3 more wallet txs, where the last is not accepted to the | # Create 3 more wallet txs, where the last is not accepted to the | ||||
# mempool because it is the third descendant of the tx above | # mempool because it is the third descendant of the tx above | ||||
for _ in range(3): | for _ in range(3): | ||||
# Set amount high enough such that all coins are spent by each tx | # Set amount high enough such that all coins are spent by each tx | ||||
txid = self.nodes[0].sendtoaddress( | txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 99000000) | ||||
self.nodes[0].getnewaddress(), 99000000) | |||||
self.log.info('Check that wallet txs not in the mempool are untrusted') | self.log.info("Check that wallet txs not in the mempool are untrusted") | ||||
assert txid not in self.nodes[0].getrawmempool() | assert txid not in self.nodes[0].getrawmempool() | ||||
assert_equal(self.nodes[0].gettransaction(txid)['trusted'], False) | assert_equal(self.nodes[0].gettransaction(txid)["trusted"], False) | ||||
assert_equal(self.nodes[0].getbalance(minconf=0), 0) | assert_equal(self.nodes[0].getbalance(minconf=0), 0) | ||||
self.log.info("Test replacement and reorg of non-mempool tx") | self.log.info("Test replacement and reorg of non-mempool tx") | ||||
tx_orig = self.nodes[0].gettransaction(txid)['hex'] | tx_orig = self.nodes[0].gettransaction(txid)["hex"] | ||||
# Increase fee by 1 coin | # Increase fee by 1 coin | ||||
tx_replace = tx_orig.replace( | tx_replace = tx_orig.replace( | ||||
struct.pack("<q", 99 * 10**8).hex(), | struct.pack("<q", 99 * 10**8).hex(), | ||||
struct.pack("<q", 98 * 10**8).hex(), | struct.pack("<q", 98 * 10**8).hex(), | ||||
) | ) | ||||
tx_replace = self.nodes[0].signrawtransactionwithwallet(tx_replace)[ | tx_replace = self.nodes[0].signrawtransactionwithwallet(tx_replace)["hex"] | ||||
'hex'] | |||||
# Total balance is given by the sum of outputs of the tx | # Total balance is given by the sum of outputs of the tx | ||||
total_amount = sum( | total_amount = sum( | ||||
[o['value'] for o in self.nodes[0].decoderawtransaction(tx_replace)['vout']]) | [o["value"] for o in self.nodes[0].decoderawtransaction(tx_replace)["vout"]] | ||||
) | |||||
self.sync_all() | self.sync_all() | ||||
self.nodes[1].sendrawtransaction(hexstring=tx_replace, maxfeerate=0) | self.nodes[1].sendrawtransaction(hexstring=tx_replace, maxfeerate=0) | ||||
# Now confirm tx_replace | # Now confirm tx_replace | ||||
block_reorg = self.generatetoaddress( | block_reorg = self.generatetoaddress(self.nodes[1], 1, ADDRESS_WATCHONLY)[0] | ||||
self.nodes[1], 1, ADDRESS_WATCHONLY)[0] | |||||
assert_equal(self.nodes[0].getbalance(minconf=0), total_amount) | assert_equal(self.nodes[0].getbalance(minconf=0), total_amount) | ||||
self.log.info('Put txs back into mempool of node 1 (not node 0)') | self.log.info("Put txs back into mempool of node 1 (not node 0)") | ||||
self.nodes[0].invalidateblock(block_reorg) | self.nodes[0].invalidateblock(block_reorg) | ||||
self.nodes[1].invalidateblock(block_reorg) | self.nodes[1].invalidateblock(block_reorg) | ||||
# wallet txs not in the mempool are untrusted | # wallet txs not in the mempool are untrusted | ||||
assert_equal(self.nodes[0].getbalance(minconf=0), 0) | assert_equal(self.nodes[0].getbalance(minconf=0), 0) | ||||
self.generatetoaddress( | self.generatetoaddress(self.nodes[0], 1, ADDRESS_WATCHONLY, sync_fun=self.no_op) | ||||
self.nodes[0], | |||||
1, | |||||
ADDRESS_WATCHONLY, | |||||
sync_fun=self.no_op) | |||||
# wallet txs not in the mempool are untrusted | # wallet txs not in the mempool are untrusted | ||||
assert_equal(self.nodes[0].getbalance(minconf=0), 0) | assert_equal(self.nodes[0].getbalance(minconf=0), 0) | ||||
# Now confirm tx_orig | # Now confirm tx_orig | ||||
self.restart_node(1, ['-persistmempool=0']) | self.restart_node(1, ["-persistmempool=0"]) | ||||
self.connect_nodes(0, 1) | self.connect_nodes(0, 1) | ||||
self.sync_blocks() | self.sync_blocks() | ||||
self.nodes[1].sendrawtransaction(tx_orig) | self.nodes[1].sendrawtransaction(tx_orig) | ||||
self.generatetoaddress(self.nodes[1], 1, ADDRESS_WATCHONLY) | self.generatetoaddress(self.nodes[1], 1, ADDRESS_WATCHONLY) | ||||
# The reorg recovered our fee of 1 coin | # The reorg recovered our fee of 1 coin | ||||
assert_equal( | assert_equal(self.nodes[0].getbalance(minconf=0), total_amount + 1000000) | ||||
self.nodes[0].getbalance( | |||||
minconf=0), | |||||
total_amount + | |||||
1000000) | |||||
if __name__ == '__main__': | if __name__ == "__main__": | ||||
WalletTest().main() | WalletTest().main() |