Skip to content

Commit e28e535

Browse files
author
MarcoFalke
committed
Merge #18545: test: refactor rpc_signrawtransaction and add logging
9cdddae test: add rpc_signrawtransaction logging (Jon Atack) 4d6cde3 test: refactor rpc_signrawtransaction witness script tests (Jon Atack) Pull request description: As a follow-up to #18484, the new tests are good but bury the one non-duplicate line in each test that sets the witness script, and there is no logging in the testfile. This PR makes it easy to see what is unique to each of the new tests and adds logging. ACKs for top commit: theStack: ACK bitcoin/bitcoin@9cdddae 🥚 🐰 Tree-SHA512: 7b1ca303326658afb90b7635abc9fe8bb65f0be004124d4dcf38702bb6f38bc06ce33c0642be4ad5d511453d003cdefeea691e66e3b963a4feb66f6237a3c241
2 parents d9fd7b5 + 9cdddae commit e28e535

File tree

1 file changed

+13
-22
lines changed

1 file changed

+13
-22
lines changed

test/functional/rpc_signrawtransaction.py

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def successful_signing_test(self):
2727
2828
1) The transaction has a complete set of signatures
2929
2) No script verification error occurred"""
30+
self.log.info("Test valid raw transaction with one input")
3031
privKeys = ['cUeKHd5orzT3mz8P9pxyREHfsWtVfgsfDjiZZBcjUBAaGk1BTj7N', 'cVKpPfVKSJxKqVpE9awvXNWuLHCa5j5tiE7K6zbUSptFpTEtiFrA']
3132

3233
inputs = [
@@ -49,7 +50,7 @@ def successful_signing_test(self):
4950
assert 'errors' not in rawTxSigned
5051

5152
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")
5354
self.nodes[0].encryptwallet("password")
5455

5556
rawTx = '020000000156b958f78e3f24e0b2f4e4db1255426b0902027cb37e3ddadb52e37c3557dddb0000000000ffffffff01c0a6b929010000001600149a2ee8c77140a053f36018ac8124a6ececc1668a00000000'
@@ -65,6 +66,7 @@ def script_verification_error_test(self):
6566
4) Two script verification errors occurred
6667
5) Script verification errors have certain properties ("txid", "vout", "scriptSig", "sequence", "error")
6768
6) The verification errors refer to the invalid (vin 1) and missing input (vin 2)"""
69+
self.log.info("Test script verification errors")
6870
privKeys = ['cUeKHd5orzT3mz8P9pxyREHfsWtVfgsfDjiZZBcjUBAaGk1BTj7N']
6971

7072
inputs = [
@@ -147,7 +149,7 @@ def script_verification_error_test(self):
147149
assert not rawTxSigned['errors'][0]['witness']
148150

149151
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")
151153
# Create a new P2SH-P2WSH 1-of-1 multisig address:
152154
embedded_address = self.nodes[1].getaddressinfo(self.nodes[1].getnewaddress())
153155
embedded_privkey = self.nodes[1].dumpprivkey(embedded_address["address"])
@@ -169,29 +171,18 @@ def witness_script_test(self):
169171
assert 'complete' in spending_tx_signed
170172
assert_equal(spending_tx_signed['complete'], True)
171173

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)
190177

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))
192180
embedded_addr_info = self.nodes[1].getaddressinfo(self.nodes[1].getnewaddress('', 'legacy'))
193181
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")
195186
redeem_script = CScript([OP_0, sha256(check_script(witness_script))]).hex()
196187
addr = script_to_p2sh(redeem_script)
197188
script_pub_key = self.nodes[1].validateaddress(addr)['scriptPubKey']

0 commit comments

Comments
 (0)