Skip to content

Commit faba790

Browse files
author
MarcoFalke
committed
test: MiniWallet: Default fee_rate in send_self_transfer, Pass in utxo_to_spend
Adds two new features to MiniWallet: * The fee rate is irrelevant sometimes, so just set an arbitrary default * The utxo to spend needs to be selected manually sometimes
1 parent fa65a11 commit faba790

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

test/functional/test_framework/wallet.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,17 @@ def generate(self, num_blocks):
4040
self._utxos.append({'txid': cb_tx['txid'], 'vout': 0, 'value': cb_tx['vout'][0]['value']})
4141
return blocks
4242

43-
def send_self_transfer(self, *, fee_rate, from_node):
43+
def send_self_transfer(self, *, fee_rate=Decimal("0.003"), from_node, utxo_to_spend=None):
4444
"""Create and send a tx with the specified fee_rate. Fee may be exact or at most one satoshi higher than needed."""
4545
self._utxos = sorted(self._utxos, key=lambda k: k['value'])
46-
largest_utxo = self._utxos.pop() # Pick the largest utxo and hope it covers the fee
46+
utxo_to_spend = utxo_to_spend or self._utxos.pop() # Pick the largest utxo (if none provided) and hope it covers the fee
4747
vsize = Decimal(96)
48-
send_value = satoshi_round(largest_utxo['value'] - fee_rate * (vsize / 1000))
49-
fee = largest_utxo['value'] - send_value
48+
send_value = satoshi_round(utxo_to_spend['value'] - fee_rate * (vsize / 1000))
49+
fee = utxo_to_spend['value'] - send_value
5050
assert send_value > 0
5151

5252
tx = CTransaction()
53-
tx.vin = [CTxIn(COutPoint(int(largest_utxo['txid'], 16), largest_utxo['vout']))]
53+
tx.vin = [CTxIn(COutPoint(int(utxo_to_spend['txid'], 16), utxo_to_spend['vout']))]
5454
tx.vout = [CTxOut(int(send_value * COIN), self._scriptPubKey)]
5555
tx.wit.vtxinwit = [CTxInWitness()]
5656
tx.wit.vtxinwit[0].scriptWitness.stack = [CScript([OP_TRUE])]

0 commit comments

Comments
 (0)