Merge bitcoin/bitcoin#30322: test: raise an error in _bulk_tx_ when target_vsize is too low

92787dd52c test: raise an error when target_vsize is below tx virtual size (ismaelsadeeq)
a8780c937f test: raise an error if output value is <= 0 in `create_self_transfer` (ismaelsadeeq)
f6e88931f0 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 https://github.com/bitcoin/bitcoin/pull/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 92787dd52c
  theStack:
    ACK 92787dd52c
  rkrux:
    reACK 92787dd52c
  glozow:
    ACK 92787dd52c

Tree-SHA512: 1f2767f2cf715ed65074c5fff347eec160b142685777d833d5e872cfef364d3dc1916b52ee442e99c7b9a8d514ff62bc67a9899d8854f65a4b93ac3ae300d18e
This commit is contained in:
Ava Chow
2025-01-24 18:27:32 -05:00
2 changed files with 10 additions and 3 deletions

View File

@ -121,6 +121,9 @@ class MiniWallet:
"""Pad a transaction with extra outputs until it reaches a target vsize.
returns the tx
"""
if target_vsize < tx.get_vsize():
raise RuntimeError(f"target_vsize {target_vsize} is less than transaction virtual size {tx.get_vsize()}")
tx.vout.append(CTxOut(nValue=0, scriptPubKey=CScript([OP_RETURN])))
# determine number of needed padding bytes
dummy_vbytes = target_vsize - tx.get_vsize()
@ -378,7 +381,8 @@ class MiniWallet:
if target_vsize and not fee: # respect fee_rate if target vsize is passed
fee = get_fee(target_vsize, fee_rate)
send_value = utxo_to_spend["value"] - (fee or (fee_rate * vsize / 1000))
if send_value <= 0:
raise RuntimeError(f"UTXO value {utxo_to_spend['value']} is too small to cover fees {(fee or (fee_rate * vsize / 1000))}")
# create tx
tx = self.create_self_transfer_multi(
utxos_to_spend=[utxo_to_spend],