Skip to content

Commit

Permalink
pytest: test onchain wallet descriptor import on bitcoind
Browse files Browse the repository at this point in the history
Signed-off-by: Antoine Poinsot <[email protected]>
  • Loading branch information
darosior committed Nov 1, 2020
1 parent 8e9ea4f commit fd74279
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/test_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,37 @@ def test_hsmtool_secret_decryption(node_factory):
assert node_id == l1.rpc.getinfo()["id"]


def test_hsmtool_dump_descriptors(node_factory, bitcoind):
l1 = node_factory.get_node()
l1.fundwallet(10**6)

# Get a tpriv descriptor of lightningd's wallet
hsm_path = os.path.join(l1.daemon.lightning_dir, TEST_NETWORK, "hsm_secret")
cmd_line = ["tools/hsmtool", "dumponchaindescriptors", hsm_path, "",
"private", "testnet"]
out = subprocess.check_output(cmd_line).decode("utf8").split("\n")
descriptor = [l for l in out if l.startswith("wpkh(tprv")][0]

# Import the descriptor to bitcoind
# FIXME: if we update the testsuite to use the upcoming 0.21 we could use
# importdescriptors instead.
bitcoind.rpc.importmulti([{
"desc": descriptor,
# No need to rescan, we'll transact afterward
"timestamp": "now",
# The default
"range": [0, 99]
}])

# Funds sent to lightningd can be retrieved by bitcoind
addr = l1.rpc.newaddr()["bech32"]
txid = l1.rpc.withdraw(addr, 10**3)["txid"]
bitcoind.generate_block(1, txid)
utxo = bitcoind.rpc.listunspent(1, 1, [addr])[0]
# And it can spend it, since we imported the master private key
assert utxo["spendable"]


# this test does a 'listtransactions' on a yet unconfirmed channel
def test_fundchannel_listtransaction(node_factory, bitcoind):
l1, l2 = node_factory.get_nodes(2)
Expand Down

0 comments on commit fd74279

Please sign in to comment.