Skip to content

Commit fab6143

Browse files
author
MarcoFalke
committed
test: Refactor MiniWallet get_utxo helper
1 parent bf2c0fb commit fab6143

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

test/functional/test_framework/wallet.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
from decimal import Decimal
99
from enum import Enum
1010
from random import choice
11-
from typing import Optional
11+
from typing import (
12+
Any,
13+
Optional,
14+
)
1215
from test_framework.address import (
1316
base58_to_byte,
1417
create_deterministic_address_bcrt1_p2tr_op_true,
@@ -144,11 +147,12 @@ def get_utxo(self, *, txid: Optional[str]='', mark_as_spent=True):
144147
Args:
145148
txid: get the first utxo we find from a specific transaction
146149
"""
147-
index = -1 # by default the last utxo
148150
self._utxos = sorted(self._utxos, key=lambda k: (k['value'], -k['height'])) # Put the largest utxo last
149151
if txid:
150-
utxo = next(filter(lambda utxo: txid == utxo['txid'], self._utxos))
151-
index = self._utxos.index(utxo)
152+
utxo_filter: Any = filter(lambda utxo: txid == utxo['txid'], self._utxos)
153+
else:
154+
utxo_filter = reversed(self._utxos) # By default the largest utxo
155+
index = self._utxos.index(next(utxo_filter))
152156
if mark_as_spent:
153157
return self._utxos.pop(index)
154158
else:

0 commit comments

Comments
 (0)