From ef7f2e128a4995c1060f53b563c774a8443dde04 Mon Sep 17 00:00:00 2001 From: Alexandre Paillier Date: Tue, 26 Jul 2022 16:56:13 +0200 Subject: [PATCH] Ragger tests now target all devices --- tests/ragger/conftest.py | 27 +++++++++++++++++---------- tests/ragger/ethereum_client.py | 6 +++++- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/tests/ragger/conftest.py b/tests/ragger/conftest.py index 64048dc..5f9efae 100644 --- a/tests/ragger/conftest.py +++ b/tests/ragger/conftest.py @@ -1,14 +1,15 @@ import pytest +from pathlib import Path from ragger import Firmware from ragger.backend import SpeculosBackend, LedgerCommBackend, LedgerWalletBackend, BackendInterface from ethereum_client import EthereumClient -# This variable is needed for Speculos only (physical tests need the application to be already installed) -APPLICATION = "../../bin/app.elf" -# This variable will be useful in tests to implement different behavior depending on the firmware -NANOX_FIRMWARE = Firmware("nanox", "2.0.2") -NANOS_FIRMWARE = Firmware("nanos", "2.1") -NANOSP_FIRMWARE = Firmware("nanosp", "1.0") +ELFS_DIR = (Path(__file__).parent.parent / "elfs").resolve() +FWS = [ + Firmware("nanox", "2.0.2"), + Firmware("nanos", "2.1"), + Firmware("nanosp", "1.0.3") +] # adding a pytest CLI option "--backend" def pytest_addoption(parser): @@ -21,9 +22,15 @@ def backend_name(pytestconfig) -> str: return pytestconfig.getoption("backend") # Providing the firmware as a fixture -@pytest.fixture -def firmware() -> Firmware: - return NANOX_FIRMWARE +@pytest.fixture(params=FWS) +def firmware(request) -> Firmware: + return request.param + +def get_elf_path(firmware: Firmware) -> Path: + assert ELFS_DIR.is_dir(), f"{ELFS_DIR} is not a directory" + app = ELFS_DIR / ("app-%s.elf" % firmware.device) + assert app.is_file(), f"{app} must exist" + return app # Depending on the "--backend" option value, a different backend is # instantiated, and the tests will either run on Speculos or on a physical @@ -34,7 +41,7 @@ def create_backend(backend: str, firmware: Firmware) -> BackendInterface: elif backend.lower() == "ledgerwallet": return LedgerWalletBackend(firmware) elif backend.lower() == "speculos": - return SpeculosBackend(APPLICATION, firmware) + return SpeculosBackend(get_elf_path(firmware), firmware) else: raise ValueError(f"Backend '{backend}' is unknown. Valid backends are: {BACKENDS}") diff --git a/tests/ragger/ethereum_client.py b/tests/ragger/ethereum_client.py index fd56ef2..5f1aea9 100644 --- a/tests/ragger/ethereum_client.py +++ b/tests/ragger/ethereum_client.py @@ -222,7 +222,11 @@ class EthereumClient: message_hash)) self._client.right_click() # sign typed message screen for _ in range(2): # two hashes (domain + message) - for _ in range(2): # two screens per hash + if self._client.firmware.device == "nanos": + screens_per_hash = 4 + else: + screens_per_hash = 2 + for _ in range(screens_per_hash): self._client.right_click() self._client.both_click() # approve signature