66from test_framework .test_framework import BitcoinTestFramework
77from test_framework .util import *
88from test_framework .mininode import *
9- from binascii import hexlify , unhexlify
109from io import BytesIO
1110
1211class DecodeScriptTest (BitcoinTestFramework ):
@@ -131,7 +130,7 @@ def decoderawtransaction_asm_sighashtype(self):
131130 assert_equal ('OP_DUP OP_HASH160 dc863734a218bfe83ef770ee9d41a27f824a6e56 OP_EQUALVERIFY OP_CHECKSIG' , rpc_result ['vout' ][0 ]['scriptPubKey' ]['asm' ])
132131 assert_equal ('OP_HASH160 2a5edea39971049a540474c6a99edf0aa4074c58 OP_EQUAL' , rpc_result ['vout' ][1 ]['scriptPubKey' ]['asm' ])
133132 txSave = CTransaction ()
134- txSave .deserialize (BytesIO (unhexlify (tx )))
133+ txSave .deserialize (BytesIO (hex_str_to_bytes (tx )))
135134
136135 # make sure that a specifically crafted op_return value will not pass all the IsDERSignature checks and then get decoded as a sighash type
137136 tx = '01000000015ded05872fdbda629c7d3d02b194763ce3b9b1535ea884e3c8e765d42e316724020000006b48304502204c10d4064885c42638cbff3585915b322de33762598321145ba033fc796971e2022100bb153ad3baa8b757e30a2175bd32852d2e1cb9080f84d7e32fcdfd667934ef1b012103163c0ff73511ea1743fb5b98384a2ff09dd06949488028fd819f4d83f56264efffffffff0200000000000000000b6a0930060201000201000180380100000000001976a9141cabd296e753837c086da7a45a6c2fe0d49d7b7b88ac00000000'
@@ -147,7 +146,7 @@ def decoderawtransaction_asm_sighashtype(self):
147146 # some more full transaction tests of varying specific scriptSigs. used instead of
148147 # tests in decodescript_script_sig because the decodescript RPC is specifically
149148 # for working on scriptPubKeys (argh!).
150- push_signature = hexlify (txSave .vin [0 ].scriptSig )[2 :(0x48 * 2 + 4 )]
149+ push_signature = bytes_to_hex_str (txSave .vin [0 ].scriptSig )[2 :(0x48 * 2 + 4 )]
151150 signature = push_signature [2 :]
152151 der_signature = signature [:- 2 ]
153152 signature_sighash_decoded = der_signature + '[ALL]'
@@ -156,25 +155,24 @@ def decoderawtransaction_asm_sighashtype(self):
156155 signature_2_sighash_decoded = der_signature + '[NONE|ANYONECANPAY]'
157156
158157 # 1) P2PK scriptSig
159- txSave .vin [0 ].scriptSig = unhexlify (push_signature )
160- rpc_result = self .nodes [0 ].decoderawtransaction (hexlify (txSave .serialize ()))
158+ txSave .vin [0 ].scriptSig = hex_str_to_bytes (push_signature )
159+ rpc_result = self .nodes [0 ].decoderawtransaction (bytes_to_hex_str (txSave .serialize ()))
161160 assert_equal (signature_sighash_decoded , rpc_result ['vin' ][0 ]['scriptSig' ]['asm' ])
162161
163162 # make sure that the sighash decodes come out correctly for a more complex / lesser used case.
164- txSave .vin [0 ].scriptSig = unhexlify (push_signature_2 )
165- rpc_result = self .nodes [0 ].decoderawtransaction (hexlify (txSave .serialize ()))
163+ txSave .vin [0 ].scriptSig = hex_str_to_bytes (push_signature_2 )
164+ rpc_result = self .nodes [0 ].decoderawtransaction (bytes_to_hex_str (txSave .serialize ()))
166165 assert_equal (signature_2_sighash_decoded , rpc_result ['vin' ][0 ]['scriptSig' ]['asm' ])
167166
168167 # 2) multisig scriptSig
169- txSave .vin [0 ].scriptSig = unhexlify ('00' + push_signature + push_signature_2 )
170- rpc_result = self .nodes [0 ].decoderawtransaction (hexlify (txSave .serialize ()))
168+ txSave .vin [0 ].scriptSig = hex_str_to_bytes ('00' + push_signature + push_signature_2 )
169+ rpc_result = self .nodes [0 ].decoderawtransaction (bytes_to_hex_str (txSave .serialize ()))
171170 assert_equal ('0 ' + signature_sighash_decoded + ' ' + signature_2_sighash_decoded , rpc_result ['vin' ][0 ]['scriptSig' ]['asm' ])
172171
173172 # 3) test a scriptSig that contains more than push operations.
174173 # in fact, it contains an OP_RETURN with data specially crafted to cause improper decode if the code does not catch it.
175- txSave .vin [0 ].scriptSig = unhexlify ('6a143011020701010101010101020601010101010101' )
176- rpc_result = self .nodes [0 ].decoderawtransaction (hexlify (txSave .serialize ()))
177- print (hexlify ('636174' ))
174+ txSave .vin [0 ].scriptSig = hex_str_to_bytes ('6a143011020701010101010101020601010101010101' )
175+ rpc_result = self .nodes [0 ].decoderawtransaction (bytes_to_hex_str (txSave .serialize ()))
178176 assert_equal ('OP_RETURN 3011020701010101010101020601010101010101' , rpc_result ['vin' ][0 ]['scriptSig' ]['asm' ])
179177
180178 def run_test (self ):
0 commit comments