EIP-712 Ragger tests snapshots handling
Also moved snapshots root path to a centralized/common file
This commit is contained in:
3
tests/ragger/constants.py
Normal file
3
tests/ragger/constants.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from pathlib import Path
|
||||
|
||||
ROOT_SNAPSHOT_PATH = Path(__file__).parent
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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]:
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user