|
5 | 5 | """Test transaction signing using the signrawtransaction* RPCs."""
|
6 | 6 |
|
7 | 7 | from test_framework.test_framework import BitcoinTestFramework
|
8 |
| -from test_framework.util import assert_equal, assert_raises_rpc_error |
| 8 | +from test_framework.util import assert_equal, assert_raises_rpc_error, bytes_to_hex_str, hex_str_to_bytes |
| 9 | +from test_framework.messages import sha256 |
| 10 | +from test_framework.script import CScript, OP_0 |
9 | 11 |
|
| 12 | +from decimal import Decimal |
10 | 13 |
|
11 | 14 | class SignRawTransactionsTest(BitcoinTestFramework):
|
12 | 15 | def set_test_params(self):
|
13 | 16 | self.setup_clean_chain = True
|
14 |
| - self.num_nodes = 1 |
15 |
| - self.extra_args = [["-deprecatedrpc=signrawtransaction"]] |
| 17 | + self.num_nodes = 2 |
| 18 | + self.extra_args = [["-deprecatedrpc=signrawtransaction"], []] |
16 | 19 |
|
17 | 20 | def skip_test_if_missing_module(self):
|
18 | 21 | self.skip_if_no_wallet()
|
@@ -143,9 +146,33 @@ def script_verification_error_test(self):
|
143 | 146 | assert_equal(rawTxSigned['errors'][1]['witness'], ["304402203609e17b84f6a7d30c80bfa610b5b4542f32a8a0d5447a12fb1366d7f01cc44a0220573a954c4518331561406f90300e8f3358f51928d43c212a8caed02de67eebee01", "025476c2e83188368da1ff3e292e7acafcdb3566bb0ad253f62fc70f07aeee6357"])
|
144 | 147 | assert not rawTxSigned['errors'][0]['witness']
|
145 | 148 |
|
| 149 | + def witness_script_test(self): |
| 150 | + # Now test signing transaction to P2SH-P2WSH addresses without wallet |
| 151 | + # Create a new P2SH-P2WSH 1-of-1 multisig address: |
| 152 | + embedded_address = self.nodes[1].getaddressinfo(self.nodes[1].getnewaddress()) |
| 153 | + embedded_privkey = self.nodes[1].dumpprivkey(embedded_address["address"]) |
| 154 | + p2sh_p2wsh_address = self.nodes[1].addmultisigaddress(1, [embedded_address["pubkey"]], "", "p2sh-segwit") |
| 155 | + # send transaction to P2SH-P2WSH 1-of-1 multisig address |
| 156 | + self.nodes[0].generate(101) |
| 157 | + self.nodes[0].sendtoaddress(p2sh_p2wsh_address["address"], 49.999) |
| 158 | + self.nodes[0].generate(1) |
| 159 | + self.sync_all() |
| 160 | + # Find the UTXO for the transaction node[1] should have received, check witnessScript matches |
| 161 | + unspent_output = self.nodes[1].listunspent(0, 999999, [p2sh_p2wsh_address["address"]])[0] |
| 162 | + assert_equal(unspent_output["witnessScript"], p2sh_p2wsh_address["redeemScript"]) |
| 163 | + p2sh_redeemScript = CScript([OP_0, sha256(hex_str_to_bytes(p2sh_p2wsh_address["redeemScript"]))]) |
| 164 | + assert_equal(unspent_output["redeemScript"], bytes_to_hex_str(p2sh_redeemScript)) |
| 165 | + # Now create and sign a transaction spending that output on node[0], which doesn't know the scripts or keys |
| 166 | + spending_tx = self.nodes[0].createrawtransaction([unspent_output], {self.nodes[1].getnewaddress(): Decimal("49.998")}) |
| 167 | + spending_tx_signed = self.nodes[0].signrawtransactionwithkey(spending_tx, [embedded_privkey], [unspent_output]) |
| 168 | + # Check the signing completed successfully |
| 169 | + assert 'complete' in spending_tx_signed |
| 170 | + assert_equal(spending_tx_signed['complete'], True) |
| 171 | + |
146 | 172 | def run_test(self):
|
147 | 173 | self.successful_signing_test()
|
148 | 174 | self.script_verification_error_test()
|
| 175 | + self.witness_script_test() |
149 | 176 | self.test_with_lock_outputs()
|
150 | 177 |
|
151 | 178 |
|
|
0 commit comments