Skip to content

Commit fa2537c

Browse files
author
MacroFake
committed
test: Target exact weight in MiniWallet _bulk_tx
Also, replace broad -acceptnonstdtxn=1 with -datacarriersize=100000
1 parent 9155f9b commit fa2537c

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

test/functional/mempool_package_limits.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ def run_test(self):
3535
self.test_anc_count_limits_2()
3636
self.test_anc_count_limits_bushy()
3737

38-
# The node will accept our (nonstandard) extra large OP_RETURN outputs
39-
self.restart_node(0, extra_args=["-acceptnonstdtxn=1"])
38+
# The node will accept (nonstandard) extra large OP_RETURN outputs
39+
self.restart_node(0, extra_args=["-datacarriersize=100000"])
4040
self.test_anc_size_limits()
4141
self.test_desc_size_limits()
4242

test/functional/test_framework/wallet.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
LegacySignatureHash,
4040
LEAF_VERSION_TAPSCRIPT,
4141
OP_NOP,
42+
OP_RETURN,
4243
OP_TRUE,
4344
SIGHASH_ALL,
4445
taproot_construct,
@@ -107,11 +108,13 @@ def _bulk_tx(self, tx, target_weight):
107108
"""Pad a transaction with extra outputs until it reaches a target weight (or higher).
108109
returns the tx
109110
"""
110-
assert_greater_than_or_equal(target_weight, tx.get_weight())
111-
while tx.get_weight() < target_weight:
112-
script_pubkey = ( b"6a4d0200" # OP_RETURN OP_PUSH2 512 bytes
113-
+ b"01" * 512 )
114-
tx.vout.append(CTxOut(0, script_pubkey))
111+
tx.vout.append(CTxOut(nValue=0, scriptPubKey=CScript([OP_RETURN, b'a'])))
112+
dummy_vbytes = (target_weight - tx.get_weight() + 3) // 4
113+
tx.vout[-1].scriptPubKey = CScript([OP_RETURN, b'a' * dummy_vbytes])
114+
# Lower bound should always be off by at most 3
115+
assert_greater_than_or_equal(tx.get_weight(), target_weight)
116+
# Higher bound should always be off by at most 3 + 12 weight (for encoding the length)
117+
assert_greater_than_or_equal(target_weight + 15, tx.get_weight())
115118

116119
def get_balance(self):
117120
return sum(u['value'] for u in self._utxos)

0 commit comments

Comments
 (0)