mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-03 20:35:17 +02:00
test: extract bulk_vout from bulk_tx so it can be used by wallet tests
This commit is contained in:
@@ -13,6 +13,7 @@ from test_framework.messages import (
|
||||
CTxIn,
|
||||
CTxInWitness,
|
||||
CTxOut,
|
||||
ser_compact_size,
|
||||
sha256,
|
||||
)
|
||||
from test_framework.script import (
|
||||
@@ -35,6 +36,8 @@ from test_framework.script import (
|
||||
hash160,
|
||||
)
|
||||
|
||||
from test_framework.util import assert_equal
|
||||
|
||||
# Maximum number of potentially executed legacy signature operations in validating a transaction.
|
||||
MAX_STD_LEGACY_SIGOPS = 2_500
|
||||
|
||||
@@ -128,6 +131,16 @@ def script_to_p2sh_p2wsh_script(script):
|
||||
p2shscript = CScript([OP_0, sha256(script)])
|
||||
return script_to_p2sh_script(p2shscript)
|
||||
|
||||
def bulk_vout(tx, target_vsize):
|
||||
if target_vsize < tx.get_vsize():
|
||||
raise RuntimeError(f"target_vsize {target_vsize} is less than transaction virtual size {tx.get_vsize()}")
|
||||
# determine number of needed padding bytes
|
||||
dummy_vbytes = target_vsize - tx.get_vsize()
|
||||
# compensate for the increase of the compact-size encoded script length
|
||||
# (note that the length encoding of the unpadded output script needs one byte)
|
||||
dummy_vbytes -= len(ser_compact_size(dummy_vbytes)) - 1
|
||||
tx.vout[-1].scriptPubKey = CScript([OP_RETURN] + [OP_1] * dummy_vbytes)
|
||||
assert_equal(tx.get_vsize(), target_vsize)
|
||||
|
||||
def output_key_to_p2tr_script(key):
|
||||
assert len(key) == 32
|
||||
|
||||
Reference in New Issue
Block a user