@@ -27,6 +27,7 @@ def successful_signing_test(self):
27
27
28
28
1) The transaction has a complete set of signatures
29
29
2) No script verification error occurred"""
30
+ self .log .info ("Test valid raw transaction with one input" )
30
31
privKeys = ['cUeKHd5orzT3mz8P9pxyREHfsWtVfgsfDjiZZBcjUBAaGk1BTj7N' , 'cVKpPfVKSJxKqVpE9awvXNWuLHCa5j5tiE7K6zbUSptFpTEtiFrA' ]
31
32
32
33
inputs = [
@@ -49,7 +50,7 @@ def successful_signing_test(self):
49
50
assert 'errors' not in rawTxSigned
50
51
51
52
def test_with_lock_outputs (self ):
52
- """ Test correct error reporting when trying to sign a locked output"""
53
+ self . log . info ( " Test correct error reporting when trying to sign a locked output")
53
54
self .nodes [0 ].encryptwallet ("password" )
54
55
55
56
rawTx = '020000000156b958f78e3f24e0b2f4e4db1255426b0902027cb37e3ddadb52e37c3557dddb0000000000ffffffff01c0a6b929010000001600149a2ee8c77140a053f36018ac8124a6ececc1668a00000000'
@@ -65,6 +66,7 @@ def script_verification_error_test(self):
65
66
4) Two script verification errors occurred
66
67
5) Script verification errors have certain properties ("txid", "vout", "scriptSig", "sequence", "error")
67
68
6) The verification errors refer to the invalid (vin 1) and missing input (vin 2)"""
69
+ self .log .info ("Test script verification errors" )
68
70
privKeys = ['cUeKHd5orzT3mz8P9pxyREHfsWtVfgsfDjiZZBcjUBAaGk1BTj7N' ]
69
71
70
72
inputs = [
@@ -147,7 +149,7 @@ def script_verification_error_test(self):
147
149
assert not rawTxSigned ['errors' ][0 ]['witness' ]
148
150
149
151
def witness_script_test (self ):
150
- # Now test signing transaction to P2SH-P2WSH addresses without wallet
152
+ self . log . info ( "Test signing transaction to P2SH-P2WSH addresses without wallet" )
151
153
# Create a new P2SH-P2WSH 1-of-1 multisig address:
152
154
embedded_address = self .nodes [1 ].getaddressinfo (self .nodes [1 ].getnewaddress ())
153
155
embedded_privkey = self .nodes [1 ].dumpprivkey (embedded_address ["address" ])
@@ -169,29 +171,18 @@ def witness_script_test(self):
169
171
assert 'complete' in spending_tx_signed
170
172
assert_equal (spending_tx_signed ['complete' ], True )
171
173
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' ])
174
+ # Now test with P2PKH and P2PK scripts as the witnessScript
175
+ for tx_type in ['P2PKH' , 'P2PK' ]: # these tests are order-independent
176
+ self .verify_txn_with_witness_script (tx_type )
190
177
191
- self .log .info ('Try with a P2PK script as the witnessScript' )
178
+ def verify_txn_with_witness_script (self , tx_type ):
179
+ self .log .info ("Test with a {} script as the witnessScript" .format (tx_type ))
192
180
embedded_addr_info = self .nodes [1 ].getaddressinfo (self .nodes [1 ].getnewaddress ('' , 'legacy' ))
193
181
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 ()
182
+ witness_script = {
183
+ 'P2PKH' : embedded_addr_info ['scriptPubKey' ],
184
+ 'P2PK' : CScript ([hex_str_to_bytes (embedded_addr_info ['pubkey' ]), OP_CHECKSIG ]).hex ()
185
+ }.get (tx_type , "Invalid tx_type" )
195
186
redeem_script = CScript ([OP_0 , sha256 (check_script (witness_script ))]).hex ()
196
187
addr = script_to_p2sh (redeem_script )
197
188
script_pub_key = self .nodes [1 ].validateaddress (addr )['scriptPubKey' ]
0 commit comments