|
17 | 17 | send_to_witness,
|
18 | 18 | witness_script,
|
19 | 19 | )
|
| 20 | +from test_framework.descriptors import descsum_create |
20 | 21 | from test_framework.messages import (
|
21 | 22 | COIN,
|
22 | 23 | COutPoint,
|
|
49 | 50 | assert_raises_rpc_error,
|
50 | 51 | try_rpc,
|
51 | 52 | )
|
| 53 | +from test_framework.wallet_util import ( |
| 54 | + get_generate_key, |
| 55 | +) |
52 | 56 |
|
53 | 57 | NODE_0 = 0
|
54 | 58 | NODE_2 = 2
|
@@ -142,13 +146,39 @@ def run_test(self):
|
142 | 146 | p2sh_ids = [] # p2sh_ids[NODE][TYPE] is an array of txids that spend to P2WPKH (TYPE=0) or P2WSH (TYPE=1) scripts to an address for NODE embedded in p2sh
|
143 | 147 | wit_ids = [] # wit_ids[NODE][TYPE] is an array of txids that spend to P2WPKH (TYPE=0) or P2WSH (TYPE=1) scripts to an address for NODE via bare witness
|
144 | 148 | for i in range(3):
|
145 |
| - newaddress = self.nodes[i].getnewaddress() |
146 |
| - self.pubkey.append(self.nodes[i].getaddressinfo(newaddress)["pubkey"]) |
| 149 | + key = get_generate_key() |
| 150 | + self.pubkey.append(key.pubkey) |
| 151 | + |
147 | 152 | multiscript = CScript([OP_1, bytes.fromhex(self.pubkey[-1]), OP_1, OP_CHECKMULTISIG])
|
148 |
| - p2sh_ms_addr = self.nodes[i].addmultisigaddress(1, [self.pubkey[-1]], '', 'p2sh-segwit')['address'] |
149 |
| - bip173_ms_addr = self.nodes[i].addmultisigaddress(1, [self.pubkey[-1]], '', 'bech32')['address'] |
| 153 | + p2sh_ms_addr = self.nodes[i].createmultisig(1, [self.pubkey[-1]], 'p2sh-segwit')['address'] |
| 154 | + bip173_ms_addr = self.nodes[i].createmultisig(1, [self.pubkey[-1]], 'bech32')['address'] |
150 | 155 | assert_equal(p2sh_ms_addr, script_to_p2sh_p2wsh(multiscript))
|
151 | 156 | assert_equal(bip173_ms_addr, script_to_p2wsh(multiscript))
|
| 157 | + |
| 158 | + p2sh_ms_desc = descsum_create(f"sh(wsh(multi(1,{key.privkey})))") |
| 159 | + bip173_ms_desc = descsum_create(f"wsh(multi(1,{key.privkey}))") |
| 160 | + assert_equal(self.nodes[i].deriveaddresses(p2sh_ms_desc)[0], p2sh_ms_addr) |
| 161 | + assert_equal(self.nodes[i].deriveaddresses(bip173_ms_desc)[0], bip173_ms_addr) |
| 162 | + |
| 163 | + sh_wpkh_desc = descsum_create(f"sh(wpkh({key.privkey}))") |
| 164 | + wpkh_desc = descsum_create(f"wpkh({key.privkey})") |
| 165 | + assert_equal(self.nodes[i].deriveaddresses(sh_wpkh_desc)[0], key.p2sh_p2wpkh_addr) |
| 166 | + assert_equal(self.nodes[i].deriveaddresses(wpkh_desc)[0], key.p2wpkh_addr) |
| 167 | + |
| 168 | + if self.options.descriptors: |
| 169 | + res = self.nodes[i].importdescriptors([ |
| 170 | + {"desc": p2sh_ms_desc, "timestamp": "now"}, |
| 171 | + {"desc": bip173_ms_desc, "timestamp": "now"}, |
| 172 | + {"desc": sh_wpkh_desc, "timestamp": "now"}, |
| 173 | + {"desc": wpkh_desc, "timestamp": "now"}, |
| 174 | + ]) |
| 175 | + else: |
| 176 | + # The nature of the legacy wallet is that this import results in also adding all of the necessary scripts |
| 177 | + res = self.nodes[i].importmulti([ |
| 178 | + {"desc": p2sh_ms_desc, "timestamp": "now"}, |
| 179 | + ]) |
| 180 | + assert all([r["success"] for r in res]) |
| 181 | + |
152 | 182 | p2sh_ids.append([])
|
153 | 183 | wit_ids.append([])
|
154 | 184 | for _ in range(2):
|
|
0 commit comments