Changeset View
Changeset View
Standalone View
Standalone View
test/functional/wallet_abandonconflict.py
Show All 13 Lines | |||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import ( | from test_framework.util import ( | ||||
assert_equal, | assert_equal, | ||||
assert_raises_rpc_error, | assert_raises_rpc_error, | ||||
connect_nodes, | connect_nodes, | ||||
disconnect_nodes, | disconnect_nodes, | ||||
satoshi_round, | satoshi_round, | ||||
wait_until, | |||||
) | ) | ||||
class AbandonConflictTest(BitcoinTestFramework): | class AbandonConflictTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.num_nodes = 2 | self.num_nodes = 2 | ||||
self.extra_args = [["-minrelaytxfee=0.00001"], []] | self.extra_args = [["-minrelaytxfee=0.00001"], []] | ||||
self.supports_cli = False | self.supports_cli = False | ||||
▲ Show 20 Lines • Show All 90 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
newbalance = self.nodes[0].getbalance() | newbalance = self.nodes[0].getbalance() | ||||
assert_equal(newbalance, balance - Decimal("30") + signed3_change) | assert_equal(newbalance, balance - Decimal("30") + signed3_change) | ||||
balance = newbalance | balance = newbalance | ||||
# Restart the node with a higher min relay fee so the parent tx is no longer in mempool | # Restart the node with a higher min relay fee so the parent tx is no longer in mempool | ||||
# TODO: redo with eviction | # TODO: redo with eviction | ||||
self.stop_node(0) | self.stop_node(0) | ||||
self.start_node(0, extra_args=["-minrelaytxfee=0.0001"]) | self.start_node(0, extra_args=["-minrelaytxfee=0.0001"]) | ||||
wait_until(lambda: self.nodes[0].getmempoolinfo()['loaded']) | assert self.nodes[0].getmempoolinfo()['loaded'] | ||||
# Verify txs no longer in either node's mempool | # Verify txs no longer in either node's mempool | ||||
assert_equal(len(self.nodes[0].getrawmempool()), 0) | assert_equal(len(self.nodes[0].getrawmempool()), 0) | ||||
assert_equal(len(self.nodes[1].getrawmempool()), 0) | assert_equal(len(self.nodes[1].getrawmempool()), 0) | ||||
# Transactions which are not in the mempool should only reduce wallet balance. | # Transactions which are not in the mempool should only reduce wallet balance. | ||||
# Transaction inputs should still be spent, but the change not yet | # Transaction inputs should still be spent, but the change not yet | ||||
# received. | # received. | ||||
Show All 17 Lines | def run_test(self): | ||||
newbalance = self.nodes[0].getbalance() | newbalance = self.nodes[0].getbalance() | ||||
assert_equal(newbalance, balance + Decimal("30")) | assert_equal(newbalance, balance + Decimal("30")) | ||||
balance = newbalance | balance = newbalance | ||||
# Verify that even with a low min relay fee, the tx is not re-accepted | # Verify that even with a low min relay fee, the tx is not re-accepted | ||||
# from wallet on startup once abandoned. | # from wallet on startup once abandoned. | ||||
self.stop_node(0) | self.stop_node(0) | ||||
self.start_node(0, extra_args=["-minrelaytxfee=0.00001"]) | self.start_node(0, extra_args=["-minrelaytxfee=0.00001"]) | ||||
wait_until(lambda: self.nodes[0].getmempoolinfo()['loaded']) | assert self.nodes[0].getmempoolinfo()['loaded'] | ||||
assert_equal(len(self.nodes[0].getrawmempool()), 0) | assert_equal(len(self.nodes[0].getrawmempool()), 0) | ||||
assert_equal(self.nodes[0].getbalance(), balance) | assert_equal(self.nodes[0].getbalance(), balance) | ||||
# If the transaction is re-sent the wallet also unabandons it. The | # If the transaction is re-sent the wallet also unabandons it. The | ||||
# change should be available, and it's child transaction should remain | # change should be available, and it's child transaction should remain | ||||
# abandoned. | # abandoned. | ||||
# NOTE: Abandoned transactions are internal to the wallet, and tracked | # NOTE: Abandoned transactions are internal to the wallet, and tracked | ||||
# separately from other indices. | # separately from other indices. | ||||
self.nodes[0].sendrawtransaction(signed["hex"]) | self.nodes[0].sendrawtransaction(signed["hex"]) | ||||
newbalance = self.nodes[0].getbalance() | newbalance = self.nodes[0].getbalance() | ||||
assert_equal(newbalance, balance - Decimal("20") + Decimal("14.99998")) | assert_equal(newbalance, balance - Decimal("20") + Decimal("14.99998")) | ||||
balance = newbalance | balance = newbalance | ||||
# Send child tx again so it is no longer abandoned. | # Send child tx again so it is no longer abandoned. | ||||
self.nodes[0].sendrawtransaction(signed2["hex"]) | self.nodes[0].sendrawtransaction(signed2["hex"]) | ||||
newbalance = self.nodes[0].getbalance() | newbalance = self.nodes[0].getbalance() | ||||
assert_equal(newbalance, balance - Decimal("10") | assert_equal(newbalance, balance - Decimal("10") | ||||
- Decimal("14.99998") + Decimal("24.9996")) | - Decimal("14.99998") + Decimal("24.9996")) | ||||
balance = newbalance | balance = newbalance | ||||
# Reset to a higher relay fee so that we abandon a transaction | # Reset to a higher relay fee so that we abandon a transaction | ||||
self.stop_node(0) | self.stop_node(0) | ||||
self.start_node(0, extra_args=["-minrelaytxfee=0.0001"]) | self.start_node(0, extra_args=["-minrelaytxfee=0.0001"]) | ||||
wait_until(lambda: self.nodes[0].getmempoolinfo()['loaded']) | assert self.nodes[0].getmempoolinfo()['loaded'] | ||||
assert_equal(len(self.nodes[0].getrawmempool()), 0) | assert_equal(len(self.nodes[0].getrawmempool()), 0) | ||||
newbalance = self.nodes[0].getbalance() | newbalance = self.nodes[0].getbalance() | ||||
assert_equal(newbalance, balance - Decimal("24.9996")) | assert_equal(newbalance, balance - Decimal("24.9996")) | ||||
balance = newbalance | balance = newbalance | ||||
# Create a double spend of AB1. Spend it again from only A's 10 output. | # Create a double spend of AB1. Spend it again from only A's 10 output. | ||||
# Mine double spend from node 1. | # Mine double spend from node 1. | ||||
inputs = [] | inputs = [] | ||||
Show All 32 Lines |