diff --git a/client/src/ledger_app_clients/ethereum/eip712/InputData.py b/client/src/ledger_app_clients/ethereum/eip712/InputData.py index 1d0263af3c..a19ccf3e83 100644 --- a/client/src/ledger_app_clients/ethereum/eip712/InputData.py +++ b/client/src/ledger_app_clients/ethereum/eip712/InputData.py @@ -337,12 +337,11 @@ def next_timeout(_signum: int, _frame): def enable_autonext(): - seconds = 1/4 if app_client._client.firmware.device == 'stax': # Stax Speculos is slow - interval = seconds * 3 + delay = 1.5 else: - interval = seconds - signal.setitimer(signal.ITIMER_REAL, seconds, interval) + delay = 1/4 + signal.setitimer(signal.ITIMER_REAL, delay, delay) def disable_autonext(): diff --git a/tests/ragger/eip712_input_files/address_substitution.json b/tests/ragger/eip712_input_files/address_substitution.json new file mode 100644 index 0000000000..3cff494e89 --- /dev/null +++ b/tests/ragger/eip712_input_files/address_substitution.json @@ -0,0 +1,29 @@ +{ + "domain": { + "chainId": 1, + "name": "Token test", + "verifyingContract": "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC", + "version": "1" + }, + "message": { + "from": "0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa", + "to": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", + "amount": "117", + "token": "0x6B175474E89094C44Da98b954EedeAC495271d0F" + }, + "primaryType": "Transfer", + "types": { + "EIP712Domain": [ + { "name": "name", "type": "string" }, + { "name": "version", "type": "string" }, + { "name": "chainId", "type": "uint256" }, + { "name": "verifyingContract", "type": "address" } + ], + "Transfer": [ + { "name": "from", "type": "address" }, + { "name": "to", "type": "address" }, + { "name": "amount", "type": "uint256" }, + { "name": "token", "type": "address" } + ] + } +} diff --git a/tests/ragger/snapshots/nanosp/eip712_address_substitution/00000.png b/tests/ragger/snapshots/nanosp/eip712_address_substitution/00000.png new file mode 100644 index 0000000000..b546f65af2 Binary files /dev/null and b/tests/ragger/snapshots/nanosp/eip712_address_substitution/00000.png differ diff --git a/tests/ragger/snapshots/nanosp/eip712_address_substitution/00001.png b/tests/ragger/snapshots/nanosp/eip712_address_substitution/00001.png new file mode 100644 index 0000000000..5ea6164a8f Binary files /dev/null and b/tests/ragger/snapshots/nanosp/eip712_address_substitution/00001.png differ diff --git a/tests/ragger/snapshots/nanosp/eip712_address_substitution/00002.png b/tests/ragger/snapshots/nanosp/eip712_address_substitution/00002.png new file mode 100644 index 0000000000..e9adb7c1d9 Binary files /dev/null and b/tests/ragger/snapshots/nanosp/eip712_address_substitution/00002.png differ diff --git a/tests/ragger/snapshots/nanosp/eip712_address_substitution/00003.png b/tests/ragger/snapshots/nanosp/eip712_address_substitution/00003.png new file mode 100644 index 0000000000..13f8255b9e Binary files /dev/null and b/tests/ragger/snapshots/nanosp/eip712_address_substitution/00003.png differ diff --git a/tests/ragger/snapshots/nanosp/eip712_address_substitution/00004.png b/tests/ragger/snapshots/nanosp/eip712_address_substitution/00004.png new file mode 100644 index 0000000000..6983285c24 Binary files /dev/null and b/tests/ragger/snapshots/nanosp/eip712_address_substitution/00004.png differ diff --git a/tests/ragger/snapshots/nanosp/eip712_address_substitution/00005.png b/tests/ragger/snapshots/nanosp/eip712_address_substitution/00005.png new file mode 100644 index 0000000000..53ae65195f Binary files /dev/null and b/tests/ragger/snapshots/nanosp/eip712_address_substitution/00005.png differ diff --git a/tests/ragger/snapshots/nanosp/eip712_address_substitution/00006.png b/tests/ragger/snapshots/nanosp/eip712_address_substitution/00006.png new file mode 100644 index 0000000000..6578872258 Binary files /dev/null and b/tests/ragger/snapshots/nanosp/eip712_address_substitution/00006.png differ diff --git a/tests/ragger/snapshots/nanosp/eip712_address_substitution_verbose/00000.png b/tests/ragger/snapshots/nanosp/eip712_address_substitution_verbose/00000.png new file mode 100644 index 0000000000..b546f65af2 Binary files /dev/null and b/tests/ragger/snapshots/nanosp/eip712_address_substitution_verbose/00000.png differ diff --git a/tests/ragger/snapshots/nanosp/eip712_address_substitution_verbose/00001.png b/tests/ragger/snapshots/nanosp/eip712_address_substitution_verbose/00001.png new file mode 100644 index 0000000000..7f1fe8adc5 Binary files /dev/null and b/tests/ragger/snapshots/nanosp/eip712_address_substitution_verbose/00001.png differ diff --git a/tests/ragger/snapshots/nanosp/eip712_address_substitution_verbose/00002.png b/tests/ragger/snapshots/nanosp/eip712_address_substitution_verbose/00002.png new file mode 100644 index 0000000000..71834ce430 Binary files /dev/null and b/tests/ragger/snapshots/nanosp/eip712_address_substitution_verbose/00002.png differ diff --git a/tests/ragger/snapshots/nanosp/eip712_address_substitution_verbose/00003.png b/tests/ragger/snapshots/nanosp/eip712_address_substitution_verbose/00003.png new file mode 100644 index 0000000000..25bfb06861 Binary files /dev/null and b/tests/ragger/snapshots/nanosp/eip712_address_substitution_verbose/00003.png differ diff --git a/tests/ragger/snapshots/nanosp/eip712_address_substitution_verbose/00004.png b/tests/ragger/snapshots/nanosp/eip712_address_substitution_verbose/00004.png new file mode 100644 index 0000000000..a4619ff2c4 Binary files /dev/null and b/tests/ragger/snapshots/nanosp/eip712_address_substitution_verbose/00004.png differ diff --git a/tests/ragger/snapshots/nanosp/eip712_address_substitution_verbose/00005.png b/tests/ragger/snapshots/nanosp/eip712_address_substitution_verbose/00005.png new file mode 100644 index 0000000000..bb49e6dab8 Binary files /dev/null and b/tests/ragger/snapshots/nanosp/eip712_address_substitution_verbose/00005.png differ diff --git a/tests/ragger/snapshots/nanosp/eip712_address_substitution_verbose/00006.png b/tests/ragger/snapshots/nanosp/eip712_address_substitution_verbose/00006.png new file mode 100644 index 0000000000..b9d7e1524a Binary files /dev/null and b/tests/ragger/snapshots/nanosp/eip712_address_substitution_verbose/00006.png differ diff --git a/tests/ragger/snapshots/nanosp/eip712_address_substitution_verbose/00007.png b/tests/ragger/snapshots/nanosp/eip712_address_substitution_verbose/00007.png new file mode 100644 index 0000000000..2191773cc1 Binary files /dev/null and b/tests/ragger/snapshots/nanosp/eip712_address_substitution_verbose/00007.png differ diff --git a/tests/ragger/snapshots/nanosp/eip712_address_substitution_verbose/00008.png b/tests/ragger/snapshots/nanosp/eip712_address_substitution_verbose/00008.png new file mode 100644 index 0000000000..394eff681f Binary files /dev/null and b/tests/ragger/snapshots/nanosp/eip712_address_substitution_verbose/00008.png differ diff --git a/tests/ragger/snapshots/nanosp/eip712_address_substitution_verbose/00009.png b/tests/ragger/snapshots/nanosp/eip712_address_substitution_verbose/00009.png new file mode 100644 index 0000000000..139d265572 Binary files /dev/null and b/tests/ragger/snapshots/nanosp/eip712_address_substitution_verbose/00009.png differ diff --git a/tests/ragger/snapshots/nanosp/eip712_address_substitution_verbose/00010.png b/tests/ragger/snapshots/nanosp/eip712_address_substitution_verbose/00010.png new file mode 100644 index 0000000000..aa7c74d61a Binary files /dev/null and b/tests/ragger/snapshots/nanosp/eip712_address_substitution_verbose/00010.png differ diff --git a/tests/ragger/snapshots/nanosp/eip712_address_substitution_verbose/00011.png b/tests/ragger/snapshots/nanosp/eip712_address_substitution_verbose/00011.png new file mode 100644 index 0000000000..53ae65195f Binary files /dev/null and b/tests/ragger/snapshots/nanosp/eip712_address_substitution_verbose/00011.png differ diff --git a/tests/ragger/snapshots/nanosp/eip712_address_substitution_verbose/00012.png b/tests/ragger/snapshots/nanosp/eip712_address_substitution_verbose/00012.png new file mode 100644 index 0000000000..6578872258 Binary files /dev/null and b/tests/ragger/snapshots/nanosp/eip712_address_substitution_verbose/00012.png differ diff --git a/tests/ragger/snapshots/nanox/eip712_address_substitution/00000.png b/tests/ragger/snapshots/nanox/eip712_address_substitution/00000.png new file mode 100644 index 0000000000..b546f65af2 Binary files /dev/null and b/tests/ragger/snapshots/nanox/eip712_address_substitution/00000.png differ diff --git a/tests/ragger/snapshots/nanox/eip712_address_substitution/00001.png b/tests/ragger/snapshots/nanox/eip712_address_substitution/00001.png new file mode 100644 index 0000000000..5ea6164a8f Binary files /dev/null and b/tests/ragger/snapshots/nanox/eip712_address_substitution/00001.png differ diff --git a/tests/ragger/snapshots/nanox/eip712_address_substitution/00002.png b/tests/ragger/snapshots/nanox/eip712_address_substitution/00002.png new file mode 100644 index 0000000000..e9adb7c1d9 Binary files /dev/null and b/tests/ragger/snapshots/nanox/eip712_address_substitution/00002.png differ diff --git a/tests/ragger/snapshots/nanox/eip712_address_substitution/00003.png b/tests/ragger/snapshots/nanox/eip712_address_substitution/00003.png new file mode 100644 index 0000000000..13f8255b9e Binary files /dev/null and b/tests/ragger/snapshots/nanox/eip712_address_substitution/00003.png differ diff --git a/tests/ragger/snapshots/nanox/eip712_address_substitution/00004.png b/tests/ragger/snapshots/nanox/eip712_address_substitution/00004.png new file mode 100644 index 0000000000..6983285c24 Binary files /dev/null and b/tests/ragger/snapshots/nanox/eip712_address_substitution/00004.png differ diff --git a/tests/ragger/snapshots/nanox/eip712_address_substitution/00005.png b/tests/ragger/snapshots/nanox/eip712_address_substitution/00005.png new file mode 100644 index 0000000000..53ae65195f Binary files /dev/null and b/tests/ragger/snapshots/nanox/eip712_address_substitution/00005.png differ diff --git a/tests/ragger/snapshots/nanox/eip712_address_substitution/00006.png b/tests/ragger/snapshots/nanox/eip712_address_substitution/00006.png new file mode 100644 index 0000000000..6578872258 Binary files /dev/null and b/tests/ragger/snapshots/nanox/eip712_address_substitution/00006.png differ diff --git a/tests/ragger/snapshots/nanox/eip712_address_substitution_verbose/00000.png b/tests/ragger/snapshots/nanox/eip712_address_substitution_verbose/00000.png new file mode 100644 index 0000000000..b546f65af2 Binary files /dev/null and b/tests/ragger/snapshots/nanox/eip712_address_substitution_verbose/00000.png differ diff --git a/tests/ragger/snapshots/nanox/eip712_address_substitution_verbose/00001.png b/tests/ragger/snapshots/nanox/eip712_address_substitution_verbose/00001.png new file mode 100644 index 0000000000..7f1fe8adc5 Binary files /dev/null and b/tests/ragger/snapshots/nanox/eip712_address_substitution_verbose/00001.png differ diff --git a/tests/ragger/snapshots/nanox/eip712_address_substitution_verbose/00002.png b/tests/ragger/snapshots/nanox/eip712_address_substitution_verbose/00002.png new file mode 100644 index 0000000000..71834ce430 Binary files /dev/null and b/tests/ragger/snapshots/nanox/eip712_address_substitution_verbose/00002.png differ diff --git a/tests/ragger/snapshots/nanox/eip712_address_substitution_verbose/00003.png b/tests/ragger/snapshots/nanox/eip712_address_substitution_verbose/00003.png new file mode 100644 index 0000000000..25bfb06861 Binary files /dev/null and b/tests/ragger/snapshots/nanox/eip712_address_substitution_verbose/00003.png differ diff --git a/tests/ragger/snapshots/nanox/eip712_address_substitution_verbose/00004.png b/tests/ragger/snapshots/nanox/eip712_address_substitution_verbose/00004.png new file mode 100644 index 0000000000..a4619ff2c4 Binary files /dev/null and b/tests/ragger/snapshots/nanox/eip712_address_substitution_verbose/00004.png differ diff --git a/tests/ragger/snapshots/nanox/eip712_address_substitution_verbose/00005.png b/tests/ragger/snapshots/nanox/eip712_address_substitution_verbose/00005.png new file mode 100644 index 0000000000..bb49e6dab8 Binary files /dev/null and b/tests/ragger/snapshots/nanox/eip712_address_substitution_verbose/00005.png differ diff --git a/tests/ragger/snapshots/nanox/eip712_address_substitution_verbose/00006.png b/tests/ragger/snapshots/nanox/eip712_address_substitution_verbose/00006.png new file mode 100644 index 0000000000..b9d7e1524a Binary files /dev/null and b/tests/ragger/snapshots/nanox/eip712_address_substitution_verbose/00006.png differ diff --git a/tests/ragger/snapshots/nanox/eip712_address_substitution_verbose/00007.png b/tests/ragger/snapshots/nanox/eip712_address_substitution_verbose/00007.png new file mode 100644 index 0000000000..2191773cc1 Binary files /dev/null and b/tests/ragger/snapshots/nanox/eip712_address_substitution_verbose/00007.png differ diff --git a/tests/ragger/snapshots/nanox/eip712_address_substitution_verbose/00008.png b/tests/ragger/snapshots/nanox/eip712_address_substitution_verbose/00008.png new file mode 100644 index 0000000000..394eff681f Binary files /dev/null and b/tests/ragger/snapshots/nanox/eip712_address_substitution_verbose/00008.png differ diff --git a/tests/ragger/snapshots/nanox/eip712_address_substitution_verbose/00009.png b/tests/ragger/snapshots/nanox/eip712_address_substitution_verbose/00009.png new file mode 100644 index 0000000000..139d265572 Binary files /dev/null and b/tests/ragger/snapshots/nanox/eip712_address_substitution_verbose/00009.png differ diff --git a/tests/ragger/snapshots/nanox/eip712_address_substitution_verbose/00010.png b/tests/ragger/snapshots/nanox/eip712_address_substitution_verbose/00010.png new file mode 100644 index 0000000000..aa7c74d61a Binary files /dev/null and b/tests/ragger/snapshots/nanox/eip712_address_substitution_verbose/00010.png differ diff --git a/tests/ragger/snapshots/nanox/eip712_address_substitution_verbose/00011.png b/tests/ragger/snapshots/nanox/eip712_address_substitution_verbose/00011.png new file mode 100644 index 0000000000..53ae65195f Binary files /dev/null and b/tests/ragger/snapshots/nanox/eip712_address_substitution_verbose/00011.png differ diff --git a/tests/ragger/snapshots/nanox/eip712_address_substitution_verbose/00012.png b/tests/ragger/snapshots/nanox/eip712_address_substitution_verbose/00012.png new file mode 100644 index 0000000000..6578872258 Binary files /dev/null and b/tests/ragger/snapshots/nanox/eip712_address_substitution_verbose/00012.png differ diff --git a/tests/ragger/snapshots/stax/eip712_address_substitution/00000.png b/tests/ragger/snapshots/stax/eip712_address_substitution/00000.png new file mode 100644 index 0000000000..7c64769b17 Binary files /dev/null and b/tests/ragger/snapshots/stax/eip712_address_substitution/00000.png differ diff --git a/tests/ragger/snapshots/stax/eip712_address_substitution/00001.png b/tests/ragger/snapshots/stax/eip712_address_substitution/00001.png new file mode 100644 index 0000000000..7437b4fcac Binary files /dev/null and b/tests/ragger/snapshots/stax/eip712_address_substitution/00001.png differ diff --git a/tests/ragger/snapshots/stax/eip712_address_substitution/00002.png b/tests/ragger/snapshots/stax/eip712_address_substitution/00002.png new file mode 100644 index 0000000000..7d3100bcce Binary files /dev/null and b/tests/ragger/snapshots/stax/eip712_address_substitution/00002.png differ diff --git a/tests/ragger/snapshots/stax/eip712_address_substitution/00003.png b/tests/ragger/snapshots/stax/eip712_address_substitution/00003.png new file mode 100644 index 0000000000..404c495539 Binary files /dev/null and b/tests/ragger/snapshots/stax/eip712_address_substitution/00003.png differ diff --git a/tests/ragger/snapshots/stax/eip712_address_substitution/00004.png b/tests/ragger/snapshots/stax/eip712_address_substitution/00004.png new file mode 100644 index 0000000000..987479c5ed Binary files /dev/null and b/tests/ragger/snapshots/stax/eip712_address_substitution/00004.png differ diff --git a/tests/ragger/snapshots/stax/eip712_address_substitution/00005.png b/tests/ragger/snapshots/stax/eip712_address_substitution/00005.png new file mode 100644 index 0000000000..726c927de7 Binary files /dev/null and b/tests/ragger/snapshots/stax/eip712_address_substitution/00005.png differ diff --git a/tests/ragger/snapshots/stax/eip712_address_substitution/00006.png b/tests/ragger/snapshots/stax/eip712_address_substitution/00006.png new file mode 100644 index 0000000000..c1a8fd4eb0 Binary files /dev/null and b/tests/ragger/snapshots/stax/eip712_address_substitution/00006.png differ diff --git a/tests/ragger/snapshots/stax/eip712_address_substitution_verbose/00000.png b/tests/ragger/snapshots/stax/eip712_address_substitution_verbose/00000.png new file mode 100644 index 0000000000..7c64769b17 Binary files /dev/null and b/tests/ragger/snapshots/stax/eip712_address_substitution_verbose/00000.png differ diff --git a/tests/ragger/snapshots/stax/eip712_address_substitution_verbose/00001.png b/tests/ragger/snapshots/stax/eip712_address_substitution_verbose/00001.png new file mode 100644 index 0000000000..eb09cbfbfa Binary files /dev/null and b/tests/ragger/snapshots/stax/eip712_address_substitution_verbose/00001.png differ diff --git a/tests/ragger/snapshots/stax/eip712_address_substitution_verbose/00002.png b/tests/ragger/snapshots/stax/eip712_address_substitution_verbose/00002.png new file mode 100644 index 0000000000..ebd81164b9 Binary files /dev/null and b/tests/ragger/snapshots/stax/eip712_address_substitution_verbose/00002.png differ diff --git a/tests/ragger/snapshots/stax/eip712_address_substitution_verbose/00003.png b/tests/ragger/snapshots/stax/eip712_address_substitution_verbose/00003.png new file mode 100644 index 0000000000..539bd78ea2 Binary files /dev/null and b/tests/ragger/snapshots/stax/eip712_address_substitution_verbose/00003.png differ diff --git a/tests/ragger/snapshots/stax/eip712_address_substitution_verbose/00004.png b/tests/ragger/snapshots/stax/eip712_address_substitution_verbose/00004.png new file mode 100644 index 0000000000..249ca4f627 Binary files /dev/null and b/tests/ragger/snapshots/stax/eip712_address_substitution_verbose/00004.png differ diff --git a/tests/ragger/snapshots/stax/eip712_address_substitution_verbose/00005.png b/tests/ragger/snapshots/stax/eip712_address_substitution_verbose/00005.png new file mode 100644 index 0000000000..c9f59eb18e Binary files /dev/null and b/tests/ragger/snapshots/stax/eip712_address_substitution_verbose/00005.png differ diff --git a/tests/ragger/snapshots/stax/eip712_address_substitution_verbose/00006.png b/tests/ragger/snapshots/stax/eip712_address_substitution_verbose/00006.png new file mode 100644 index 0000000000..8da1fa8c08 Binary files /dev/null and b/tests/ragger/snapshots/stax/eip712_address_substitution_verbose/00006.png differ diff --git a/tests/ragger/snapshots/stax/eip712_address_substitution_verbose/00007.png b/tests/ragger/snapshots/stax/eip712_address_substitution_verbose/00007.png new file mode 100644 index 0000000000..26ca679616 Binary files /dev/null and b/tests/ragger/snapshots/stax/eip712_address_substitution_verbose/00007.png differ diff --git a/tests/ragger/snapshots/stax/eip712_address_substitution_verbose/00008.png b/tests/ragger/snapshots/stax/eip712_address_substitution_verbose/00008.png new file mode 100644 index 0000000000..dee5c6cd2a Binary files /dev/null and b/tests/ragger/snapshots/stax/eip712_address_substitution_verbose/00008.png differ diff --git a/tests/ragger/snapshots/stax/eip712_address_substitution_verbose/00009.png b/tests/ragger/snapshots/stax/eip712_address_substitution_verbose/00009.png new file mode 100644 index 0000000000..fa8a88e3c4 Binary files /dev/null and b/tests/ragger/snapshots/stax/eip712_address_substitution_verbose/00009.png differ diff --git a/tests/ragger/snapshots/stax/eip712_address_substitution_verbose/00010.png b/tests/ragger/snapshots/stax/eip712_address_substitution_verbose/00010.png new file mode 100644 index 0000000000..606a1edc83 Binary files /dev/null and b/tests/ragger/snapshots/stax/eip712_address_substitution_verbose/00010.png differ diff --git a/tests/ragger/snapshots/stax/eip712_address_substitution_verbose/00011.png b/tests/ragger/snapshots/stax/eip712_address_substitution_verbose/00011.png new file mode 100644 index 0000000000..726c927de7 Binary files /dev/null and b/tests/ragger/snapshots/stax/eip712_address_substitution_verbose/00011.png differ diff --git a/tests/ragger/snapshots/stax/eip712_address_substitution_verbose/00012.png b/tests/ragger/snapshots/stax/eip712_address_substitution_verbose/00012.png new file mode 100644 index 0000000000..c1a8fd4eb0 Binary files /dev/null and b/tests/ragger/snapshots/stax/eip712_address_substitution_verbose/00012.png differ diff --git a/tests/ragger/test_eip712.py b/tests/ragger/test_eip712.py index 46b4259bcc..1b7b31f4d9 100644 --- a/tests/ragger/test_eip712.py +++ b/tests/ragger/test_eip712.py @@ -9,6 +9,8 @@ from ragger.firmware import Firmware from ragger.navigator import Navigator, NavInsID import json +from typing import Optional +from constants import ROOT_SCREENSHOT_PATH import ledger_app_clients.ethereum.response_parser as ResponseParser from ledger_app_clients.ethereum.client import EthAppClient @@ -29,9 +31,13 @@ def __init__(self, test_name: str, idx: int = 0): snaps_config: Optional[SnapshotsConfig] = None +def eip712_json_path() -> str: + return "%s/eip712_input_files" % (os.path.dirname(__file__)) + + def input_files() -> list[str]: files = [] - for file in os.scandir("%s/eip712_input_files" % (os.path.dirname(__file__))): + for file in os.scandir(eip712_json_path()): if fnmatch.fnmatch(file, "*-data.json"): files.append(file.path) return sorted(files) @@ -87,7 +93,52 @@ def autonext(fw: Firmware, nav: Navigator): moves = [NavInsID.RIGHT_CLICK] else: moves = [NavInsID.USE_CASE_REVIEW_TAP] - nav.navigate(moves, screen_change_before_first_instruction=False, screen_change_after_last_instruction=False) + if snaps_config is not None: + nav.navigate_and_compare(ROOT_SCREENSHOT_PATH, + snaps_config.test_name, + moves, + screen_change_before_first_instruction=False, + screen_change_after_last_instruction=False, + snap_start_idx=snaps_config.idx) + snaps_config.idx += 1 + else: + nav.navigate(moves, + screen_change_before_first_instruction=False, + screen_change_after_last_instruction=False) + + +def eip712_new_common(fw: Firmware, + nav: Navigator, + app_client: EthAppClient, + json_data: dict, + filters: Optional[dict], + verbose: bool): + assert InputData.process_data(app_client, + json_data, + filters, + partial(autonext, fw, nav)) + with app_client.eip712_sign_new(BIP32_PATH): + moves = list() + if fw.device.startswith("nano"): + # need to skip the message hash + if not verbose and filters is None: + moves = [NavInsID.RIGHT_CLICK] * 2 + moves += [NavInsID.BOTH_CLICK] + else: + time.sleep(1.5) + # need to skip the message hash + if not verbose and filters is None: + moves += [NavInsID.USE_CASE_REVIEW_TAP] + moves += [NavInsID.USE_CASE_REVIEW_CONFIRM] + if snaps_config is not None: + nav.navigate_and_compare(ROOT_SCREENSHOT_PATH, + snaps_config.test_name, + moves, + snap_start_idx=snaps_config.idx) + snaps_config.idx += 1 + else: + nav.navigate(moves) + return ResponseParser.signature(app_client.response().data) def test_eip712_new(firmware: Firmware, @@ -124,26 +175,69 @@ def test_eip712_new(firmware: Firmware, settings_toggle(firmware, navigator, [SettingID.VERBOSE_EIP712]) with open(input_file) as file: - assert InputData.process_data(app_client, - json.load(file), - filters, - partial(autonext, firmware, navigator)) - with app_client.eip712_sign_new(BIP32_PATH): - # tight on timing, needed by the CI otherwise might fail sometimes - time.sleep(0.5) - - moves = list() - if firmware.device.startswith("nano"): - if not verbose and not filtering: # need to skip the message hash - moves = [NavInsID.RIGHT_CLICK] * 2 - moves += [NavInsID.BOTH_CLICK] - else: - if not verbose and not filtering: # need to skip the message hash - moves += [NavInsID.USE_CASE_REVIEW_TAP] - moves += [NavInsID.USE_CASE_REVIEW_CONFIRM] - navigator.navigate(moves) - v, r, s = ResponseParser.signature(app_client.response().data) - - assert v == bytes.fromhex(config["signature"]["v"]) - assert r == bytes.fromhex(config["signature"]["r"]) - assert s == bytes.fromhex(config["signature"]["s"]) + v, r, s = eip712_new_common(firmware, + navigator, + app_client, + json.load(file), + filters, + verbose) + + assert v == bytes.fromhex(config["signature"]["v"]) + assert r == bytes.fromhex(config["signature"]["r"]) + assert s == bytes.fromhex(config["signature"]["s"]) + + +def test_eip712_address_substitution(firmware: Firmware, + backend: BackendInterface, + navigator: Navigator, + verbose: bool): + global snaps_config + + app_client = EthAppClient(backend) + if firmware.device == "nanos": + pytest.skip("Not supported on LNS") + else: + test_name = "eip712_address_substitution" + if verbose: + test_name += "_verbose" + snaps_config = SnapshotsConfig(test_name) + with open("%s/address_substitution.json" % (eip712_json_path())) as file: + data = json.load(file) + + with app_client.provide_token_metadata("DAI", + bytes.fromhex(data["message"]["token"][2:]), + 18, + 1): + pass + + with app_client.get_challenge(): + pass + challenge = ResponseParser.challenge(app_client.response().data) + with app_client.provide_domain_name(challenge, + "vitalik.eth", + bytes.fromhex(data["message"]["to"][2:])): + pass + + if verbose: + settings_toggle(firmware, navigator, [SettingID.VERBOSE_EIP712]) + filters = None + else: + filters = { + "name": "Token test", + "fields": { + "amount": "Amount", + "token": "Token", + "to": "To", + } + } + + v, r, s = eip712_new_common(firmware, + navigator, + app_client, + data, + filters, + verbose) + + assert v == bytes.fromhex("1b") + assert r == bytes.fromhex("d4a0e058251cdc3845aaa5eb8409d8a189ac668db7c55a64eb3121b0db7fd8c0") + assert s == bytes.fromhex("3221800e4f45272c6fa8fafda5e94c848d1a4b90c442aa62afa8e8d6a9af0f00")