Changeset View
Changeset View
Standalone View
Standalone View
test/functional/wallet_txn_clone.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 are cloned transactions with malleated scriptsigs.""" | """Test the wallet accounts properly when there are cloned transactions with malleated scriptsigs.""" | ||||
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, | ||||
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 69 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
# Don't send the clone anywhere yet | # Don't send the clone anywhere yet | ||||
tx1_clone = self.nodes[0].signrawtransactionwithwallet( | tx1_clone = self.nodes[0].signrawtransactionwithwallet( | ||||
clone_raw, None, "ALL|FORKID|ANYONECANPAY") | clone_raw, None, "ALL|FORKID|ANYONECANPAY") | ||||
assert_equal(tx1_clone["complete"], True) | assert_equal(tx1_clone["complete"], True) | ||||
# Have node0 mine a block, if requested: | # Have node0 mine a block, if requested: | ||||
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 tx1 and tx2 amounts, and minus transaction fees: | # matured block, minus tx1 and tx2 amounts, and minus transaction fees: | ||||
expected = starting_balance + node0_tx1["fee"] + node0_tx2["fee"] | expected = starting_balance + node0_tx1["fee"] + node0_tx2["fee"] | ||||
if self.options.mine_block: | if self.options.mine_block: | ||||
Show All 16 Lines | def run_test(self): | ||||
# ... 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].sendrawtransaction(node0_tx2["hex"]) | self.nodes[2].sendrawtransaction(node0_tx2["hex"]) | ||||
self.nodes[2].sendrawtransaction(tx2["hex"]) | self.nodes[2].sendrawtransaction(tx2["hex"]) | ||||
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() | ||||
# Re-fetch transaction info: | # Re-fetch transaction info: | ||||
tx1 = self.nodes[0].gettransaction(txid1) | tx1 = self.nodes[0].gettransaction(txid1) | ||||
tx1_clone = self.nodes[0].gettransaction(txid1_clone) | tx1_clone = self.nodes[0].gettransaction(txid1_clone) | ||||
tx2 = self.nodes[0].gettransaction(txid2) | tx2 = self.nodes[0].gettransaction(txid2) | ||||
# Verify expected confirmations | # Verify expected confirmations | ||||
assert_equal(tx1["confirmations"], -2) | assert_equal(tx1["confirmations"], -2) | ||||
Show All 13 Lines |