Skip to content

Commit 2222842

Browse files
author
MacroFake
committed
test: Allow absolute fee in MiniWallet create_self_transfer
1 parent c892cb7 commit 2222842

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

test/functional/test_framework/wallet.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def get_utxos(self, *, mark_as_spent=True):
197197
return utxos
198198

199199
def send_self_transfer(self, *, from_node, **kwargs):
200-
"""Create and send a tx with the specified fee_rate. Fee may be exact or at most one satoshi higher than needed."""
200+
"""Call create_self_transfer and send the transaction."""
201201
tx = self.create_self_transfer(**kwargs)
202202
self.sendrawtransaction(from_node=from_node, tx_hex=tx['hex'])
203203
return tx
@@ -272,16 +272,18 @@ def create_self_transfer_multi(
272272
"tx": tx,
273273
}
274274

275-
def create_self_transfer(self, *, fee_rate=Decimal("0.003"), utxo_to_spend=None, locktime=0, sequence=0):
276-
"""Create and return a tx with the specified fee_rate. Fee may be exact or at most one satoshi higher than needed."""
275+
def create_self_transfer(self, *, fee_rate=Decimal("0.003"), fee=Decimal("0"), utxo_to_spend=None, locktime=0, sequence=0):
276+
"""Create and return a tx with the specified fee. If fee is 0, use fee_rate, where the resulting fee may be exact or at most one satoshi higher than needed."""
277277
utxo_to_spend = utxo_to_spend or self.get_utxo()
278+
assert fee_rate >= 0
279+
assert fee >= 0
278280
if self._mode in (MiniWalletMode.RAW_OP_TRUE, MiniWalletMode.ADDRESS_OP_TRUE):
279281
vsize = Decimal(104) # anyone-can-spend
280282
elif self._mode == MiniWalletMode.RAW_P2PK:
281283
vsize = Decimal(168) # P2PK (73 bytes scriptSig + 35 bytes scriptPubKey + 60 bytes other)
282284
else:
283285
assert False
284-
send_value = utxo_to_spend["value"] - (fee_rate * vsize / 1000)
286+
send_value = utxo_to_spend["value"] - (fee or (fee_rate * vsize / 1000))
285287
assert send_value > 0
286288

287289
tx = CTransaction()

0 commit comments

Comments
 (0)