@@ -30,11 +30,13 @@ def getutxo(txid):
30
30
utxo ["txid" ] = txid
31
31
return utxo
32
32
33
- def find_unspent (node , min_value ):
34
- for utxo in node .listunspent ():
35
- if utxo ['amount' ] >= min_value :
33
+ def find_spendable_utxo (node , min_value ):
34
+ for utxo in node .listunspent (query_options = { 'minimumAmount' : min_value } ):
35
+ if utxo ['spendable' ] :
36
36
return utxo
37
37
38
+ raise AssertionError ("Unspent output equal or higher than %s not found" % min_value )
39
+
38
40
class SegWitTest (BitcoinTestFramework ):
39
41
def set_test_params (self ):
40
42
self .setup_clean_chain = True
@@ -113,8 +115,8 @@ def run_test(self):
113
115
for i in range (5 ):
114
116
for n in range (3 ):
115
117
for v in range (2 ):
116
- wit_ids [n ][v ].append (send_to_witness (v , self .nodes [0 ], find_unspent (self .nodes [0 ], 50 ), self .pubkey [n ], False , Decimal ("49.999" )))
117
- p2sh_ids [n ][v ].append (send_to_witness (v , self .nodes [0 ], find_unspent (self .nodes [0 ], 50 ), self .pubkey [n ], True , Decimal ("49.999" )))
118
+ wit_ids [n ][v ].append (send_to_witness (v , self .nodes [0 ], find_spendable_utxo (self .nodes [0 ], 50 ), self .pubkey [n ], False , Decimal ("49.999" )))
119
+ p2sh_ids [n ][v ].append (send_to_witness (v , self .nodes [0 ], find_spendable_utxo (self .nodes [0 ], 50 ), self .pubkey [n ], True , Decimal ("49.999" )))
118
120
119
121
self .nodes [0 ].generate (1 ) #block 163
120
122
sync_blocks (self .nodes )
@@ -209,7 +211,7 @@ def run_test(self):
209
211
# tx2 (segwit input, paying to a non-segwit output) ->
210
212
# tx3 (non-segwit input, paying to a non-segwit output).
211
213
# tx1 is allowed to appear in the block, but no others.
212
- txid1 = send_to_witness (1 , self .nodes [0 ], find_unspent (self .nodes [0 ], 50 ), self .pubkey [0 ], False , Decimal ("49.996" ))
214
+ txid1 = send_to_witness (1 , self .nodes [0 ], find_spendable_utxo (self .nodes [0 ], 50 ), self .pubkey [0 ], False , Decimal ("49.996" ))
213
215
hex_tx = self .nodes [0 ].gettransaction (txid )['hex' ]
214
216
tx = FromHex (CTransaction (), hex_tx )
215
217
assert (tx .wit .is_null ()) # This should not be a segwit input
@@ -570,7 +572,7 @@ def run_test(self):
570
572
assert_equal (self .nodes [1 ].listtransactions ("*" , 1 , 0 , True )[0 ]["txid" ], txid )
571
573
572
574
def mine_and_test_listunspent (self , script_list , ismine ):
573
- utxo = find_unspent (self .nodes [0 ], 50 )
575
+ utxo = find_spendable_utxo (self .nodes [0 ], 50 )
574
576
tx = CTransaction ()
575
577
tx .vin .append (CTxIn (COutPoint (int ('0x' + utxo ['txid' ],0 ), utxo ['vout' ])))
576
578
for i in script_list :
0 commit comments