From c2fd4fe379f6bb123b5127d466e3ee00daf69715 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Mon, 15 Nov 2021 17:19:52 +0100 Subject: [PATCH] Merge bitcoin/bitcoin#23515: test: Return the largest utxo in MiniWallet.get_utxo fa62207737657e76ba45d5bf826fc0ccac658df6 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 --- test/functional/rpc_txoutproof.py | 2 +- test/functional/test_framework/wallet.py | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/test/functional/rpc_txoutproof.py b/test/functional/rpc_txoutproof.py index 34eb48a89e..9fed9cbe15 100755 --- a/test/functional/rpc_txoutproof.py +++ b/test/functional/rpc_txoutproof.py @@ -54,7 +54,7 @@ class MerkleBlockTest(BitcoinTestFramework): assert_equal(self.nodes[0].verifytxoutproof(self.nodes[0].gettxoutproof([txid1, txid2])), txlist) assert_equal(self.nodes[0].verifytxoutproof(self.nodes[0].gettxoutproof([txid1, txid2], blockhash)), txlist) - txin_spent = miniwallet.get_utxo() # Get the change from txid2 + txin_spent = miniwallet.get_utxo(txid=txid2) # Get the change from txid2 tx3 = miniwallet.send_self_transfer(from_node=self.nodes[0], utxo_to_spend=txin_spent) txid3 = tx3['txid'] self.generate(self.nodes[0], 1) diff --git a/test/functional/test_framework/wallet.py b/test/functional/test_framework/wallet.py index 6d494ee2c6..d0285f3ad9 100644 --- a/test/functional/test_framework/wallet.py +++ b/test/functional/test_framework/wallet.py @@ -135,10 +135,9 @@ class MiniWallet: Args: txid: get the first utxo we find from a specific transaction - - Note: Can be used to get the change output immediately after a send_self_transfer """ index = -1 # by default the last utxo + self._utxos = sorted(self._utxos, key=lambda k: (k['value'], -k['height'])) # Put the largest utxo last if txid: utxo = next(filter(lambda utxo: txid == utxo['txid'], self._utxos)) index = self._utxos.index(utxo) @@ -155,8 +154,7 @@ class MiniWallet: def create_self_transfer(self, *, fee_rate=Decimal("0.003"), from_node, utxo_to_spend=None, mempool_valid=True, locktime=0, sequence=0): """Create and return a tx with the specified fee_rate. Fee may be exact or at most one satoshi higher than needed.""" - self._utxos = sorted(self._utxos, key=lambda k: (k['value'], -k['height'])) - utxo_to_spend = utxo_to_spend or self._utxos.pop() # Pick the largest utxo (if none provided) and hope it covers the fee + utxo_to_spend = utxo_to_spend or self.get_utxo() if self._priv_key is None: vsize = Decimal(85) # anyone-can-spend else: