@@ -50,34 +50,47 @@ def decodescript_script_sig(self):
50
50
def decodescript_script_pub_key (self ):
51
51
public_key = '03b0da749730dc9b4b1f4a14d6902877a92541f5368778853d9c4a0cb7802dcfb2'
52
52
push_public_key = '21' + public_key
53
- public_key_hash = '11695b6cd891484c2d49ec5aa738ec2b2f897777 '
53
+ public_key_hash = '5dd1d3a048119c27b28293056724d9522f26d945 '
54
54
push_public_key_hash = '14' + public_key_hash
55
+ uncompressed_public_key = '04b0da749730dc9b4b1f4a14d6902877a92541f5368778853d9c4a0cb7802dcfb25e01fc8fde47c96c98a4f3a8123e33a38a50cf9025cc8c4494a518f991792bb7'
56
+ push_uncompressed_public_key = '41' + uncompressed_public_key
57
+ p2wsh_p2pk_script_hash = 'd8590cf8ea0674cf3d49fd7ca249b85ef7485dea62c138468bddeb20cd6519f7'
55
58
56
59
# below are test cases for all of the standard transaction types
57
60
58
61
# 1) P2PK scriptPubKey
59
62
# <pubkey> OP_CHECKSIG
60
63
rpc_result = self .nodes [0 ].decodescript (push_public_key + 'ac' )
61
64
assert_equal (public_key + ' OP_CHECKSIG' , rpc_result ['asm' ])
65
+ # P2PK is translated to P2WPKH
66
+ assert_equal ('0 ' + public_key_hash , rpc_result ['segwit' ]['asm' ])
62
67
63
68
# 2) P2PKH scriptPubKey
64
69
# OP_DUP OP_HASH160 <PubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
65
70
rpc_result = self .nodes [0 ].decodescript ('76a9' + push_public_key_hash + '88ac' )
66
71
assert_equal ('OP_DUP OP_HASH160 ' + public_key_hash + ' OP_EQUALVERIFY OP_CHECKSIG' , rpc_result ['asm' ])
72
+ # P2PKH is translated to P2WPKH
73
+ assert_equal ('0 ' + public_key_hash , rpc_result ['segwit' ]['asm' ])
67
74
68
75
# 3) multisig scriptPubKey
69
76
# <m> <A pubkey> <B pubkey> <C pubkey> <n> OP_CHECKMULTISIG
70
77
# just imagine that the pub keys used below are different.
71
78
# for our purposes here it does not matter that they are the same even though it is unrealistic.
72
- rpc_result = self .nodes [0 ].decodescript ('52' + push_public_key + push_public_key + push_public_key + '53ae' )
79
+ multisig_script = '52' + push_public_key + push_public_key + push_public_key + '53ae'
80
+ rpc_result = self .nodes [0 ].decodescript (multisig_script )
73
81
assert_equal ('2 ' + public_key + ' ' + public_key + ' ' + public_key + ' 3 OP_CHECKMULTISIG' , rpc_result ['asm' ])
82
+ # multisig in P2WSH
83
+ multisig_script_hash = bytes_to_hex_str (sha256 (hex_str_to_bytes (multisig_script )))
84
+ assert_equal ('0 ' + multisig_script_hash , rpc_result ['segwit' ]['asm' ])
74
85
75
86
# 4) P2SH scriptPubKey
76
87
# OP_HASH160 <Hash160(redeemScript)> OP_EQUAL.
77
88
# push_public_key_hash here should actually be the hash of a redeem script.
78
89
# but this works the same for purposes of this test.
79
90
rpc_result = self .nodes [0 ].decodescript ('a9' + push_public_key_hash + '87' )
80
91
assert_equal ('OP_HASH160 ' + public_key_hash + ' OP_EQUAL' , rpc_result ['asm' ])
92
+ # P2SH does not work in segwit secripts. decodescript should not return a result for it.
93
+ assert 'segwit' not in rpc_result
81
94
82
95
# 5) null data scriptPubKey
83
96
# use a signature look-alike here to make sure that we do not decode random data as a signature.
@@ -101,8 +114,49 @@ def decodescript_script_pub_key(self):
101
114
# <sender-pubkey> OP_CHECKSIG
102
115
#
103
116
# lock until block 500,000
104
- rpc_result = self .nodes [0 ].decodescript ('63' + push_public_key + 'ad670320a107b17568' + push_public_key + 'ac' )
117
+ cltv_script = '63' + push_public_key + 'ad670320a107b17568' + push_public_key + 'ac'
118
+ rpc_result = self .nodes [0 ].decodescript (cltv_script )
105
119
assert_equal ('OP_IF ' + public_key + ' OP_CHECKSIGVERIFY OP_ELSE 500000 OP_CHECKLOCKTIMEVERIFY OP_DROP OP_ENDIF ' + public_key + ' OP_CHECKSIG' , rpc_result ['asm' ])
120
+ # CLTV script in P2WSH
121
+ cltv_script_hash = bytes_to_hex_str (sha256 (hex_str_to_bytes (cltv_script )))
122
+ assert_equal ('0 ' + cltv_script_hash , rpc_result ['segwit' ]['asm' ])
123
+
124
+ # 7) P2PK scriptPubKey
125
+ # <pubkey> OP_CHECKSIG
126
+ rpc_result = self .nodes [0 ].decodescript (push_uncompressed_public_key + 'ac' )
127
+ assert_equal (uncompressed_public_key + ' OP_CHECKSIG' , rpc_result ['asm' ])
128
+ # uncompressed pubkeys are invalid for checksigs in segwit scripts.
129
+ # decodescript should not return a P2WPKH equivalent.
130
+ assert 'segwit' not in rpc_result
131
+
132
+ # 8) multisig scriptPubKey with an uncompressed pubkey
133
+ # <m> <A pubkey> <B pubkey> <n> OP_CHECKMULTISIG
134
+ # just imagine that the pub keys used below are different.
135
+ # the purpose of this test is to check that a segwit script is not returned for bare multisig scripts
136
+ # with an uncompressed pubkey in them.
137
+ rpc_result = self .nodes [0 ].decodescript ('52' + push_public_key + push_uncompressed_public_key + '52ae' )
138
+ assert_equal ('2 ' + public_key + ' ' + uncompressed_public_key + ' 2 OP_CHECKMULTISIG' , rpc_result ['asm' ])
139
+ # uncompressed pubkeys are invalid for checksigs in segwit scripts.
140
+ # decodescript should not return a P2WPKH equivalent.
141
+ assert 'segwit' not in rpc_result
142
+
143
+ # 9) P2WPKH scriptpubkey
144
+ # 0 <PubKeyHash>
145
+ rpc_result = self .nodes [0 ].decodescript ('00' + push_public_key_hash )
146
+ assert_equal ('0 ' + public_key_hash , rpc_result ['asm' ])
147
+ # segwit scripts do not work nested into each other.
148
+ # a nested segwit script should not be returned in the results.
149
+ assert 'segwit' not in rpc_result
150
+
151
+ # 10) P2WSH scriptpubkey
152
+ # 0 <ScriptHash>
153
+ # even though this hash is of a P2PK script which is better used as bare P2WPKH, it should not matter
154
+ # for the purpose of this test.
155
+ rpc_result = self .nodes [0 ].decodescript ('0020' + p2wsh_p2pk_script_hash )
156
+ assert_equal ('0 ' + p2wsh_p2pk_script_hash , rpc_result ['asm' ])
157
+ # segwit scripts do not work nested into each other.
158
+ # a nested segwit script should not be returned in the results.
159
+ assert 'segwit' not in rpc_result
106
160
107
161
def decoderawtransaction_asm_sighashtype (self ):
108
162
"""Test decoding scripts via RPC command "decoderawtransaction".
0 commit comments