Skip to content

Commit

Permalink
1st test (for Stax only so far) that uses Speculos load-nvram functio…
Browse files Browse the repository at this point in the history
…nality
  • Loading branch information
iartemov-ledger committed Feb 28, 2025
1 parent 31a21a2 commit dcd638f
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 1 deletion.
33 changes: 32 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
from pathlib import Path
from typing import List, Optional
import pytest
from ragger.firmware import Firmware
from ragger.conftest.base_conftest import prepare_speculos_args
from ragger.backend import SpeculosBackend

###########################
### CONFIGURATION START ###
###########################

# You can configure optional parameters by overriding the value of ragger.configuration.OPTIONAL_CONFIGURATION
# You can configure optional parameters by overriding the value
# of ragger.configuration.OPTIONAL_CONFIGURATION
# Please refer to ragger/conftest/configuration.py for their descriptions and accepted values

#########################
Expand All @@ -12,3 +19,27 @@

# Pull all features from the base ragger conftest using the overridden configuration
pytest_plugins = ("ragger.conftest.base_conftest", )

@pytest.fixture(scope="function")
def get_2_backends(
root_pytest_dir: Path,
firmware: Firmware,
display: bool,
log_apdu_file: Optional[Path],
cli_user_seed: str,
additional_speculos_arguments: List[str]):

b = []
additional_speculos_arguments_loc = \
[additional_speculos_arguments, \
additional_speculos_arguments + ["--load-nvram"]]

for i in range(2):
main_app_path, speculos_args = prepare_speculos_args(root_pytest_dir, firmware, display,
cli_user_seed,
additional_speculos_arguments_loc[i])
b.append(SpeculosBackend(main_app_path,
firmware=firmware,
log_apdu_file=log_apdu_file,
**speculos_args))
yield b[0], b[1]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 55 additions & 0 deletions tests/test_app_storage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import pytest
from ragger.backend import SpeculosBackend
from ragger.firmware import Firmware
from ragger.navigator import NavInsID, NavIns
from ragger.navigator import NanoNavigator, TouchNavigator

def get_navigator(
backend: SpeculosBackend,
golden_run: bool):
NavigatorType = TouchNavigator if backend.firmware == Firmware.STAX else NanoNavigator
return NavigatorType(backend, backend.firmware, golden_run)

# In this test we check app persistent storage functionality supported by Speculos
def test_app_storage_verification(
firmware: Firmware,
get_2_backends,
backend_name: str,
golden_run: bool,
test_name: str,
default_screenshot_path: str) -> None:

if backend_name != "speculos":
pytest.skip("Requires Speculos")

b_setup, b_with_load_nvram = get_2_backends

# Navigating in the main menu and creating some persistent data
with b_setup:
navigator1 = get_navigator(b_setup, golden_run)
instructions = []
if firmware is Firmware.STAX:
instructions += [
NavInsID.USE_CASE_HOME_SETTINGS,
NavIns(NavInsID.TOUCH, (200, 113)),
NavIns(NavInsID.TOUCH, (200, 261)),
NavInsID.USE_CASE_CHOICE_CONFIRM,
NavIns(NavInsID.TOUCH, (200, 261)),
NavInsID.USE_CASE_SETTINGS_MULTI_PAGE_EXIT
]
assert len(instructions) > 0
navigator1.navigate_and_compare(default_screenshot_path, test_name + "_setup", instructions,
screen_change_before_first_instruction=False)

# Pre-loading the persistent data and checking it
with b_with_load_nvram:
navigator2 = get_navigator(b_with_load_nvram, golden_run)
instructions = []
if firmware is Firmware.STAX:
instructions += [
NavInsID.USE_CASE_HOME_SETTINGS,
NavInsID.USE_CASE_SETTINGS_MULTI_PAGE_EXIT
]
assert len(instructions) > 0
navigator2.navigate_and_compare(default_screenshot_path, test_name + "_check", instructions,
screen_change_before_first_instruction=False)

0 comments on commit dcd638f

Please sign in to comment.