message: tests: Test getaddressinfo parent_desc
diff: @@ -151,5 +151,62 @@ class WalletDescriptorTest(BitcoinTestFramework):
  nopriv_rpc = self.nodes[0].get_wallet_rpc('desc_no_priv')
  assert_raises_rpc_error(-4, 'This wallet has no available keys', nopriv_rpc.getnewaddress)
  + self.log.info("Test descriptor exports")
  + self.nodes[0].createwallet(wallet_name='desc_export', descriptors=True)
  + exp_rpc = self.nodes[0].get_wallet_rpc('desc_export')
  + self.nodes[0].createwallet(wallet_name='desc_import', disable_private_keys=True, descriptors=True)
  + imp_rpc = self.nodes[0].get_wallet_rpc('desc_import')
  +
  + addr_types = [('legacy', False, 'pkh(', '44\'/1\'/0\'', -13),
  + ('p2sh-segwit', False, 'sh(wpkh(', '49\'/1\'/0\'', -14),
  + ('bech32', False, 'wpkh(', '84\'/1\'/0\'', -13),
  + ('legacy', True, 'pkh(', '44\'/1\'/0\'', -13),
  + ('p2sh-segwit', True, 'sh(wpkh(', '49\'/1\'/0\'', -14),
  + ('bech32', True, 'wpkh(', '84\'/1\'/0\'', -13)]
  +
  + for addr_type, internal, desc_prefix, deriv_path, int_idx in addr_types:
  + int_str = 'internal' if internal else 'external'
  +
  + self.log.info("Testing descriptor address type for {} {}".format(addr_type, int_str))
  + if internal:
  + addr = exp_rpc.getrawchangeaddress(address_type=addr_type)
  + else:
  + addr = exp_rpc.getnewaddress(address_type=addr_type)
  + desc = exp_rpc.getaddressinfo(addr)['parent_desc']
  + assert_equal(desc_prefix, desc[0:len(desc_prefix)])
  + idx = desc.index('/') + 1
  + assert_equal(deriv_path, desc[idx:idx + 9])
  + if internal:
  + assert_equal('1', desc[int_idx])
  + else:
  + assert_equal('0', desc[int_idx])
  +
  + self.log.info("Testing the same descriptor is returned for address type {} {}".format(addr_type, int_str))
  + for i in range(0, 10):
  + if internal:
  + addr = exp_rpc.getrawchangeaddress(address_type=addr_type)
  + else:
  + addr = exp_rpc.getnewaddress(address_type=addr_type)
  + test_desc = exp_rpc.getaddressinfo(addr)['parent_desc']
  + assert_equal(desc, test_desc)
  +
  + self.log.info("Testing import of exported {} descriptor".format(addr_type))
  + imp_rpc.importdescriptors([{
  + 'desc': desc,
  + 'active': True,
  + 'next_index': 11,
  + 'timestamp': 'now',
  + 'internal': internal
  + }])
  +
  + for i in range(0, 10):
  + if internal:
  + exp_addr = exp_rpc.getrawchangeaddress(address_type=addr_type)
  + imp_addr = imp_rpc.getrawchangeaddress(address_type=addr_type)
  + else:
  + exp_addr = exp_rpc.getnewaddress(address_type=addr_type)
  + imp_addr = imp_rpc.getnewaddress(address_type=addr_type)
  + assert_equal(exp_addr, imp_addr)
  +
  if __name__ == '__main__':
  WalletDescriptorTest().main ()
  