Skip to content

Commit 4ac1efb

Browse files
committed
Merge bitcoin#30322: test: raise an error in _bulk_tx_ when target_vsize is too low
92787dd test: raise an error when target_vsize is below tx virtual size (ismaelsadeeq) a8780c9 test: raise an error if output value is <= 0 in `create_self_transfer` (ismaelsadeeq) f6e8893 test: test that `create_self_transfer_multi` respects `target_vsize` (ismaelsadeeq) Pull request description: This is a simple test PR that does two things: 1. Raise an exception in `_bulk_tx_` when `target_vsize` is too low, i.e., below the tx vsize. 2. Addresses some review comments from bitcoin#30162, which are: - Raise an error if the output value is less than or equal to zero in `create_self_transfer`. This prevents creating transactions with a value of 0 or less. - Add a test to verify that `create_self_transfer_multi` also respects the passed `target_vsize`. ACKs for top commit: achow101: ACK 92787dd theStack: ACK 92787dd rkrux: reACK 92787dd glozow: ACK 92787dd Tree-SHA512: 1f2767f2cf715ed65074c5fff347eec160b142685777d833d5e872cfef364d3dc1916b52ee442e99c7b9a8d514ff62bc67a9899d8854f65a4b93ac3ae300d18e
2 parents 8775731 + 92787dd commit 4ac1efb

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

test/functional/feature_framework_miniwallet.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@ def test_tx_padding(self):
2929
utxo = wallet.get_utxo(mark_as_spent=False)
3030
for target_vsize in [250, 500, 1250, 2500, 5000, 12500, 25000, 50000, 1000000,
3131
248, 501, 1085, 3343, 5805, 12289, 25509, 55855, 999998]:
32-
tx = wallet.create_self_transfer(utxo_to_spend=utxo, target_vsize=target_vsize)["tx"]
33-
assert_equal(tx.get_vsize(), target_vsize)
32+
tx = wallet.create_self_transfer(utxo_to_spend=utxo, target_vsize=target_vsize)
33+
assert_equal(tx['tx'].get_vsize(), target_vsize)
34+
child_tx = wallet.create_self_transfer_multi(utxos_to_spend=[tx["new_utxo"]], target_vsize=target_vsize)
35+
assert_equal(child_tx['tx'].get_vsize(), target_vsize)
36+
3437

3538
def test_wallet_tagging(self):
3639
"""Verify that tagged wallet instances are able to send funds."""

test/functional/test_framework/wallet.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ def _bulk_tx(self, tx, target_vsize):
121121
"""Pad a transaction with extra outputs until it reaches a target vsize.
122122
returns the tx
123123
"""
124+
if target_vsize < tx.get_vsize():
125+
raise RuntimeError(f"target_vsize {target_vsize} is less than transaction virtual size {tx.get_vsize()}")
126+
124127
tx.vout.append(CTxOut(nValue=0, scriptPubKey=CScript([OP_RETURN])))
125128
# determine number of needed padding bytes
126129
dummy_vbytes = target_vsize - tx.get_vsize()
@@ -378,7 +381,8 @@ def create_self_transfer(
378381
if target_vsize and not fee: # respect fee_rate if target vsize is passed
379382
fee = get_fee(target_vsize, fee_rate)
380383
send_value = utxo_to_spend["value"] - (fee or (fee_rate * vsize / 1000))
381-
384+
if send_value <= 0:
385+
raise RuntimeError(f"UTXO value {utxo_to_spend['value']} is too small to cover fees {(fee or (fee_rate * vsize / 1000))}")
382386
# create tx
383387
tx = self.create_self_transfer_multi(
384388
utxos_to_spend=[utxo_to_spend],

0 commit comments

Comments
 (0)