5
5
"""Test the SegWit changeover logic."""
6
6
7
7
from decimal import Decimal
8
- from io import BytesIO
9
8
10
9
from test_framework .address import (
11
10
key_to_p2pkh ,
14
13
script_to_p2sh_p2wsh ,
15
14
script_to_p2wsh ,
16
15
)
17
- from test_framework .blocktools import witness_script , send_to_witness
18
- from test_framework .messages import COIN , COutPoint , CTransaction , CTxIn , CTxOut , FromHex , sha256 , ToHex
19
- from test_framework .script import CScript , OP_HASH160 , OP_CHECKSIG , OP_0 , hash160 , OP_EQUAL , OP_DUP , OP_EQUALVERIFY , OP_1 , OP_2 , OP_CHECKMULTISIG , OP_TRUE , OP_DROP
16
+ from test_framework .blocktools import (
17
+ send_to_witness ,
18
+ witness_script ,
19
+ )
20
+ from test_framework .messages import (
21
+ COIN ,
22
+ COutPoint ,
23
+ CTransaction ,
24
+ CTxIn ,
25
+ CTxOut ,
26
+ ToHex ,
27
+ sha256 ,
28
+ tx_from_hex ,
29
+ )
30
+ from test_framework .script import (
31
+ CScript ,
32
+ OP_0 ,
33
+ OP_1 ,
34
+ OP_2 ,
35
+ OP_CHECKMULTISIG ,
36
+ OP_CHECKSIG ,
37
+ OP_DROP ,
38
+ OP_DUP ,
39
+ OP_EQUAL ,
40
+ OP_EQUALVERIFY ,
41
+ OP_HASH160 ,
42
+ OP_TRUE ,
43
+ hash160 ,
44
+ )
20
45
from test_framework .test_framework import BitcoinTestFramework
21
46
from test_framework .util import (
22
47
assert_equal ,
@@ -179,7 +204,7 @@ def run_test(self):
179
204
assert self .nodes [1 ].getblock (blockhash , False ) == self .nodes [2 ].getblock (blockhash , False )
180
205
181
206
for tx_id in segwit_tx_list :
182
- tx = FromHex ( CTransaction (), self .nodes [2 ].gettransaction (tx_id )["hex" ])
207
+ tx = tx_from_hex ( self .nodes [2 ].gettransaction (tx_id )["hex" ])
183
208
assert self .nodes [2 ].getrawtransaction (tx_id , False , blockhash ) != self .nodes [0 ].getrawtransaction (tx_id , False , blockhash )
184
209
assert self .nodes [1 ].getrawtransaction (tx_id , False , blockhash ) == self .nodes [2 ].getrawtransaction (tx_id , False , blockhash )
185
210
assert self .nodes [0 ].getrawtransaction (tx_id , False , blockhash ) != self .nodes [2 ].gettransaction (tx_id )["hex" ]
@@ -225,12 +250,12 @@ def run_test(self):
225
250
# tx1 is allowed to appear in the block, but no others.
226
251
txid1 = send_to_witness (1 , self .nodes [0 ], find_spendable_utxo (self .nodes [0 ], 50 ), self .pubkey [0 ], False , Decimal ("49.996" ))
227
252
hex_tx = self .nodes [0 ].gettransaction (txid )['hex' ]
228
- tx = FromHex ( CTransaction (), hex_tx )
253
+ tx = tx_from_hex ( hex_tx )
229
254
assert tx .wit .is_null () # This should not be a segwit input
230
255
assert txid1 in self .nodes [0 ].getrawmempool ()
231
256
232
257
tx1_hex = self .nodes [0 ].gettransaction (txid1 )['hex' ]
233
- tx1 = FromHex ( CTransaction (), tx1_hex )
258
+ tx1 = tx_from_hex ( tx1_hex )
234
259
235
260
# Check that wtxid is properly reported in mempool entry (txid1)
236
261
assert_equal (int (self .nodes [0 ].getmempoolentry (txid1 )["wtxid" ], 16 ), tx1 .calc_sha256 (True ))
@@ -245,7 +270,7 @@ def run_test(self):
245
270
tx .vout .append (CTxOut (int (49.99 * COIN ), CScript ([OP_TRUE , OP_DROP ] * 15 + [OP_TRUE ])))
246
271
tx2_hex = self .nodes [0 ].signrawtransactionwithwallet (ToHex (tx ))['hex' ]
247
272
txid2 = self .nodes [0 ].sendrawtransaction (tx2_hex )
248
- tx = FromHex ( CTransaction (), tx2_hex )
273
+ tx = tx_from_hex ( tx2_hex )
249
274
assert not tx .wit .is_null ()
250
275
251
276
# Check that wtxid is properly reported in mempool entry (txid2)
@@ -611,10 +636,8 @@ def p2pkh_address_to_script(self, v):
611
636
def create_and_mine_tx_from_txids (self , txids , success = True ):
612
637
tx = CTransaction ()
613
638
for i in txids :
614
- txtmp = CTransaction ()
615
639
txraw = self .nodes [0 ].getrawtransaction (i , 0 , txs_mined [i ])
616
- f = BytesIO (hex_str_to_bytes (txraw ))
617
- txtmp .deserialize (f )
640
+ txtmp = tx_from_hex (txraw )
618
641
for j in range (len (txtmp .vout )):
619
642
tx .vin .append (CTxIn (COutPoint (int ('0x' + i , 0 ), j )))
620
643
tx .vout .append (CTxOut (0 , CScript ()))
0 commit comments