From 9faba1485499e6ceb6fc75de0319bec9a638f50c Mon Sep 17 00:00:00 2001 From: Aneesh Karve Date: Wed, 5 Jun 2024 17:15:31 -0700 Subject: [PATCH] test for bad input, improve help text --- src/bipsea/bipsea.py | 2 +- tests/test_cli.py | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/bipsea/bipsea.py b/src/bipsea/bipsea.py index 0470567..c34e398 100644 --- a/src/bipsea/bipsea.py +++ b/src/bipsea/bipsea.py @@ -125,7 +125,7 @@ def bip39_cmd(from_, to, input, number, passphrase, pretty): words = normalize_list(re.split(r"\s+", input), lower=True) if language and not verify_seed_words(words, language): raise click.BadParameter( - f"--input mnemonic not in {from_} or has bad checksum.", + f"--input mnemonic not in {ISO_TO_LANGUAGE[from_]} wordlist or has bad checksum.", param_hint="--input", ) if from_ == "any": diff --git a/tests/test_cli.py b/tests/test_cli.py index d8ef9a3..6c26b89 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -73,7 +73,8 @@ def test_seed_option_sensitivity(runner, language, vectors): result = runner.invoke(cli, cmd) if suffix == ".": assert result.exit_code != 0 - assert lang_code in result.output + assert ISO_TO_LANGUAGE[lang_code] in result.output + assert "not in" in result.output else: assert result.exit_code == 0 result_xprv = result.output.strip().split("\n")[-1] @@ -242,3 +243,10 @@ def test_entropy_wif(runner, vector): result = runner.invoke(cli, ["entropy", "-a", "wif", "--input", xprv]) assert result.exit_code == 0 assert result.output.strip() == vector["derived_wif"] + + +def test_seed_bad_input(runner): + phrase = "きわめる そせい ばかり なみだ みつかる くしゃみ にあう ひみつ かくとく よけい げんき ほきょう" + result = runner.invoke(cli, ["seed", "-f", "spa", "--input", phrase]) + assert result.exit_code != 0 + assert "not in spa" in result.output