Merge bitcoin/bitcoin#33067: test: refactor ValidWitnessMalleatedTx class to helper function

3f5211cba8 test: remove child_one/child_two (w)txid variables (naiyoma)
7cfe790820 test: replace ValidWitnessMalleatedTx class with function (naiyoma)
81675a781f test: use pre-generated chain (naiyoma)

Pull request description:

  This PR refactors ` ValidWitnessMalleatedTx` class into a `build_malleated_tx_package` function. As a result, two tests are updated:  `mempool_accept_wtxid` and `p2p_p2p_private_broadcast`. Also included are a  few small refactors in mempool_accept_wtxid , (switching to MiniWallet, using a pre-mined chain, using txid directly.)

  Together, these changes reduce complexity and improve test runtime.

ACKs for top commit:
  stratospher:
    reACK 3f5211c.
  cedwies:
    reACK 3f5211c
  maflcko:
    review ACK 3f5211cba8 👥
  rkrux:
    ACK 3f5211cba8

Tree-SHA512: 1fd02be3432fef6b68e54fbe8b15ed56d2699580bb13d0777b21f9cbe4c6d33bbb710541e3ca2fc93eab771d17bf1c427e4b08fa216d561bdb320cc6b36ac8fc
This commit is contained in:
merge-script committed 2026-01-27 10:10:41 +00:00
commit 8593d96519
3 files changed
+70 -71

No files matched your search

+8 -8
View File
@@ -18,7 +18,6 @@ from test_framework.p2p import (
from test_framework.messages import (
CAddress,
CInv,
COIN,
MSG_WTX,
malleate_tx_to_invalid_witness,
msg_inv,
@@ -27,7 +26,7 @@ from test_framework.messages import (
from test_framework.netutil import (
format_addr_port
)
from test_framework.script_util import ValidWitnessMalleatedTx
from test_framework.script_util import build_malleated_tx_package
from test_framework.socks5 import (
Socks5Configuration,
Socks5Server,
@@ -399,16 +398,17 @@ class P2PPrivateBroadcast(BitcoinTestFramework):
tx_originator.setmocktime(0) # Let the clock tick again (it will go backwards due to this).
self.log.info("Sending a pair of transactions with the same txid but different valid wtxids via RPC")
txgen = ValidWitnessMalleatedTx()
funding = wallet.get_utxo()
fee_sat = 1000
siblings_parent = txgen.build_parent_tx(funding["txid"], amount=funding["value"] * COIN - fee_sat)
sibling1, sibling2 = txgen.build_malleated_children(siblings_parent.txid_hex, amount=siblings_parent.vout[0].nValue - fee_sat)
parent = wallet.create_self_transfer()["tx"]
parent_amount = parent.vout[0].nValue - 10000
child_amount = parent_amount - 10000
siblings_parent, sibling1, sibling2 = build_malleated_tx_package(
parent=parent,
rebalance_parent_output_amount=parent_amount,
child_amount=child_amount)
self.log.info(f" - sibling1: txid={sibling1.txid_hex}, wtxid={sibling1.wtxid_hex}")
self.log.info(f" - sibling2: txid={sibling2.txid_hex}, wtxid={sibling2.wtxid_hex}")
assert_equal(sibling1.txid_hex, sibling2.txid_hex)
assert_not_equal(sibling1.wtxid_hex, sibling2.wtxid_hex)
wallet.sign_tx(siblings_parent)
assert_equal(len(tx_originator.getrawmempool()), 1)
tx_returner.send_without_ping(msg_tx(siblings_parent))
self.wait_until(lambda: len(tx_originator.getrawmempool()) > 1)