Changeset View
Changeset View
Standalone View
Standalone View
test/functional/rpc_decodescript.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2015-2016 The Bitcoin Core developers | # Copyright (c) 2015-2016 The Bitcoin Core developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import * | from test_framework.util import * | ||||
from test_framework.mininode import * | from test_framework.messages import CTransaction, FromHex, ToHex | ||||
class DecodeScriptTest(BitcoinTestFramework): | class DecodeScriptTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.setup_clean_chain = True | self.setup_clean_chain = True | ||||
self.num_nodes = 1 | self.num_nodes = 1 | ||||
def decodescript_script_sig(self): | def decodescript_script_sig(self): | ||||
▲ Show 20 Lines • Show All 157 Lines • ▼ Show 20 Lines | def decoderawtransaction_asm_sighashtype(self): | ||||
der_signature = signature[:-2] | der_signature = signature[:-2] | ||||
signature_sighash_decoded = der_signature + '[ALL]' | signature_sighash_decoded = der_signature + '[ALL]' | ||||
signature_2 = der_signature + '82' | signature_2 = der_signature + '82' | ||||
push_signature_2 = '48' + signature_2 | push_signature_2 = '48' + signature_2 | ||||
signature_2_sighash_decoded = der_signature + '[NONE|ANYONECANPAY]' | signature_2_sighash_decoded = der_signature + '[NONE|ANYONECANPAY]' | ||||
# 1) P2PK scriptSig | # 1) P2PK scriptSig | ||||
txSave.vin[0].scriptSig = hex_str_to_bytes(push_signature) | txSave.vin[0].scriptSig = hex_str_to_bytes(push_signature) | ||||
rpc_result = self.nodes[0].decoderawtransaction( | rpc_result = self.nodes[0].decoderawtransaction(ToHex(txSave)) | ||||
bytes_to_hex_str(txSave.serialize())) | |||||
assert_equal(signature_sighash_decoded, | assert_equal(signature_sighash_decoded, | ||||
rpc_result['vin'][0]['scriptSig']['asm']) | rpc_result['vin'][0]['scriptSig']['asm']) | ||||
# make sure that the sighash decodes come out correctly for a more | # make sure that the sighash decodes come out correctly for a more | ||||
# complex / lesser used case. | # complex / lesser used case. | ||||
txSave.vin[0].scriptSig = hex_str_to_bytes(push_signature_2) | txSave.vin[0].scriptSig = hex_str_to_bytes(push_signature_2) | ||||
rpc_result = self.nodes[0].decoderawtransaction( | rpc_result = self.nodes[0].decoderawtransaction(ToHex(txSave)) | ||||
bytes_to_hex_str(txSave.serialize())) | |||||
assert_equal(signature_2_sighash_decoded, | assert_equal(signature_2_sighash_decoded, | ||||
rpc_result['vin'][0]['scriptSig']['asm']) | rpc_result['vin'][0]['scriptSig']['asm']) | ||||
# 2) multisig scriptSig | # 2) multisig scriptSig | ||||
txSave.vin[0].scriptSig = hex_str_to_bytes( | txSave.vin[0].scriptSig = hex_str_to_bytes( | ||||
'00' + push_signature + push_signature_2) | '00' + push_signature + push_signature_2) | ||||
rpc_result = self.nodes[0].decoderawtransaction( | rpc_result = self.nodes[0].decoderawtransaction(ToHex(txSave)) | ||||
bytes_to_hex_str(txSave.serialize())) | |||||
assert_equal('0 ' + signature_sighash_decoded + ' ' + | assert_equal('0 ' + signature_sighash_decoded + ' ' + | ||||
signature_2_sighash_decoded, rpc_result['vin'][0]['scriptSig']['asm']) | signature_2_sighash_decoded, rpc_result['vin'][0]['scriptSig']['asm']) | ||||
# 3) test a scriptSig that contains more than push operations. | # 3) test a scriptSig that contains more than push operations. | ||||
# in fact, it contains an OP_RETURN with data specially crafted to | # in fact, it contains an OP_RETURN with data specially crafted to | ||||
# cause improper decode if the code does not catch it. | # cause improper decode if the code does not catch it. | ||||
txSave.vin[0].scriptSig = hex_str_to_bytes( | txSave.vin[0].scriptSig = hex_str_to_bytes( | ||||
'6a143011020701010101010101020601010101010101') | '6a143011020701010101010101020601010101010101') | ||||
rpc_result = self.nodes[0].decoderawtransaction( | rpc_result = self.nodes[0].decoderawtransaction(ToHex(txSave)) | ||||
bytes_to_hex_str(txSave.serialize())) | |||||
assert_equal('OP_RETURN 3011020701010101010101020601010101010101', | assert_equal('OP_RETURN 3011020701010101010101020601010101010101', | ||||
rpc_result['vin'][0]['scriptSig']['asm']) | rpc_result['vin'][0]['scriptSig']['asm']) | ||||
def run_test(self): | def run_test(self): | ||||
self.decodescript_script_sig() | self.decodescript_script_sig() | ||||
self.decodescript_script_pub_key() | self.decodescript_script_pub_key() | ||||
self.decoderawtransaction_asm_sighashtype() | self.decoderawtransaction_asm_sighashtype() | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
DecodeScriptTest().main() | DecodeScriptTest().main() |