Changeset View
Changeset View
Standalone View
Standalone View
test/functional/txn_doublespend.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. | ||||
"""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 test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import * | from test_framework.util import * | ||||
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 = [ | self.extra_args = [["-noparkdeepreorg"], ["-noparkdeepreorg"], [], []] | ||||
["-noparkdeepreorg", "-deprecatedrpc=signrawtransaction"], ["-noparkdeepreorg"], [], []] | |||||
def add_options(self, parser): | def add_options(self, parser): | ||||
parser.add_argument("--mineblock", dest="mine_block", default=False, action="store_true", | parser.add_argument("--mineblock", dest="mine_block", default=False, action="store_true", | ||||
help="Test double-spend of 1-confirmed transaction") | help="Test double-spend of 1-confirmed transaction") | ||||
def setup_network(self): | def setup_network(self): | ||||
# Start with split network: | # Start with split network: | ||||
super().setup_network() | super().setup_network() | ||||
Show All 33 Lines | def run_test(self): | ||||
rawtx_input_1["txid"] = fund_bar_txid | rawtx_input_1["txid"] = fund_bar_txid | ||||
rawtx_input_1["vout"] = find_output(self.nodes[0], fund_bar_txid, 29) | rawtx_input_1["vout"] = find_output(self.nodes[0], fund_bar_txid, 29) | ||||
inputs = [rawtx_input_0, rawtx_input_1] | inputs = [rawtx_input_0, rawtx_input_1] | ||||
change_address = self.nodes[0].getnewaddress() | change_address = self.nodes[0].getnewaddress() | ||||
outputs = {} | outputs = {} | ||||
outputs[node1_address] = 1240 | outputs[node1_address] = 1240 | ||||
outputs[change_address] = 1248 - 1240 + doublespend_fee | outputs[change_address] = 1248 - 1240 + doublespend_fee | ||||
rawtx = self.nodes[0].createrawtransaction(inputs, outputs) | rawtx = self.nodes[0].createrawtransaction(inputs, outputs) | ||||
doublespend = self.nodes[0].signrawtransaction(rawtx) | doublespend = self.nodes[0].signrawtransactionwithwallet(rawtx) | ||||
assert_equal(doublespend["complete"], True) | assert_equal(doublespend["complete"], True) | ||||
# Create two spends using 1 50 BTC coin each | # Create two spends using 1 50 BTC coin each | ||||
txid1 = self.nodes[0].sendfrom("foo", node1_address, 40, 0) | txid1 = self.nodes[0].sendfrom("foo", node1_address, 40, 0) | ||||
txid2 = self.nodes[0].sendfrom("bar", node1_address, 20, 0) | txid2 = self.nodes[0].sendfrom("bar", node1_address, 20, 0) | ||||
# Have node0 mine a block: | # Have node0 mine a block: | ||||
if (self.options.mine_block): | if (self.options.mine_block): | ||||
▲ Show 20 Lines • Show All 80 Lines • Show Last 20 Lines |