Skip to content

Commit 1d13c44

Browse files
committed
tests: Use descriptors for feature_segwit multisig setup
When setting up the multisig addresses in feature_segwit.py, use descriptors rather than addmultisigaddress.
1 parent 986003a commit 1d13c44

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

test/functional/feature_segwit.py

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
send_to_witness,
1818
witness_script,
1919
)
20+
from test_framework.descriptors import descsum_create
2021
from test_framework.messages import (
2122
COIN,
2223
COutPoint,
@@ -49,6 +50,9 @@
4950
assert_raises_rpc_error,
5051
try_rpc,
5152
)
53+
from test_framework.wallet_util import (
54+
get_generate_key,
55+
)
5256

5357
NODE_0 = 0
5458
NODE_2 = 2
@@ -142,13 +146,39 @@ def run_test(self):
142146
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
143147
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
144148
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+
147152
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']
150155
assert_equal(p2sh_ms_addr, script_to_p2sh_p2wsh(multiscript))
151156
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+
152182
p2sh_ids.append([])
153183
wit_ids.append([])
154184
for _ in range(2):

0 commit comments

Comments
 (0)