Skip to content

Commit fa23039

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#23515: test: Return the largest utxo in MiniWallet.get_utxo
fa62207 test: Return the largest utxo in MiniWallet.get_utxo (MarcoFalke) Pull request description: This is for consistency with the `send_self_transfer` method. Also, remove the feature that the change of the last transfer can be retrieved via `get_utxo`. This can trivially and clearer be achieved by simply passing the txid of the transfer. Also, this fixes the bug in `feature_txindex_compatibility` in current master after a silent merge conflict. Fixes #23514 Top commit has no ACKs. Tree-SHA512: edd066d372aaa72b4e0fc7526f84931c8d1f6d14f53678cb7832bc8e3d211f44b90ec9c59b7d915ef24acc63a36e7d66c8d3b7598355bd490ac637ed3bcc3dff
2 parents 024e4de + fa62207 commit fa23039

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

test/functional/rpc_txoutproof.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def run_test(self):
5353
assert_equal(self.nodes[0].verifytxoutproof(self.nodes[0].gettxoutproof([txid1, txid2])), txlist)
5454
assert_equal(self.nodes[0].verifytxoutproof(self.nodes[0].gettxoutproof([txid1, txid2], blockhash)), txlist)
5555

56-
txin_spent = miniwallet.get_utxo() # Get the change from txid2
56+
txin_spent = miniwallet.get_utxo(txid=txid2) # Get the change from txid2
5757
tx3 = miniwallet.send_self_transfer(from_node=self.nodes[0], utxo_to_spend=txin_spent)
5858
txid3 = tx3['txid']
5959
self.generate(self.nodes[0], 1)

test/functional/test_framework/wallet.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,9 @@ def get_utxo(self, *, txid: Optional[str]='', mark_as_spent=True):
133133
134134
Args:
135135
txid: get the first utxo we find from a specific transaction
136-
137-
Note: Can be used to get the change output immediately after a send_self_transfer
138136
"""
139137
index = -1 # by default the last utxo
138+
self._utxos = sorted(self._utxos, key=lambda k: (k['value'], -k['height'])) # Put the largest utxo last
140139
if txid:
141140
utxo = next(filter(lambda utxo: txid == utxo['txid'], self._utxos))
142141
index = self._utxos.index(utxo)
@@ -172,8 +171,7 @@ def send_to(self, *, from_node, scriptPubKey, amount, fee=1000):
172171

173172
def create_self_transfer(self, *, fee_rate=Decimal("0.003"), from_node, utxo_to_spend=None, mempool_valid=True, locktime=0, sequence=0):
174173
"""Create and return a tx with the specified fee_rate. Fee may be exact or at most one satoshi higher than needed."""
175-
self._utxos = sorted(self._utxos, key=lambda k: (k['value'], -k['height']))
176-
utxo_to_spend = utxo_to_spend or self._utxos.pop() # Pick the largest utxo (if none provided) and hope it covers the fee
174+
utxo_to_spend = utxo_to_spend or self.get_utxo()
177175
if self._priv_key is None:
178176
vsize = Decimal(104) # anyone-can-spend
179177
else:

0 commit comments

Comments
 (0)