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

Function test_recover

tests/test_misc.py:1556–1633  ·  view source on GitHub ↗

Test the recover option

(node_factory, bitcoind, old_hsmsecret)

Source from the content-addressed store, hash-verified

1554@unittest.skipIf(os.getenv('TEST_DB_PROVIDER', 'sqlite3') != 'sqlite3', "deletes database, which is assumed sqlite3")
1555@pytest.mark.parametrize("old_hsmsecret", [False, True])
1556def test_recover(node_factory, bitcoind, old_hsmsecret):
1557 """Test the recover option
1558 """
1559 if old_hsmsecret:
1560 recoverarg = "cl10leetsllhdmn9m42vcsamx24zrxgs3qrl7ahwvhw4fnzrhve25gvezzyqqjdsjnzedu43ns"
1561 hsmsecret = bytes.fromhex("ffeeddccbbaa99887766554433221100ffeeddccbbaa99887766554433221100")
1562 bad_recoverarg = "CL10LEETSLLHDMN9M42VCSAMX24ZRXGS3QQAT3LTDVAKMT73"
1563 else:
1564 recoverarg = "hockey enroll sure trip track rescue original plate abandon abandon abandon account"
1565 hsmsecret = bytes.fromhex("0000000000000000000000000000000000000000000000000000000000000000") + recoverarg.encode('utf-8')
1566 bad_recoverarg = "hockey enroll sure trip track rescue original plate abandon abandon abandon abandon"
1567
1568 # Start the node with --recovery with valid secret
1569 l1 = node_factory.get_node(start=False,
1570 options={"recover": recoverarg}, old_hsmsecret=old_hsmsecret)
1571
1572 os.unlink(os.path.join(l1.daemon.lightning_dir, TEST_NETWORK, "hsm_secret"))
1573 l1.daemon.start()
1574
1575 cmd_line = ["tools/lightning-hsmtool", "getsecret", os.path.join(l1.daemon.lightning_dir, TEST_NETWORK, "hsm_secret")]
1576 out = subprocess.check_output(cmd_line + ["leet"]).decode('utf-8')
1577 assert out == recoverarg + "\n"
1578
1579 # Check bad ids (we ignore id for modern hsm_secret)
1580 if old_hsmsecret:
1581 out = subprocess.run(cmd_line + ["lee"], stderr=subprocess.PIPE, timeout=TIMEOUT)
1582 assert 'Invalid id: must be 4 characters' in out.stderr.decode('utf-8')
1583 assert out.returncode == 2
1584
1585 out = subprocess.run(cmd_line + ["Leet"], stderr=subprocess.PIPE, timeout=TIMEOUT)
1586 assert 'Invalid id: must be lower-case' in out.stderr.decode('utf-8')
1587 assert out.returncode == 2
1588
1589 out = subprocess.run(cmd_line + ["💔"], stderr=subprocess.PIPE, timeout=TIMEOUT)
1590 assert 'Invalid id: must be ASCII' in out.stderr.decode('utf-8')
1591 assert out.returncode == 2
1592
1593 for bad_bech32 in ['b', 'o', 'i', '1']:
1594 out = subprocess.run(cmd_line + [bad_bech32 + "eet"], stderr=subprocess.PIPE, timeout=TIMEOUT)
1595 assert 'Invalid id: must be valid bech32 string' in out.stderr.decode('utf-8')
1596 assert out.returncode == 2
1597
1598 basedir = l1.daemon.opts.get("lightning-dir")
1599 with open(os.path.join(basedir, TEST_NETWORK, 'hsm_secret'), 'rb') as f:
1600 buff = f.read()
1601
1602 # Check the node secret
1603 assert buff == hsmsecret
1604 l1.stop()
1605
1606 os.unlink(os.path.join(l1.daemon.lightning_dir, TEST_NETWORK, "lightningd.sqlite3"))
1607
1608 # Node should throw error to recover flag if HSM already exists.
1609 l1.daemon.opts['recover'] = recoverarg
1610 l1.daemon.start(wait_for_initialized=False, stderr_redir=True)
1611
1612 # Will exit with failure code.
1613 assert l1.daemon.wait() == 1

Callers

nothing calls this directly

Calls 12

joinMethod · 0.80
is_in_stderrMethod · 0.80
updateMethod · 0.80
encodeMethod · 0.45
get_nodeMethod · 0.45
startMethod · 0.45
decodeMethod · 0.45
runMethod · 0.45
getMethod · 0.45
readMethod · 0.45
stopMethod · 0.45
waitMethod · 0.45

Tested by

no test coverage detected