From aa2586a45a69527d9af3a3996a08019d559f86d6 Mon Sep 17 00:00:00 2001 From: Antoine Poinsot Date: Sun, 3 Jan 2021 00:51:48 +0100 Subject: [PATCH] pytest: reproduce issue #4302 Signed-off-by: Antoine Poinsot --- tests/test_wallet.py | 33 +++++++++++++++++++++++++++++++++ tools/hsmtool.c | 2 ++ 2 files changed, 35 insertions(+) diff --git a/tests/test_wallet.py b/tests/test_wallet.py index 36ce7b631..562a3f984 100644 --- a/tests/test_wallet.py +++ b/tests/test_wallet.py @@ -1097,6 +1097,39 @@ def test_hsmtool_dump_descriptors(node_factory, bitcoind): assert len(bitcoind.rpc.listunspent(1, 1, [addr])) == 1 +@pytest.mark.xfail(strict=True) +@unittest.skipIf(VALGRIND, "It does not play well with prompt and key derivation.") +def test_hsmtool_generatehsm(node_factory): + l1 = node_factory.get_node() + l1.stop() + hsm_path = os.path.join(l1.daemon.lightning_dir, TEST_NETWORK, + "hsm_secret") + master_fd, slave_fd = os.openpty() + + hsmtool = HsmTool("generatehsm", hsm_path) + # You cannot re-generate an already existing hsm_secret + hsmtool.start(stdin=slave_fd, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + assert hsmtool.proc.wait(5) == 2 + os.remove(hsm_path) + + # We can generate a valid hsm_secret from a wordlist and a "passphrase" + hsmtool.start(stdin=slave_fd, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + hsmtool.wait_for_log(r"Select your language:") + os.write(master_fd, "0\n".encode("utf-8")) + hsmtool.wait_for_log(r"Introduce your BIP39 word list") + os.write(master_fd, "ritual idle hat sunny universe pluck key alpha wing " + "cake have wedding\n".encode("utf-8")) + hsmtool.wait_for_log(r"Enter your passphrase:") + os.write(master_fd, "This is actually not a passphrase\n".encode("utf-8")) + hsmtool.proc.wait(5) + hsmtool.is_in_log(r"New hsm_secret file created") + + # We can start the node with this hsm_secret + l1.start() + + # this test does a 'listtransactions' on a yet unconfirmed channel def test_fundchannel_listtransaction(node_factory, bitcoind): l1, l2 = node_factory.get_nodes(2) diff --git a/tools/hsmtool.c b/tools/hsmtool.c index eecf54fd9..dbfa2483c 100644 --- a/tools/hsmtool.c +++ b/tools/hsmtool.c @@ -461,6 +461,7 @@ static void get_words(struct words **words) { printf(" %zu) %s (%s)\n", i, languages[i].name, languages[i].abbr); } printf("Select [0-%zu]: ", ARRAY_SIZE(languages)); + fflush(stdout); char *selected = NULL; size_t size = 0; @@ -483,6 +484,7 @@ static void get_mnemonic(char *mnemonic) { size_t line_size = 0; printf("Introduce your BIP39 word list separated by space:\n"); + fflush(stdout); size_t characters = getline(&line, &line_size, stdin); if (characters < 0) errx(ERROR_USAGE, "Could not read line from stdin.");