test: replace ValidWitnessMalleatedTx class with function

Simplify the witness malleation test helper by converting the
ValidWitnessMalleatedTx class to a standalone function
build_malleated_tx_package() and updating call sites.

Co-authored-by: rkrux <rkrux.connect@gmail.com>
This commit is contained in:
naiyomaandrkrux committed 2026-01-21 14:07:59 +03:00
1 parent 81675a781f
commit 7cfe790820
3 files changed
+61 -54

No files matched your search

+17 -14
View File
@@ -7,17 +7,16 @@ Test mempool acceptance in case of an already known transaction
with identical non-witness data but different witness.
"""
from test_framework.messages import (
COIN,
)
from test_framework.p2p import P2PTxInvStore
from test_framework.script_util import ValidWitnessMalleatedTx
from test_framework.script_util import build_malleated_tx_package
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
assert_not_equal,
assert_equal,
)
from test_framework.wallet import (
MiniWallet,
)
class MempoolWtxidTest(BitcoinTestFramework):
def set_test_params(self):
@@ -25,23 +24,27 @@ class MempoolWtxidTest(BitcoinTestFramework):
def run_test(self):
node = self.nodes[0]
mini_wallet = MiniWallet(node)
self.log.info('Start with pre-generated blocks')
blockhash = self.nodes[0].getblockhash(1)
txid = node.getblock(blockhash=blockhash, verbosity=2)["tx"][0]["txid"]
assert_equal(node.getmempoolinfo()['size'], 0)
self.log.info("Submit parent with multiple script branches to mempool")
txgen = ValidWitnessMalleatedTx()
parent = txgen.build_parent_tx(txid, 9.99998 * COIN)
privkeys = [node.get_deterministic_priv_key().key]
raw_parent = node.signrawtransactionwithkey(hexstring=parent.serialize().hex(), privkeys=privkeys)['hex']
signed_parent_txid = node.sendrawtransaction(hexstring=raw_parent, maxfeerate=0)
parent = mini_wallet.create_self_transfer()["tx"]
parent_amount = parent.vout[0].nValue - 10000
child_amount = parent_amount - 10000
parent, child_one, child_two = build_malleated_tx_package(
parent=parent,
rebalance_parent_output_amount=parent_amount,
child_amount=child_amount
)
mini_wallet.sendrawtransaction(from_node=node, tx_hex=parent.serialize().hex())
self.generate(node, 1)
peer_wtxid_relay = node.add_p2p_connection(P2PTxInvStore())
child_one, child_two = txgen.build_malleated_children(signed_parent_txid, 9.99996 * COIN)
child_one_wtxid = child_one.wtxid_hex
child_one_txid = child_one.txid_hex
child_two_wtxid = child_two.wtxid_hex