From 6e477717decf43c971b4e2cf5d605bc633afe8bc Mon Sep 17 00:00:00 2001 From: Charles-Edouard de la Vergne Date: Mon, 25 Mar 2024 14:47:53 +0100 Subject: [PATCH] Port 'test_configuration_cmd' from 'speculos' to 'ragger' --- tests/ragger/test_configuration_cmd.py | 48 ++++++++++++++++++++++++ tests/speculos/test_configuration_cmd.py | 3 -- 2 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 tests/ragger/test_configuration_cmd.py delete mode 100644 tests/speculos/test_configuration_cmd.py diff --git a/tests/ragger/test_configuration_cmd.py b/tests/ragger/test_configuration_cmd.py new file mode 100644 index 0000000..c8a8e95 --- /dev/null +++ b/tests/ragger/test_configuration_cmd.py @@ -0,0 +1,48 @@ +from pathlib import Path +from typing import List +import re +from ragger.backend import BackendInterface +from ragger.utils.misc import get_current_app_name_and_version + + +def test_check_version(backend: BackendInterface): + """Check version and name""" + + # Send the APDU + app_name, version = get_current_app_name_and_version(backend) + print(f" Name: {app_name}") + print(f" Version: {version}") + _verify_version(version.split("-")[0]) + + +def _verify_version(version: str) -> None: + """Verify the app version, based on defines in Makefile + + Args: + Version (str): Version to be checked + """ + + vers_dict = {} + vers_str = "" + lines = _read_makefile() + version_re = re.compile(r"^APPVERSION_(?P\w)\s?=\s?(?P\d*)", re.I) + for line in lines: + info = version_re.match(line) + if info: + dinfo = info.groupdict() + vers_dict[dinfo["part"]] = dinfo["val"] + try: + vers_str = f"{vers_dict['M']}.{vers_dict['N']}.{vers_dict['P']}" + except KeyError: + pass + assert version == vers_str + + +def _read_makefile() -> List[str]: + """Read lines from the parent Makefile """ + + parent = Path(__file__).parent.parent.parent.resolve() + makefile = f"{parent}/Makefile" + with open(makefile, "r", encoding="utf-8") as f_p: + lines = f_p.readlines() + return lines diff --git a/tests/speculos/test_configuration_cmd.py b/tests/speculos/test_configuration_cmd.py deleted file mode 100644 index af56756..0000000 --- a/tests/speculos/test_configuration_cmd.py +++ /dev/null @@ -1,3 +0,0 @@ - -def test_configuration(cmd): - assert cmd.get_configuration() == (2, 1, 11, 0)