Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abandonconflict.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2014-2016 The Bitcoin Core developers | # Copyright (c) 2014-2016 The Bitcoin Core developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import * | from test_framework.util import * | ||||
import urllib.parse | import urllib.parse | ||||
class AbandonConflictTest(BitcoinTestFramework): | class AbandonConflictTest(BitcoinTestFramework): | ||||
def set_test_params(self): | |||||
def __init__(self): | |||||
super().__init__() | |||||
self.num_nodes = 2 | self.num_nodes = 2 | ||||
self.setup_clean_chain = False | |||||
self.extra_args = [["-minrelaytxfee=0.00001"], []] | self.extra_args = [["-minrelaytxfee=0.00001"], []] | ||||
def run_test(self): | def run_test(self): | ||||
self.nodes[1].generate(100) | self.nodes[1].generate(100) | ||||
sync_blocks(self.nodes) | sync_blocks(self.nodes) | ||||
balance = self.nodes[0].getbalance() | balance = self.nodes[0].getbalance() | ||||
txA = self.nodes[0].sendtoaddress( | txA = self.nodes[0].sendtoaddress( | ||||
self.nodes[0].getnewaddress(), Decimal("10")) | self.nodes[0].getnewaddress(), Decimal("10")) | ||||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
# In mempool txs from self should increase balance from change | # In mempool txs from self should increase balance from change | ||||
newbalance = self.nodes[0].getbalance() | newbalance = self.nodes[0].getbalance() | ||||
assert_equal(newbalance, balance - Decimal("30") + Decimal("24.9996")) | assert_equal(newbalance, balance - Decimal("30") + Decimal("24.9996")) | ||||
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.nodes[0] = self.start_node(0, self.options.tmpdir, [ | self.start_node(0, extra_args=["-minrelaytxfee=0.0001"]) | ||||
"-minrelaytxfee=0.0001"]) | |||||
# Verify txs no longer in mempool | # Verify txs no longer in mempool | ||||
assert_equal(len(self.nodes[0].getrawmempool()), 0) | assert_equal(len(self.nodes[0].getrawmempool()), 0) | ||||
# Not in mempool txs from self should only reduce balance | # Not in mempool txs from self should only reduce balance | ||||
# inputs are still spent, but change not received | # inputs are still spent, but change not received | ||||
newbalance = self.nodes[0].getbalance() | newbalance = self.nodes[0].getbalance() | ||||
assert_equal(newbalance, balance - Decimal("24.9996")) | assert_equal(newbalance, balance - Decimal("24.9996")) | ||||
Show All 11 Lines | def run_test(self): | ||||
# including that the child tx was also abandoned | # including that the child tx was also abandoned | ||||
self.nodes[0].abandontransaction(txAB1) | self.nodes[0].abandontransaction(txAB1) | ||||
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 reaccepted from wallet on startup once abandoned | # Verify that even with a low min relay fee, the tx is not reaccepted from wallet on startup once abandoned | ||||
self.stop_node(0) | self.stop_node(0) | ||||
self.nodes[0] = self.start_node(0, self.options.tmpdir, [ | self.start_node(0, extra_args=["-minrelaytxfee=0.00001"]) | ||||
"-minrelaytxfee=0.00001"]) | |||||
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) | ||||
# But if its received again then it is unabandoned | # But if its received again then it is unabandoned | ||||
# And since now in mempool, the change is available | # And since now in mempool, the change is available | ||||
# But its child tx remains abandoned | # But its child tx remains abandoned | ||||
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 its unabandoned | # Send child tx again so its unabandoned | ||||
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 | ||||
# Remove using high relay fee again | # Remove using high relay fee again | ||||
self.stop_node(0) | self.stop_node(0) | ||||
self.nodes[0] = self.start_node(0, self.options.tmpdir, [ | self.start_node(0, extra_args=["-minrelaytxfee=0.0001"]) | ||||
"-minrelaytxfee=0.0001"]) | |||||
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 by spending again from only A's 10 output | # Create a double spend of AB1 by spending 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 |