mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-09-08 23:41:26 +02:00
tests: wallet_txn explicilty specify inputs
Instead of relying on coin selection to deterministically choose the correct inputs to use, just specify them explicitly and use the raw transaction RPCs.
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
from test_framework.test_framework import BitcoinTestFramework
|
||||
from test_framework.util import (
|
||||
assert_equal,
|
||||
find_vout_for_address
|
||||
)
|
||||
from test_framework.messages import (
|
||||
COIN,
|
||||
@@ -33,6 +34,13 @@ class TxnMallTest(BitcoinTestFramework):
|
||||
super().setup_network()
|
||||
self.disconnect_nodes(1, 2)
|
||||
|
||||
def spend_txid(self, txid, vout, outputs):
|
||||
inputs = [{"txid": txid, "vout": vout}]
|
||||
tx = self.nodes[0].createrawtransaction(inputs, outputs)
|
||||
tx = self.nodes[0].fundrawtransaction(tx)
|
||||
tx = self.nodes[0].signrawtransactionwithwallet(tx['hex'])
|
||||
return self.nodes[0].sendrawtransaction(tx['hex'])
|
||||
|
||||
def run_test(self):
|
||||
if self.options.segwit:
|
||||
output_type = "p2sh-segwit"
|
||||
@@ -49,6 +57,7 @@ class TxnMallTest(BitcoinTestFramework):
|
||||
node0_address1 = self.nodes[0].getnewaddress(address_type=output_type)
|
||||
node0_txid1 = self.nodes[0].sendtoaddress(node0_address1, 1219)
|
||||
node0_tx1 = self.nodes[0].gettransaction(node0_txid1)
|
||||
self.nodes[0].lockunspent(False, [{"txid":node0_txid1, "vout": find_vout_for_address(self.nodes[0], node0_txid1, node0_address1)}])
|
||||
|
||||
node0_address2 = self.nodes[0].getnewaddress(address_type=output_type)
|
||||
node0_txid2 = self.nodes[0].sendtoaddress(node0_address2, 29)
|
||||
@@ -61,8 +70,8 @@ class TxnMallTest(BitcoinTestFramework):
|
||||
node1_address = self.nodes[1].getnewaddress()
|
||||
|
||||
# Send tx1, and another transaction tx2 that won't be cloned
|
||||
txid1 = self.nodes[0].sendtoaddress(node1_address, 40)
|
||||
txid2 = self.nodes[0].sendtoaddress(node1_address, 20)
|
||||
txid1 = self.spend_txid(node0_txid1, find_vout_for_address(self.nodes[0], node0_txid1, node0_address1), {node1_address: 40})
|
||||
txid2 = self.spend_txid(node0_txid2, find_vout_for_address(self.nodes[0], node0_txid2, node0_address2), {node1_address: 20})
|
||||
|
||||
# Construct a clone of tx1, to be malleated
|
||||
rawtx1 = self.nodes[0].getrawtransaction(txid1, 1)
|
||||
|
@@ -9,6 +9,7 @@ from test_framework.test_framework import BitcoinTestFramework
|
||||
from test_framework.util import (
|
||||
assert_equal,
|
||||
find_output,
|
||||
find_vout_for_address
|
||||
)
|
||||
|
||||
|
||||
@@ -29,6 +30,13 @@ class TxnMallTest(BitcoinTestFramework):
|
||||
super().setup_network()
|
||||
self.disconnect_nodes(1, 2)
|
||||
|
||||
def spend_txid(self, txid, vout, outputs):
|
||||
inputs = [{"txid": txid, "vout": vout}]
|
||||
tx = self.nodes[0].createrawtransaction(inputs, outputs)
|
||||
tx = self.nodes[0].fundrawtransaction(tx)
|
||||
tx = self.nodes[0].signrawtransactionwithwallet(tx['hex'])
|
||||
return self.nodes[0].sendrawtransaction(tx['hex'])
|
||||
|
||||
def run_test(self):
|
||||
# All nodes should start with 1,250 BTC:
|
||||
starting_balance = 1250
|
||||
@@ -47,6 +55,7 @@ class TxnMallTest(BitcoinTestFramework):
|
||||
node0_address_foo = self.nodes[0].getnewaddress()
|
||||
fund_foo_txid = self.nodes[0].sendtoaddress(node0_address_foo, 1219)
|
||||
fund_foo_tx = self.nodes[0].gettransaction(fund_foo_txid)
|
||||
self.nodes[0].lockunspent(False, [{"txid":fund_foo_txid, "vout": find_vout_for_address(self.nodes[0], fund_foo_txid, node0_address_foo)}])
|
||||
|
||||
node0_address_bar = self.nodes[0].getnewaddress()
|
||||
fund_bar_txid = self.nodes[0].sendtoaddress(node0_address_bar, 29)
|
||||
@@ -77,8 +86,8 @@ class TxnMallTest(BitcoinTestFramework):
|
||||
assert_equal(doublespend["complete"], True)
|
||||
|
||||
# Create two spends using 1 50 BTC coin each
|
||||
txid1 = self.nodes[0].sendtoaddress(node1_address, 40)
|
||||
txid2 = self.nodes[0].sendtoaddress(node1_address, 20)
|
||||
txid1 = self.spend_txid(fund_foo_txid, find_vout_for_address(self.nodes[0], fund_foo_txid, node0_address_foo), {node1_address: 40})
|
||||
txid2 = self.spend_txid(fund_bar_txid, find_vout_for_address(self.nodes[0], fund_bar_txid, node0_address_bar), {node1_address: 20})
|
||||
|
||||
# Have node0 mine a block:
|
||||
if (self.options.mine_block):
|
||||
|
Reference in New Issue
Block a user