mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-06 14:19:59 -05:00
Merge bitcoin/bitcoin#25773: test: Target exact weight in MiniWallet _bulk_tx
fa2537cf0a
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 ACKfa2537cf0a
Tree-SHA512: cf02c3082a13195b8aa730866aeaf2575ce01974ae2b0244739d8cfc12e60c66312729ed703bb3214651744166a3b560bfaa8dc302ef46ed79fc4d1fe7fcc214
This commit is contained in:
commit
2c3115d4f5
2 changed files with 10 additions and 7 deletions
|
@ -35,8 +35,8 @@ class MempoolPackageLimitsTest(BitcoinTestFramework):
|
||||||
self.test_anc_count_limits_2()
|
self.test_anc_count_limits_2()
|
||||||
self.test_anc_count_limits_bushy()
|
self.test_anc_count_limits_bushy()
|
||||||
|
|
||||||
# The node will accept our (nonstandard) extra large OP_RETURN outputs
|
# The node will accept (nonstandard) extra large OP_RETURN outputs
|
||||||
self.restart_node(0, extra_args=["-acceptnonstdtxn=1"])
|
self.restart_node(0, extra_args=["-datacarriersize=100000"])
|
||||||
self.test_anc_size_limits()
|
self.test_anc_size_limits()
|
||||||
self.test_desc_size_limits()
|
self.test_desc_size_limits()
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@ from test_framework.script import (
|
||||||
LegacySignatureHash,
|
LegacySignatureHash,
|
||||||
LEAF_VERSION_TAPSCRIPT,
|
LEAF_VERSION_TAPSCRIPT,
|
||||||
OP_NOP,
|
OP_NOP,
|
||||||
|
OP_RETURN,
|
||||||
OP_TRUE,
|
OP_TRUE,
|
||||||
SIGHASH_ALL,
|
SIGHASH_ALL,
|
||||||
taproot_construct,
|
taproot_construct,
|
||||||
|
@ -107,11 +108,13 @@ class MiniWallet:
|
||||||
"""Pad a transaction with extra outputs until it reaches a target weight (or higher).
|
"""Pad a transaction with extra outputs until it reaches a target weight (or higher).
|
||||||
returns the tx
|
returns the tx
|
||||||
"""
|
"""
|
||||||
assert_greater_than_or_equal(target_weight, tx.get_weight())
|
tx.vout.append(CTxOut(nValue=0, scriptPubKey=CScript([OP_RETURN, b'a'])))
|
||||||
while tx.get_weight() < target_weight:
|
dummy_vbytes = (target_weight - tx.get_weight() + 3) // 4
|
||||||
script_pubkey = ( b"6a4d0200" # OP_RETURN OP_PUSH2 512 bytes
|
tx.vout[-1].scriptPubKey = CScript([OP_RETURN, b'a' * dummy_vbytes])
|
||||||
+ b"01" * 512 )
|
# Lower bound should always be off by at most 3
|
||||||
tx.vout.append(CTxOut(0, script_pubkey))
|
assert_greater_than_or_equal(tx.get_weight(), target_weight)
|
||||||
|
# Higher bound should always be off by at most 3 + 12 weight (for encoding the length)
|
||||||
|
assert_greater_than_or_equal(target_weight + 15, tx.get_weight())
|
||||||
|
|
||||||
def get_balance(self):
|
def get_balance(self):
|
||||||
return sum(u['value'] for u in self._utxos)
|
return sum(u['value'] for u in self._utxos)
|
||||||
|
|
Loading…
Add table
Reference in a new issue