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

Function test_hsmtool_checkhsm_variants

tests/test_wallet.py:1508–1539  ·  view source on GitHub ↗

Test checkhsm with various configurations

(node_factory, test_case)

Source from the content-addressed store, hash-verified

1506 }, id="wrong_mnemonic_should_fail")
1507])
1508def test_hsmtool_checkhsm_variants(node_factory, test_case):
1509 """Test checkhsm with various configurations"""
1510 l1 = node_factory.get_node(start=False)
1511 hsm_path = os.path.join(l1.daemon.lightning_dir, TEST_NETWORK, "hsm_secret")
1512 os.remove(hsm_path)
1513
1514 # Create hsm_secret with known mnemonic and passphrase
1515 hsmtool = HsmTool(node_factory.directory, "generatehsm", hsm_path)
1516 master_fd, slave_fd = os.openpty()
1517 hsmtool.start(stdin=slave_fd)
1518 hsmtool.wait_for_log(r"Introduce your BIP39 word list separated by space")
1519 write_all(master_fd, f"{test_case['mnemonic']}\n".encode("utf-8"))
1520 hsmtool.wait_for_log(r"Enter your passphrase:")
1521 write_all(master_fd, f"{test_case['passphrase']}\n".encode("utf-8"))
1522 assert hsmtool.proc.wait(WAIT_TIMEOUT) == 0
1523
1524 # Test checkhsm with credentials
1525 hsmtool = HsmTool(node_factory.directory, "checkhsm", hsm_path)
1526 master_fd, slave_fd = os.openpty()
1527 hsmtool.start(stdin=slave_fd)
1528
1529 # If the original had a passphrase, we need to unlock the file first
1530 if test_case['passphrase']:
1531 hsmtool.wait_for_log(r"Enter hsm_secret password:") # Decrypt file
1532 write_all(master_fd, f"{test_case['passphrase']}\n".encode("utf-8"))
1533
1534 hsmtool.wait_for_log(r"Enter your mnemonic passphrase:") # Backup verification
1535 write_all(master_fd, f"{test_case['check_passphrase']}\n".encode("utf-8"))
1536 hsmtool.wait_for_log(r"Introduce your BIP39 word list separated by space")
1537 write_all(master_fd, f"{test_case['check_mnemonic']}\n".encode("utf-8"))
1538 assert hsmtool.proc.wait(WAIT_TIMEOUT) == test_case['expected_exit']
1539 hsmtool.is_in_log(test_case['expected_log'])
1540
1541
1542def test_hsmtool_checkhsm_legacy_encrypted_with_mnemonic_no_passphrase(node_factory):

Callers

nothing calls this directly

Calls 10

HsmToolClass · 0.85
joinMethod · 0.80
wait_for_logMethod · 0.80
is_in_logMethod · 0.80
write_allFunction · 0.70
get_nodeMethod · 0.45
removeMethod · 0.45
startMethod · 0.45
encodeMethod · 0.45
waitMethod · 0.45

Tested by

no test coverage detected