Skip to content

Commit 8403e0e

Browse files
committed
Merge bitcoin#25773: test: Target exact weight in MiniWallet _bulk_tx
fa2537c test: Target exact weight in MiniWallet _bulk_tx (MacroFake) Pull request description: Seems better to target the exact weight than a weight that is up to more than 2000 WU larger. Also, replace a broad `-acceptnonstdtxn=1` with `-datacarriersize=100000` to document the test assumptions better. ACKs for top commit: theStack: Code-review ACK fa2537c Tree-SHA512: cf02c3082a13195b8aa730866aeaf2575ce01974ae2b0244739d8cfc12e60c66312729ed703bb3214651744166a3b560bfaa8dc302ef46ed79fc4d1fe7fcc214
1 parent 2241b09 commit 8403e0e

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

test/functional/mempool_package_limits.py

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

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

test/functional/test_framework/wallet.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@
2929
)
3030
from test_framework.script import (
3131
CScript,
32-
SignatureHash,
33-
OP_TRUE,
3432
OP_NOP,
33+
OP_RETURN,
34+
OP_TRUE,
35+
SignatureHash,
3536
SIGHASH_ALL,
3637
)
3738
from test_framework.script_util import (
@@ -97,11 +98,13 @@ def _bulk_tx(self, tx, target_weight):
9798
"""Pad a transaction with extra outputs until it reaches a target weight (or higher).
9899
returns the tx
99100
"""
100-
assert_greater_than_or_equal(target_weight, tx.get_weight())
101-
while tx.get_weight() < target_weight:
102-
script_pubkey = ( b"6a4d0200" # OP_RETURN OP_PUSH2 512 bytes
103-
+ b"01" * 512 )
104-
tx.vout.append(CTxOut(0, script_pubkey))
101+
tx.vout.append(CTxOut(nValue=0, scriptPubKey=CScript([OP_RETURN, b'a'])))
102+
dummy_vbytes = (target_weight - tx.get_weight() + 3) // 4
103+
tx.vout[-1].scriptPubKey = CScript([OP_RETURN, b'a' * dummy_vbytes])
104+
# Lower bound should always be off by at most 3
105+
assert_greater_than_or_equal(tx.get_weight(), target_weight)
106+
# Higher bound should always be off by at most 3 + 12 weight (for encoding the length)
107+
assert_greater_than_or_equal(target_weight + 15, tx.get_weight())
105108

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

0 commit comments

Comments
 (0)