From f6e88931f071f06cb8aefeac61cf3bce662eea74 Mon Sep 17 00:00:00 2001 From: ismaelsadeeq Date: Sat, 22 Jun 2024 13:16:23 +0100 Subject: [PATCH 1/3] test: test that `create_self_transfer_multi` respects `target_vsize` --- test/functional/feature_framework_miniwallet.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/functional/feature_framework_miniwallet.py b/test/functional/feature_framework_miniwallet.py index f723f7f31e..e92ea1b339 100755 --- a/test/functional/feature_framework_miniwallet.py +++ b/test/functional/feature_framework_miniwallet.py @@ -29,8 +29,11 @@ class FeatureFrameworkMiniWalletTest(BitcoinTestFramework): utxo = wallet.get_utxo(mark_as_spent=False) for target_vsize in [250, 500, 1250, 2500, 5000, 12500, 25000, 50000, 1000000, 248, 501, 1085, 3343, 5805, 12289, 25509, 55855, 999998]: - tx = wallet.create_self_transfer(utxo_to_spend=utxo, target_vsize=target_vsize)["tx"] - assert_equal(tx.get_vsize(), target_vsize) + tx = wallet.create_self_transfer(utxo_to_spend=utxo, target_vsize=target_vsize) + assert_equal(tx['tx'].get_vsize(), target_vsize) + child_tx = wallet.create_self_transfer_multi(utxos_to_spend=[tx["new_utxo"]], target_vsize=target_vsize) + assert_equal(child_tx['tx'].get_vsize(), target_vsize) + def test_wallet_tagging(self): """Verify that tagged wallet instances are able to send funds.""" From a8780c937f730f4fa2ef2045458e3908bb2176e4 Mon Sep 17 00:00:00 2001 From: ismaelsadeeq Date: Sat, 22 Jun 2024 14:13:54 +0100 Subject: [PATCH 2/3] test: raise an error if output value is <= 0 in `create_self_transfer` --- test/functional/test_framework/wallet.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/functional/test_framework/wallet.py b/test/functional/test_framework/wallet.py index 1cef714705..32045e2332 100644 --- a/test/functional/test_framework/wallet.py +++ b/test/functional/test_framework/wallet.py @@ -378,7 +378,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], From 92787dd52cd4ddc378cf1bcb7e92a649916a0f42 Mon Sep 17 00:00:00 2001 From: ismaelsadeeq Date: Tue, 1 Oct 2024 23:21:29 +0100 Subject: [PATCH 3/3] test: raise an error when target_vsize is below tx virtual size --- test/functional/test_framework/wallet.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/functional/test_framework/wallet.py b/test/functional/test_framework/wallet.py index 32045e2332..0a8c08474f 100644 --- a/test/functional/test_framework/wallet.py +++ b/test/functional/test_framework/wallet.py @@ -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()