Skip to content

Commit

Permalink
EIP-712 Ragger tests snapshots handling
Browse files Browse the repository at this point in the history
Also moved snapshots root path to a centralized/common file
  • Loading branch information
apaillier-ledger committed Jan 31, 2024
1 parent d587204 commit 5140353
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
3 changes: 3 additions & 0 deletions tests/ragger/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from pathlib import Path

ROOT_SNAPSHOT_PATH = Path(__file__).parent
12 changes: 5 additions & 7 deletions tests/ragger/test_domain_name.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -12,8 +12,6 @@
from web3 import Web3


ROOT_SCREENSHOT_PATH = Path(__file__).parent

# Values used across all tests
CHAIN_ID = 1
NAME = "ledger.eth"
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down
10 changes: 10 additions & 0 deletions tests/ragger/test_eip712.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,17 @@
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]:
Expand Down
8 changes: 3 additions & 5 deletions tests/ragger/test_get_address.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
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
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])
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions tests/ragger/test_nft.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
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"
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 5140353

Please sign in to comment.