7
7
with identical non-witness data but different witness.
8
8
"""
9
9
10
- from copy import deepcopy
11
10
from test_framework .messages import (
12
11
COIN ,
13
- COutPoint ,
14
- CTransaction ,
15
- CTxIn ,
16
- CTxInWitness ,
17
- CTxOut ,
18
- sha256 ,
19
12
)
20
13
from test_framework .p2p import P2PTxInvStore
21
- from test_framework .script import (
22
- CScript ,
23
- OP_0 ,
24
- OP_ELSE ,
25
- OP_ENDIF ,
26
- OP_EQUAL ,
27
- OP_HASH160 ,
28
- OP_IF ,
29
- OP_TRUE ,
30
- hash160 ,
31
- )
14
+ from test_framework .script_util import ValidWitnessMalleatedTx
32
15
from test_framework .test_framework import BitcoinTestFramework
33
16
from test_framework .util import (
34
17
assert_not_equal ,
35
18
assert_equal ,
36
19
)
37
20
21
+
38
22
class MempoolWtxidTest (BitcoinTestFramework ):
39
23
def set_test_params (self ):
40
24
self .num_nodes = 1
@@ -50,38 +34,19 @@ def run_test(self):
50
34
assert_equal (node .getmempoolinfo ()['size' ], 0 )
51
35
52
36
self .log .info ("Submit parent with multiple script branches to mempool" )
53
- hashlock = hash160 (b'Preimage' )
54
- witness_script = CScript ([OP_IF , OP_HASH160 , hashlock , OP_EQUAL , OP_ELSE , OP_TRUE , OP_ENDIF ])
55
- witness_program = sha256 (witness_script )
56
- script_pubkey = CScript ([OP_0 , witness_program ])
57
-
58
- parent = CTransaction ()
59
- parent .vin .append (CTxIn (COutPoint (int (txid , 16 ), 0 ), b"" ))
60
- parent .vout .append (CTxOut (int (9.99998 * COIN ), script_pubkey ))
37
+ txgen = ValidWitnessMalleatedTx ()
38
+ parent = txgen .build_parent_tx (txid , 9.99998 * COIN )
61
39
62
40
privkeys = [node .get_deterministic_priv_key ().key ]
63
41
raw_parent = node .signrawtransactionwithkey (hexstring = parent .serialize ().hex (), privkeys = privkeys )['hex' ]
64
- parent_txid = node .sendrawtransaction (hexstring = raw_parent , maxfeerate = 0 )
42
+ signed_parent_txid = node .sendrawtransaction (hexstring = raw_parent , maxfeerate = 0 )
65
43
self .generate (node , 1 )
66
44
67
45
peer_wtxid_relay = node .add_p2p_connection (P2PTxInvStore ())
68
46
69
- # Create a new transaction with witness solving first branch
70
- child_witness_script = CScript ([OP_TRUE ])
71
- child_witness_program = sha256 (child_witness_script )
72
- child_script_pubkey = CScript ([OP_0 , child_witness_program ])
73
-
74
- child_one = CTransaction ()
75
- child_one .vin .append (CTxIn (COutPoint (int (parent_txid , 16 ), 0 ), b"" ))
76
- child_one .vout .append (CTxOut (int (9.99996 * COIN ), child_script_pubkey ))
77
- child_one .wit .vtxinwit .append (CTxInWitness ())
78
- child_one .wit .vtxinwit [0 ].scriptWitness .stack = [b'Preimage' , b'\x01 ' , witness_script ]
47
+ child_one , child_two = txgen .build_malleated_children (signed_parent_txid , 9.99996 * COIN )
79
48
child_one_wtxid = child_one .wtxid_hex
80
49
child_one_txid = child_one .txid_hex
81
-
82
- # Create another identical transaction with witness solving second branch
83
- child_two = deepcopy (child_one )
84
- child_two .wit .vtxinwit [0 ].scriptWitness .stack = [b'' , witness_script ]
85
50
child_two_wtxid = child_two .wtxid_hex
86
51
child_two_txid = child_two .txid_hex
87
52
0 commit comments