Skip to content

Commit b77885f

Browse files
committed
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.
1 parent 59ba7d2 commit b77885f

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

test/functional/wallet_txn_clone.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from test_framework.test_framework import BitcoinTestFramework
88
from test_framework.util import (
99
assert_equal,
10+
find_vout_for_address
1011
)
1112
from test_framework.messages import (
1213
COIN,
@@ -33,6 +34,13 @@ def setup_network(self):
3334
super().setup_network()
3435
self.disconnect_nodes(1, 2)
3536

37+
def spend_txid(self, txid, vout, outputs):
38+
inputs = [{"txid": txid, "vout": vout}]
39+
tx = self.nodes[0].createrawtransaction(inputs, outputs)
40+
tx = self.nodes[0].fundrawtransaction(tx)
41+
tx = self.nodes[0].signrawtransactionwithwallet(tx['hex'])
42+
return self.nodes[0].sendrawtransaction(tx['hex'])
43+
3644
def run_test(self):
3745
if self.options.segwit:
3846
output_type = "p2sh-segwit"
@@ -49,6 +57,7 @@ def run_test(self):
4957
node0_address1 = self.nodes[0].getnewaddress(address_type=output_type)
5058
node0_txid1 = self.nodes[0].sendtoaddress(node0_address1, 1219)
5159
node0_tx1 = self.nodes[0].gettransaction(node0_txid1)
60+
self.nodes[0].lockunspent(False, [{"txid":node0_txid1, "vout": find_vout_for_address(self.nodes[0], node0_txid1, node0_address1)}])
5261

5362
node0_address2 = self.nodes[0].getnewaddress(address_type=output_type)
5463
node0_txid2 = self.nodes[0].sendtoaddress(node0_address2, 29)
@@ -61,8 +70,8 @@ def run_test(self):
6170
node1_address = self.nodes[1].getnewaddress()
6271

6372
# Send tx1, and another transaction tx2 that won't be cloned
64-
txid1 = self.nodes[0].sendtoaddress(node1_address, 40)
65-
txid2 = self.nodes[0].sendtoaddress(node1_address, 20)
73+
txid1 = self.spend_txid(node0_txid1, find_vout_for_address(self.nodes[0], node0_txid1, node0_address1), {node1_address: 40})
74+
txid2 = self.spend_txid(node0_txid2, find_vout_for_address(self.nodes[0], node0_txid2, node0_address2), {node1_address: 20})
6675

6776
# Construct a clone of tx1, to be malleated
6877
rawtx1 = self.nodes[0].getrawtransaction(txid1, 1)

test/functional/wallet_txn_doublespend.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from test_framework.util import (
1010
assert_equal,
1111
find_output,
12+
find_vout_for_address
1213
)
1314

1415

@@ -29,6 +30,13 @@ def setup_network(self):
2930
super().setup_network()
3031
self.disconnect_nodes(1, 2)
3132

33+
def spend_txid(self, txid, vout, outputs):
34+
inputs = [{"txid": txid, "vout": vout}]
35+
tx = self.nodes[0].createrawtransaction(inputs, outputs)
36+
tx = self.nodes[0].fundrawtransaction(tx)
37+
tx = self.nodes[0].signrawtransactionwithwallet(tx['hex'])
38+
return self.nodes[0].sendrawtransaction(tx['hex'])
39+
3240
def run_test(self):
3341
# All nodes should start with 1,250 BTC:
3442
starting_balance = 1250
@@ -47,6 +55,7 @@ def run_test(self):
4755
node0_address_foo = self.nodes[0].getnewaddress()
4856
fund_foo_txid = self.nodes[0].sendtoaddress(node0_address_foo, 1219)
4957
fund_foo_tx = self.nodes[0].gettransaction(fund_foo_txid)
58+
self.nodes[0].lockunspent(False, [{"txid":fund_foo_txid, "vout": find_vout_for_address(self.nodes[0], fund_foo_txid, node0_address_foo)}])
5059

5160
node0_address_bar = self.nodes[0].getnewaddress()
5261
fund_bar_txid = self.nodes[0].sendtoaddress(node0_address_bar, 29)
@@ -77,8 +86,8 @@ def run_test(self):
7786
assert_equal(doublespend["complete"], True)
7887

7988
# Create two spends using 1 50 BTC coin each
80-
txid1 = self.nodes[0].sendtoaddress(node1_address, 40)
81-
txid2 = self.nodes[0].sendtoaddress(node1_address, 20)
89+
txid1 = self.spend_txid(fund_foo_txid, find_vout_for_address(self.nodes[0], fund_foo_txid, node0_address_foo), {node1_address: 40})
90+
txid2 = self.spend_txid(fund_bar_txid, find_vout_for_address(self.nodes[0], fund_bar_txid, node0_address_bar), {node1_address: 20})
8291

8392
# Have node0 mine a block:
8493
if (self.options.mine_block):

0 commit comments

Comments
 (0)