Skip to content

Commit

Permalink
Merge bitcoin#11869: QA: segwit.py: s/find_unspent/find_spendable_utxo/
Browse files Browse the repository at this point in the history
9bb59cf QA: segwit.py: s/find_unspent/find_spendable_utxo/ (Jorge Timón)

Pull request description:

  Separated from bitcoin#8994
  It was found out testing that PR but I think this fix should be done even without bitcoin#8994 the fix is not necessary by luck. Unless I'm missing something.

Tree-SHA512: ba1a970e674878ae2f27ee8bba372fa3b42dafff682374f50e5ddc9896fd8808fef2b2b70c7028f2a7b0dbea9f3e29a757e2cde98970f5761bf414455ba02c09
  • Loading branch information
MarcoFalke committed Feb 2, 2018
2 parents 1b06ed1 + 9bb59cf commit 4cad916
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions test/functional/feature_segwit.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ def getutxo(txid):
utxo["txid"] = txid
return utxo

def find_unspent(node, min_value):
for utxo in node.listunspent():
if utxo['amount'] >= min_value:
def find_spendable_utxo(node, min_value):
for utxo in node.listunspent(query_options={'minimumAmount': min_value}):
if utxo['spendable']:
return utxo

raise AssertionError("Unspent output equal or higher than %s not found" % min_value)

class SegWitTest(BitcoinTestFramework):
def set_test_params(self):
self.setup_clean_chain = True
Expand Down Expand Up @@ -113,8 +115,8 @@ def run_test(self):
for i in range(5):
for n in range(3):
for v in range(2):
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")))
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")))
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")))
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")))

self.nodes[0].generate(1) #block 163
sync_blocks(self.nodes)
Expand Down Expand Up @@ -209,7 +211,7 @@ def run_test(self):
# tx2 (segwit input, paying to a non-segwit output) ->
# tx3 (non-segwit input, paying to a non-segwit output).
# tx1 is allowed to appear in the block, but no others.
txid1 = send_to_witness(1, self.nodes[0], find_unspent(self.nodes[0], 50), self.pubkey[0], False, Decimal("49.996"))
txid1 = send_to_witness(1, self.nodes[0], find_spendable_utxo(self.nodes[0], 50), self.pubkey[0], False, Decimal("49.996"))
hex_tx = self.nodes[0].gettransaction(txid)['hex']
tx = FromHex(CTransaction(), hex_tx)
assert(tx.wit.is_null()) # This should not be a segwit input
Expand Down Expand Up @@ -570,7 +572,7 @@ def run_test(self):
assert_equal(self.nodes[1].listtransactions("*", 1, 0, True)[0]["txid"], txid)

def mine_and_test_listunspent(self, script_list, ismine):
utxo = find_unspent(self.nodes[0], 50)
utxo = find_spendable_utxo(self.nodes[0], 50)
tx = CTransaction()
tx.vin.append(CTxIn(COutPoint(int('0x'+utxo['txid'],0), utxo['vout'])))
for i in script_list:
Expand Down

0 comments on commit 4cad916

Please sign in to comment.