Skip to content

Commit f0f4bb9

Browse files
authored
Merge pull request #3129 from IntersectMBO/add_key_mnemonic_test
Add key mnemonic test
2 parents 1a27e31 + a12f927 commit f0f4bb9

File tree

3 files changed

+78
-5
lines changed

3 files changed

+78
-5
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
"""Tests for deriving keys from a mnemonic sentence."""
2+
3+
import logging
4+
import pathlib as pl
5+
import typing as tp
6+
7+
import allure
8+
import pytest
9+
from cardano_clusterlib import clusterlib
10+
11+
from cardano_node_tests.tests import common
12+
from cardano_node_tests.utils import helpers
13+
14+
LOGGER = logging.getLogger(__name__)
15+
16+
17+
@common.SKIPIF_WRONG_ERA
18+
class TestMnemonic:
19+
"""Tests for mnemonic sentence."""
20+
21+
@allure.link(helpers.get_vcs_link())
22+
@pytest.mark.parametrize("size", (12, 15, 18, 21, 24))
23+
@pytest.mark.parametrize("out", ("file", "stdout"))
24+
@pytest.mark.parametrize(
25+
"key_type",
26+
# pyrefly: ignore # no-matching-overload
27+
iter(clusterlib.KeyType),
28+
# pyrefly: ignore # no-matching-overload
29+
ids=(k.value.replace("-", "_") for k in iter(clusterlib.KeyType)),
30+
)
31+
@pytest.mark.parametrize(
32+
"out_format",
33+
# pyrefly: ignore # no-matching-overload
34+
iter(clusterlib.OutputFormat),
35+
# pyrefly: ignore # no-matching-overload
36+
ids=(k.value.replace("-", "_") for k in iter(clusterlib.OutputFormat)),
37+
)
38+
@pytest.mark.parametrize("path_num", (0, 2**31 - 1))
39+
@pytest.mark.smoke
40+
def test_gen_and_deriv(
41+
self,
42+
cluster: clusterlib.ClusterLib,
43+
size: tp.Literal[12, 15, 18, 21, 24],
44+
out: str,
45+
key_type: clusterlib.KeyType,
46+
out_format: clusterlib.OutputFormat,
47+
path_num: int,
48+
):
49+
"""Test `generate-mnemonic` and `derive-from-mnemonic`."""
50+
temp_template = common.get_test_id(cluster)
51+
mnemonic_file = pl.Path(f"{temp_template}_mnemonic")
52+
53+
if out == "stdout":
54+
words = cluster.g_key.gen_mnemonic(size=size)
55+
mnemonic_file.write_text(" ".join(words))
56+
else:
57+
words = cluster.g_key.gen_mnemonic(size=size, out_file=mnemonic_file)
58+
assert len(words) == size
59+
60+
key_number = (
61+
path_num
62+
if (key_type in (clusterlib.KeyType.PAYMENT, clusterlib.KeyType.STAKE))
63+
else None
64+
)
65+
key_file = cluster.g_key.derive_from_mnemonic(
66+
key_name=f"{temp_template}_derived",
67+
key_type=key_type,
68+
mnemonic_file=mnemonic_file,
69+
account_number=path_num,
70+
key_number=key_number,
71+
out_format=out_format,
72+
)
73+
assert key_file.exists()

poetry.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ packages = [{include = "cardano_node_tests"}]
2626
[tool.poetry.dependencies]
2727
python = ">=3.11,<4.0"
2828
allure-pytest = "^2.14.3"
29-
cardano-clusterlib = "^0.9.3"
29+
cardano-clusterlib = "^0.9.4"
3030
cbor2 = "^5.6.5"
3131
filelock = "^3.18.0"
3232
hypothesis = "^6.135.17"

0 commit comments

Comments
 (0)