MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_hsmtool_dump_descriptors

Function test_hsmtool_dump_descriptors

tests/test_wallet.py:1362–1397  ·  view source on GitHub ↗
(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

1360
1361@unittest.skipIf(TEST_NETWORK == 'liquid-regtest', '')
1362def test_hsmtool_dump_descriptors(node_factory, bitcoind):
1363 l1 = node_factory.get_node()
1364 l1.fundwallet(10**6)
1365 # Get a tpub descriptor of lightningd's wallet
1366 hsm_path = os.path.join(l1.daemon.lightning_dir, TEST_NETWORK, "hsm_secret")
1367 cmd_line = ["tools/lightning-hsmtool", "dumponchaindescriptors", hsm_path, "testnet"]
1368 descriptors = subprocess.check_output(cmd_line).decode("utf8").split("\n")
1369
1370 # Deprecated or empty line
1371 descriptors = [desc for desc in descriptors if not (desc.startswith("sh(wpkh(") or desc == '')]
1372
1373 withdraw_addr = None
1374 index_offset = 2 # index starts handing out addrs at 2
1375
1376 # Generate twenty addresses for all known descriptors
1377 cln_addrs = [l1.rpc.newaddr('all') for _ in range(20)]
1378 for descriptor in descriptors:
1379 for i, cln_addr in enumerate(cln_addrs):
1380 computed_addr = bitcoind.rpc.deriveaddresses(descriptor, [i + index_offset, i + index_offset])[0]
1381 if descriptor.startswith("wpkh"):
1382 assert cln_addr["bech32"] == computed_addr
1383 withdraw_addr = cln_addr["bech32"]
1384 elif descriptor.startswith("tr"):
1385 assert cln_addr["p2tr"] == computed_addr
1386 withdraw_addr = cln_addr["p2tr"]
1387 else:
1388 raise Exception('Unexpected descriptor!')
1389
1390 # For last address per type:
1391 # Funds sent to lightningd can be retrieved by bitcoind
1392 txid = l1.rpc.withdraw(withdraw_addr, 10**3)["txid"]
1393 bitcoind.generate_block(1, txid, bitcoind.rpc.getnewaddress())
1394 l1.daemon.wait_for_log('Owning output .* txid {} CONFIRMED'.format(txid))
1395 actual_index = len(cln_addrs) - 1 + index_offset
1396 res = bitcoind.rpc.scantxoutset("start", [{"desc": descriptor, "range": [actual_index, actual_index]}])
1397 assert res["total_amount"] == Decimal('0.00001000')
1398
1399
1400@pytest.mark.parametrize("mnemonic,passphrase,expected_format", [

Callers

nothing calls this directly

Calls 9

fundwalletMethod · 0.80
joinMethod · 0.80
generate_blockMethod · 0.80
wait_for_logMethod · 0.80
get_nodeMethod · 0.45
decodeMethod · 0.45
newaddrMethod · 0.45
withdrawMethod · 0.45
getnewaddressMethod · 0.45

Tested by

no test coverage detected