Skip to content

Commit de6b389

Browse files
committed
tests: Test getaddressinfo parent_desc
1 parent e4ac869 commit de6b389

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

test/functional/wallet_descriptor.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,5 +140,62 @@ def run_test(self):
140140
nopriv_rpc = self.nodes[0].get_wallet_rpc('desc_no_priv')
141141
assert_raises_rpc_error(-4, 'This wallet has no available keys', nopriv_rpc.getnewaddress)
142142

143+
self.log.info("Test descriptor exports")
144+
self.nodes[0].createwallet(wallet_name='desc_export', descriptors=True)
145+
exp_rpc = self.nodes[0].get_wallet_rpc('desc_export')
146+
self.nodes[0].createwallet(wallet_name='desc_import', disable_private_keys=True, descriptors=True)
147+
imp_rpc = self.nodes[0].get_wallet_rpc('desc_import')
148+
149+
addr_types = [('legacy', False, 'pkh(', '44\'/1\'/0\'', -13),
150+
('p2sh-segwit', False, 'sh(wpkh(', '49\'/1\'/0\'', -14),
151+
('bech32', False, 'wpkh(', '84\'/1\'/0\'', -13),
152+
('legacy', True, 'pkh(', '44\'/1\'/0\'', -13),
153+
('p2sh-segwit', True, 'sh(wpkh(', '49\'/1\'/0\'', -14),
154+
('bech32', True, 'wpkh(', '84\'/1\'/0\'', -13)]
155+
156+
for addr_type, internal, desc_prefix, deriv_path, int_idx in addr_types:
157+
int_str = 'internal' if internal else 'external'
158+
159+
self.log.info("Testing descriptor address type for {} {}".format(addr_type, int_str))
160+
if internal:
161+
addr = exp_rpc.getrawchangeaddress(address_type=addr_type)
162+
else:
163+
addr = exp_rpc.getnewaddress(address_type=addr_type)
164+
desc = exp_rpc.getaddressinfo(addr)['parent_desc']
165+
assert_equal(desc_prefix, desc[0:len(desc_prefix)])
166+
idx = desc.index('/') + 1
167+
assert_equal(deriv_path, desc[idx:idx + 9])
168+
if internal:
169+
assert_equal('1', desc[int_idx])
170+
else:
171+
assert_equal('0', desc[int_idx])
172+
173+
self.log.info("Testing the same descriptor is returned for address type {} {}".format(addr_type, int_str))
174+
for i in range(0, 10):
175+
if internal:
176+
addr = exp_rpc.getrawchangeaddress(address_type=addr_type)
177+
else:
178+
addr = exp_rpc.getnewaddress(address_type=addr_type)
179+
test_desc = exp_rpc.getaddressinfo(addr)['parent_desc']
180+
assert_equal(desc, test_desc)
181+
182+
self.log.info("Testing import of exported {} descriptor".format(addr_type))
183+
imp_rpc.importdescriptors([{
184+
'desc': desc,
185+
'active': True,
186+
'next_index': 11,
187+
'timestamp': 'now',
188+
'internal': internal
189+
}])
190+
191+
for i in range(0, 10):
192+
if internal:
193+
exp_addr = exp_rpc.getrawchangeaddress(address_type=addr_type)
194+
imp_addr = imp_rpc.getrawchangeaddress(address_type=addr_type)
195+
else:
196+
exp_addr = exp_rpc.getnewaddress(address_type=addr_type)
197+
imp_addr = imp_rpc.getnewaddress(address_type=addr_type)
198+
assert_equal(exp_addr, imp_addr)
199+
143200
if __name__ == '__main__':
144201
WalletDescriptorTest().main ()

0 commit comments

Comments
 (0)