From c8c6b9a2d1a742d044d66f970f3d51d43a162f21 Mon Sep 17 00:00:00 2001 From: Alexandre Paillier Date: Tue, 30 Jan 2024 11:47:44 +0100 Subject: [PATCH] EIP-712 Ragger tests snapshots handling Also moved snapshots root path to a centralized/common file --- tests/ragger/constants.py | 3 +++ tests/ragger/test_domain_name.py | 12 +++++------- tests/ragger/test_eip712.py | 10 ++++++++++ tests/ragger/test_get_address.py | 8 +++----- tests/ragger/test_nft.py | 4 ++-- 5 files changed, 23 insertions(+), 14 deletions(-) create mode 100644 tests/ragger/constants.py diff --git a/tests/ragger/constants.py b/tests/ragger/constants.py new file mode 100644 index 0000000..86b6304 --- /dev/null +++ b/tests/ragger/constants.py @@ -0,0 +1,3 @@ +from pathlib import Path + +ROOT_SNAPSHOT_PATH = Path(__file__).parent diff --git a/tests/ragger/test_domain_name.py b/tests/ragger/test_domain_name.py index 36637a3..71eea7b 100644 --- a/tests/ragger/test_domain_name.py +++ b/tests/ragger/test_domain_name.py @@ -1,9 +1,9 @@ import pytest -from pathlib import Path from ragger.backend import BackendInterface from ragger.firmware import Firmware from ragger.error import ExceptionRAPDU from ragger.navigator import Navigator, NavInsID +from constants import ROOT_SNAPSHOT_PATH import ledger_app_clients.ethereum.response_parser as ResponseParser from ledger_app_clients.ethereum.client import EthAppClient, StatusWord @@ -12,8 +12,6 @@ from ledger_app_clients.ethereum.settings import SettingID, settings_toggle from web3 import Web3 -ROOT_SCREENSHOT_PATH = Path(__file__).parent - # Values used across all tests CHAIN_ID = 1 NAME = "ledger.eth" @@ -74,7 +72,7 @@ def test_send_fund(firmware: Firmware, if verbose: moves += [NavInsID.USE_CASE_REVIEW_TAP] moves += [NavInsID.USE_CASE_REVIEW_CONFIRM] - navigator.navigate_and_compare(ROOT_SCREENSHOT_PATH, + navigator.navigate_and_compare(ROOT_SNAPSHOT_PATH, "domain_name_verbose_" + str(verbose), moves) @@ -123,7 +121,7 @@ def test_send_fund_wrong_addr(firmware: Firmware, else: moves += [NavInsID.USE_CASE_REVIEW_TAP] * 2 moves += [NavInsID.USE_CASE_REVIEW_CONFIRM] - navigator.navigate_and_compare(ROOT_SCREENSHOT_PATH, + navigator.navigate_and_compare(ROOT_SNAPSHOT_PATH, "domain_name_wrong_addr", moves) @@ -154,7 +152,7 @@ def test_send_fund_non_mainnet(firmware: Firmware, else: moves += [NavInsID.USE_CASE_REVIEW_TAP] * 2 moves += [NavInsID.USE_CASE_REVIEW_CONFIRM] - navigator.navigate_and_compare(ROOT_SCREENSHOT_PATH, + navigator.navigate_and_compare(ROOT_SNAPSHOT_PATH, "domain_name_non_mainnet", moves) @@ -185,7 +183,7 @@ def test_send_fund_unknown_chain(firmware: Firmware, else: moves += [NavInsID.USE_CASE_REVIEW_TAP] * 3 moves += [NavInsID.USE_CASE_REVIEW_CONFIRM] - navigator.navigate_and_compare(ROOT_SCREENSHOT_PATH, + navigator.navigate_and_compare(ROOT_SNAPSHOT_PATH, "domain_name_unknown_chain", moves) diff --git a/tests/ragger/test_eip712.py b/tests/ragger/test_eip712.py index ec4a22a..46b4259 100644 --- a/tests/ragger/test_eip712.py +++ b/tests/ragger/test_eip712.py @@ -16,7 +16,17 @@ from ledger_app_clients.ethereum.eip712 import InputData from ledger_app_clients.ethereum.settings import SettingID, settings_toggle +class SnapshotsConfig: + test_name: str + idx: int + + def __init__(self, test_name: str, idx: int = 0): + self.test_name = test_name + self.idx = idx + + BIP32_PATH = "m/44'/60'/0'/0/0" +snaps_config: Optional[SnapshotsConfig] = None def input_files() -> list[str]: diff --git a/tests/ragger/test_get_address.py b/tests/ragger/test_get_address.py index 46c290a..60cf4bb 100644 --- a/tests/ragger/test_get_address.py +++ b/tests/ragger/test_get_address.py @@ -1,6 +1,5 @@ import pytest from typing import Optional -from pathlib import Path from ragger.error import ExceptionRAPDU from ragger.firmware import Firmware from ragger.backend import BackendInterface @@ -8,8 +7,7 @@ from ragger.navigator import Navigator, NavInsID from ledger_app_clients.ethereum.client import EthAppClient, StatusWord import ledger_app_clients.ethereum.response_parser as ResponseParser from ragger.bip import calculate_public_key_and_chaincode, CurveChoice - -ROOT_SCREENSHOT_PATH = Path(__file__).parent +from constants import ROOT_SNAPSHOT_PATH @pytest.fixture(params=[True, False]) @@ -56,7 +54,7 @@ def test_get_pk_rejected(firmware: Firmware, try: with app_client.get_public_addr(): - navigator.navigate_and_compare(ROOT_SCREENSHOT_PATH, + navigator.navigate_and_compare(ROOT_SNAPSHOT_PATH, "get_pk_rejected", get_moves(firmware, navigator, reject=True)) except ExceptionRAPDU as e: @@ -73,7 +71,7 @@ def test_get_pk(firmware: Firmware, app_client = EthAppClient(backend) with app_client.get_public_addr(chaincode=with_chaincode, chain_id=chain): - navigator.navigate_and_compare(ROOT_SCREENSHOT_PATH, + navigator.navigate_and_compare(ROOT_SNAPSHOT_PATH, "get_pk_%s" % (chain), get_moves(firmware, navigator, chain=chain)) pk, addr, chaincode = ResponseParser.pk_addr(app_client.response().data, with_chaincode) diff --git a/tests/ragger/test_nft.py b/tests/ragger/test_nft.py index 17430c1..87c1ac0 100644 --- a/tests/ragger/test_nft.py +++ b/tests/ragger/test_nft.py @@ -12,9 +12,9 @@ from ledger_app_clients.ethereum.utils import get_selector_from_data, recover_tr from web3 import Web3 import json import os +from constants import ROOT_SNAPSHOT_PATH -ROOT_SCREENSHOT_PATH = Path(__file__).parent ABIS_FOLDER = "%s/abis" % (os.path.dirname(__file__)) BIP32_PATH = "m/44'/60'/0'/0/0" @@ -116,7 +116,7 @@ def common_test_nft(fw: Firmware, "data": data, } with app_client.sign(BIP32_PATH, tx_params): - nav.navigate_and_compare(ROOT_SCREENSHOT_PATH, + nav.navigate_and_compare(ROOT_SNAPSHOT_PATH, snapshot_test_name(plugin_name.lower(), action.fn_name, collec.chain_id,