Changeset View
Changeset View
Standalone View
Standalone View
test/functional/wallet_txn_doublespend.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2014-2019 The Bitcoin Core developers | # Copyright (c) 2014-2019 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. | ||||
"""Test the wallet accounts properly when there is a double-spend conflict.""" | """Test the wallet accounts properly when there is a double-spend conflict.""" | ||||
from decimal import Decimal | from decimal import Decimal | ||||
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, | ||||
connect_nodes, | connect_nodes, | ||||
disconnect_nodes, | disconnect_nodes, | ||||
find_output, | find_output, | ||||
sync_blocks, | |||||
) | ) | ||||
class TxnMallTest(BitcoinTestFramework): | class TxnMallTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.num_nodes = 4 | self.num_nodes = 4 | ||||
self.extra_args = [["-noparkdeepreorg"], ["-noparkdeepreorg"], [], []] | self.extra_args = [["-noparkdeepreorg"], ["-noparkdeepreorg"], [], []] | ||||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
# Create two spends using 1 50 BCH coin each | # Create two spends using 1 50 BCH coin each | ||||
txid1 = self.nodes[0].sendtoaddress(node1_address, 40) | txid1 = self.nodes[0].sendtoaddress(node1_address, 40) | ||||
txid2 = self.nodes[0].sendtoaddress(node1_address, 20) | txid2 = self.nodes[0].sendtoaddress(node1_address, 20) | ||||
# Have node0 mine a block: | # Have node0 mine a block: | ||||
if (self.options.mine_block): | if (self.options.mine_block): | ||||
self.nodes[0].generate(1) | self.nodes[0].generate(1) | ||||
sync_blocks(self.nodes[0:2]) | self.sync_blocks(self.nodes[0:2]) | ||||
tx1 = self.nodes[0].gettransaction(txid1) | tx1 = self.nodes[0].gettransaction(txid1) | ||||
tx2 = self.nodes[0].gettransaction(txid2) | tx2 = self.nodes[0].gettransaction(txid2) | ||||
# Node0's balance should be starting balance, plus 50BTC for another | # Node0's balance should be starting balance, plus 50BTC for another | ||||
# matured block, minus 40, minus 20, and minus transaction fees: | # matured block, minus 40, minus 20, and minus transaction fees: | ||||
expected = starting_balance + fund_foo_tx["fee"] + fund_bar_tx["fee"] | expected = starting_balance + fund_foo_tx["fee"] + fund_bar_tx["fee"] | ||||
if self.options.mine_block: | if self.options.mine_block: | ||||
Show All 17 Lines | def run_test(self): | ||||
self.nodes[2].sendrawtransaction(fund_bar_tx["hex"]) | self.nodes[2].sendrawtransaction(fund_bar_tx["hex"]) | ||||
doublespend_txid = self.nodes[2].sendrawtransaction(doublespend["hex"]) | doublespend_txid = self.nodes[2].sendrawtransaction(doublespend["hex"]) | ||||
# ... mine a block... | # ... mine a block... | ||||
self.nodes[2].generate(1) | self.nodes[2].generate(1) | ||||
# Reconnect the split network, and sync chain: | # Reconnect the split network, and sync chain: | ||||
connect_nodes(self.nodes[1], self.nodes[2]) | connect_nodes(self.nodes[1], self.nodes[2]) | ||||
self.nodes[2].generate(1) # Mine another block to make sure we sync | self.nodes[2].generate(1) # Mine another block to make sure we sync | ||||
sync_blocks(self.nodes) | self.sync_blocks() | ||||
assert_equal(self.nodes[0].gettransaction( | assert_equal(self.nodes[0].gettransaction( | ||||
doublespend_txid)["confirmations"], 2) | doublespend_txid)["confirmations"], 2) | ||||
# Re-fetch transaction info: | # Re-fetch transaction info: | ||||
tx1 = self.nodes[0].gettransaction(txid1) | tx1 = self.nodes[0].gettransaction(txid1) | ||||
tx2 = self.nodes[0].gettransaction(txid2) | tx2 = self.nodes[0].gettransaction(txid2) | ||||
# Both transactions should be conflicted | # Both transactions should be conflicted | ||||
Show All 17 Lines |