Skip to content

Commit c8c6b9a

Browse files
EIP-712 Ragger tests snapshots handling
Also moved snapshots root path to a centralized/common file
1 parent d24d630 commit c8c6b9a

File tree

5 files changed

+23
-14
lines changed

5 files changed

+23
-14
lines changed

tests/ragger/constants.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from pathlib import Path
2+
3+
ROOT_SNAPSHOT_PATH = Path(__file__).parent

tests/ragger/test_domain_name.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import pytest
2-
from pathlib import Path
32
from ragger.backend import BackendInterface
43
from ragger.firmware import Firmware
54
from ragger.error import ExceptionRAPDU
65
from ragger.navigator import Navigator, NavInsID
6+
from constants import ROOT_SNAPSHOT_PATH
77

88
import ledger_app_clients.ethereum.response_parser as ResponseParser
99
from ledger_app_clients.ethereum.client import EthAppClient, StatusWord
@@ -12,8 +12,6 @@
1212
from web3 import Web3
1313

1414

15-
ROOT_SCREENSHOT_PATH = Path(__file__).parent
16-
1715
# Values used across all tests
1816
CHAIN_ID = 1
1917
NAME = "ledger.eth"
@@ -74,7 +72,7 @@ def test_send_fund(firmware: Firmware,
7472
if verbose:
7573
moves += [NavInsID.USE_CASE_REVIEW_TAP]
7674
moves += [NavInsID.USE_CASE_REVIEW_CONFIRM]
77-
navigator.navigate_and_compare(ROOT_SCREENSHOT_PATH,
75+
navigator.navigate_and_compare(ROOT_SNAPSHOT_PATH,
7876
"domain_name_verbose_" + str(verbose),
7977
moves)
8078

@@ -123,7 +121,7 @@ def test_send_fund_wrong_addr(firmware: Firmware,
123121
else:
124122
moves += [NavInsID.USE_CASE_REVIEW_TAP] * 2
125123
moves += [NavInsID.USE_CASE_REVIEW_CONFIRM]
126-
navigator.navigate_and_compare(ROOT_SCREENSHOT_PATH,
124+
navigator.navigate_and_compare(ROOT_SNAPSHOT_PATH,
127125
"domain_name_wrong_addr",
128126
moves)
129127

@@ -154,7 +152,7 @@ def test_send_fund_non_mainnet(firmware: Firmware,
154152
else:
155153
moves += [NavInsID.USE_CASE_REVIEW_TAP] * 2
156154
moves += [NavInsID.USE_CASE_REVIEW_CONFIRM]
157-
navigator.navigate_and_compare(ROOT_SCREENSHOT_PATH,
155+
navigator.navigate_and_compare(ROOT_SNAPSHOT_PATH,
158156
"domain_name_non_mainnet",
159157
moves)
160158

@@ -185,7 +183,7 @@ def test_send_fund_unknown_chain(firmware: Firmware,
185183
else:
186184
moves += [NavInsID.USE_CASE_REVIEW_TAP] * 3
187185
moves += [NavInsID.USE_CASE_REVIEW_CONFIRM]
188-
navigator.navigate_and_compare(ROOT_SCREENSHOT_PATH,
186+
navigator.navigate_and_compare(ROOT_SNAPSHOT_PATH,
189187
"domain_name_unknown_chain",
190188
moves)
191189

tests/ragger/test_eip712.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,17 @@
1616
from ledger_app_clients.ethereum.settings import SettingID, settings_toggle
1717

1818

19+
class SnapshotsConfig:
20+
test_name: str
21+
idx: int
22+
23+
def __init__(self, test_name: str, idx: int = 0):
24+
self.test_name = test_name
25+
self.idx = idx
26+
27+
1928
BIP32_PATH = "m/44'/60'/0'/0/0"
29+
snaps_config: Optional[SnapshotsConfig] = None
2030

2131

2232
def input_files() -> list[str]:

tests/ragger/test_get_address.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import pytest
22
from typing import Optional
3-
from pathlib import Path
43
from ragger.error import ExceptionRAPDU
54
from ragger.firmware import Firmware
65
from ragger.backend import BackendInterface
76
from ragger.navigator import Navigator, NavInsID
87
from ledger_app_clients.ethereum.client import EthAppClient, StatusWord
98
import ledger_app_clients.ethereum.response_parser as ResponseParser
109
from ragger.bip import calculate_public_key_and_chaincode, CurveChoice
11-
12-
ROOT_SCREENSHOT_PATH = Path(__file__).parent
10+
from constants import ROOT_SNAPSHOT_PATH
1311

1412

1513
@pytest.fixture(params=[True, False])
@@ -56,7 +54,7 @@ def test_get_pk_rejected(firmware: Firmware,
5654

5755
try:
5856
with app_client.get_public_addr():
59-
navigator.navigate_and_compare(ROOT_SCREENSHOT_PATH,
57+
navigator.navigate_and_compare(ROOT_SNAPSHOT_PATH,
6058
"get_pk_rejected",
6159
get_moves(firmware, navigator, reject=True))
6260
except ExceptionRAPDU as e:
@@ -73,7 +71,7 @@ def test_get_pk(firmware: Firmware,
7371
app_client = EthAppClient(backend)
7472

7573
with app_client.get_public_addr(chaincode=with_chaincode, chain_id=chain):
76-
navigator.navigate_and_compare(ROOT_SCREENSHOT_PATH,
74+
navigator.navigate_and_compare(ROOT_SNAPSHOT_PATH,
7775
"get_pk_%s" % (chain),
7876
get_moves(firmware, navigator, chain=chain))
7977
pk, addr, chaincode = ResponseParser.pk_addr(app_client.response().data, with_chaincode)

tests/ragger/test_nft.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
from web3 import Web3
1313
import json
1414
import os
15+
from constants import ROOT_SNAPSHOT_PATH
1516

1617

17-
ROOT_SCREENSHOT_PATH = Path(__file__).parent
1818
ABIS_FOLDER = "%s/abis" % (os.path.dirname(__file__))
1919

2020
BIP32_PATH = "m/44'/60'/0'/0/0"
@@ -116,7 +116,7 @@ def common_test_nft(fw: Firmware,
116116
"data": data,
117117
}
118118
with app_client.sign(BIP32_PATH, tx_params):
119-
nav.navigate_and_compare(ROOT_SCREENSHOT_PATH,
119+
nav.navigate_and_compare(ROOT_SNAPSHOT_PATH,
120120
snapshot_test_name(plugin_name.lower(),
121121
action.fn_name,
122122
collec.chain_id,

0 commit comments

Comments
 (0)