@@ -169,29 +169,18 @@ def witness_script_test(self):
169
169
assert 'complete' in spending_tx_signed
170
170
assert_equal (spending_tx_signed ['complete' ], True )
171
171
172
- self .log .info ('Try with a P2PKH script as the witnessScript' )
173
- embedded_addr_info = self .nodes [1 ].getaddressinfo (self .nodes [1 ].getnewaddress ('' , 'legacy' ))
174
- embedded_privkey = self .nodes [1 ].dumpprivkey (embedded_addr_info ['address' ])
175
- witness_script = embedded_addr_info ['scriptPubKey' ]
176
- redeem_script = CScript ([OP_0 , sha256 (check_script (witness_script ))]).hex ()
177
- addr = script_to_p2sh (redeem_script )
178
- script_pub_key = self .nodes [1 ].validateaddress (addr )['scriptPubKey' ]
179
- # Fund that address
180
- txid = self .nodes [0 ].sendtoaddress (addr , 10 )
181
- vout = find_vout_for_address (self .nodes [0 ], txid , addr )
182
- self .nodes [0 ].generate (1 )
183
- # Now create and sign a transaction spending that output on node[0], which doesn't know the scripts or keys
184
- spending_tx = self .nodes [0 ].createrawtransaction ([{'txid' : txid , 'vout' : vout }], {self .nodes [1 ].getnewaddress (): Decimal ("9.999" )})
185
- spending_tx_signed = self .nodes [0 ].signrawtransactionwithkey (spending_tx , [embedded_privkey ], [{'txid' : txid , 'vout' : vout , 'scriptPubKey' : script_pub_key , 'redeemScript' : redeem_script , 'witnessScript' : witness_script , 'amount' : 10 }])
186
- # Check the signing completed successfully
187
- assert 'complete' in spending_tx_signed
188
- assert_equal (spending_tx_signed ['complete' ], True )
189
- self .nodes [0 ].sendrawtransaction (spending_tx_signed ['hex' ])
172
+ # Now test with P2PKH and P2PK scripts as the witnessScript
173
+ for tx_type in ['P2PKH' , 'P2PK' ]: # these tests are order-independent
174
+ self .verify_txn_with_witness_script (tx_type )
190
175
191
- self .log .info ('Try with a P2PK script as the witnessScript' )
176
+ def verify_txn_with_witness_script (self , tx_type ):
177
+ self .log .info ("Test with a {} script as the witnessScript" .format (tx_type ))
192
178
embedded_addr_info = self .nodes [1 ].getaddressinfo (self .nodes [1 ].getnewaddress ('' , 'legacy' ))
193
179
embedded_privkey = self .nodes [1 ].dumpprivkey (embedded_addr_info ['address' ])
194
- witness_script = CScript ([hex_str_to_bytes (embedded_addr_info ['pubkey' ]), OP_CHECKSIG ]).hex ()
180
+ witness_script = {
181
+ 'P2PKH' : embedded_addr_info ['scriptPubKey' ],
182
+ 'P2PK' : CScript ([hex_str_to_bytes (embedded_addr_info ['pubkey' ]), OP_CHECKSIG ]).hex ()
183
+ }.get (tx_type , "Invalid tx_type" )
195
184
redeem_script = CScript ([OP_0 , sha256 (check_script (witness_script ))]).hex ()
196
185
addr = script_to_p2sh (redeem_script )
197
186
script_pub_key = self .nodes [1 ].validateaddress (addr )['scriptPubKey' ]
0 commit comments