Skip to content

Commit

Permalink
Improve 'ROOT_SNAPSHOT_PATH' with latest ragger version
Browse files Browse the repository at this point in the history
  • Loading branch information
cedelavergne-ledger committed Apr 11, 2024
1 parent 8fcaf9f commit c9436ab
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 77 deletions.
2 changes: 0 additions & 2 deletions tests/ragger/constants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from pathlib import Path
import os

ROOT_SNAPSHOT_PATH = Path(__file__).parent
ABIS_FOLDER = f"{os.path.dirname(__file__)}/abis"
8 changes: 5 additions & 3 deletions tests/ragger/test_blind_sign.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from pathlib import Path
import json
import pytest
from web3 import Web3
Expand All @@ -9,14 +10,15 @@
from ragger.navigator import Navigator, NavInsID
from ragger.error import ExceptionRAPDU

from constants import ROOT_SNAPSHOT_PATH, ABIS_FOLDER
from constants import ABIS_FOLDER


# Token approval, would require loading the "internal plugin" &
# providing the token metadata from the CAL
def test_blind_sign(firmware: Firmware,
backend: BackendInterface,
navigator: Navigator):
navigator: Navigator,
default_screenshot_path: Path):
app_client = EthAppClient(backend)

with open(f"{ABIS_FOLDER}/erc20.json", encoding="utf-8") as file:
Expand Down Expand Up @@ -51,6 +53,6 @@ def test_blind_sign(firmware: Firmware,
moves += [NavInsID.BOTH_CLICK]
else:
moves += [NavInsID.USE_CASE_CHOICE_CONFIRM]
navigator.navigate_and_compare(ROOT_SNAPSHOT_PATH,
navigator.navigate_and_compare(default_screenshot_path,
"blind-signed_approval",
moves)
4 changes: 3 additions & 1 deletion tests/ragger/test_clone.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from pathlib import Path
from web3 import Web3

from ragger.backend import BackendInterface
Expand All @@ -20,6 +21,7 @@
def test_clone_thundercore(firmware: Firmware,
backend: BackendInterface,
navigator: Navigator,
default_screenshot_path: Path,
test_name: str):
tx_params: dict = {
"nonce": NONCE,
Expand All @@ -29,4 +31,4 @@ def test_clone_thundercore(firmware: Firmware,
"value": Web3.to_wei(VALUE, "ether"),
"chainId": 108
}
common(firmware, backend, navigator, tx_params, test_name, BIP32_PATH)
common(firmware, backend, navigator, default_screenshot_path, tx_params, test_name, BIP32_PATH)
21 changes: 12 additions & 9 deletions tests/ragger/test_domain_name.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from pathlib import Path
import pytest
from web3 import Web3

Expand All @@ -10,8 +11,6 @@
from ragger.error import ExceptionRAPDU
from ragger.navigator import Navigator, NavInsID

from constants import ROOT_SNAPSHOT_PATH


# Values used across all tests
CHAIN_ID = 1
Expand Down Expand Up @@ -42,6 +41,7 @@ def common(firmware: Firmware, app_client: EthAppClient) -> int:
def test_send_fund(firmware: Firmware,
backend: BackendInterface,
navigator: Navigator,
default_screenshot_path: Path,
verbose: bool):
app_client = EthAppClient(backend)
challenge = common(firmware, app_client)
Expand Down Expand Up @@ -71,7 +71,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_SNAPSHOT_PATH,
navigator.navigate_and_compare(default_screenshot_path,
"domain_name_verbose_" + str(verbose),
moves)

Expand All @@ -87,7 +87,8 @@ def test_send_fund_wrong_challenge(firmware: Firmware, backend: BackendInterface

def test_send_fund_wrong_addr(firmware: Firmware,
backend: BackendInterface,
navigator: Navigator):
navigator: Navigator,
default_screenshot_path: Path):
app_client = EthAppClient(backend)
challenge = common(firmware, app_client)

Expand All @@ -112,14 +113,15 @@ 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_SNAPSHOT_PATH,
navigator.navigate_and_compare(default_screenshot_path,
"domain_name_wrong_addr",
moves)


def test_send_fund_non_mainnet(firmware: Firmware,
backend: BackendInterface,
navigator: Navigator):
navigator: Navigator,
default_screenshot_path: Path):
app_client = EthAppClient(backend)
challenge = common(firmware, app_client)

Expand All @@ -141,14 +143,15 @@ 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_SNAPSHOT_PATH,
navigator.navigate_and_compare(default_screenshot_path,
"domain_name_non_mainnet",
moves)


def test_send_fund_unknown_chain(firmware: Firmware,
backend: BackendInterface,
navigator: Navigator):
navigator: Navigator,
default_screenshot_path: Path):
app_client = EthAppClient(backend)
challenge = common(firmware, app_client)

Expand All @@ -170,7 +173,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_SNAPSHOT_PATH,
navigator.navigate_and_compare(default_screenshot_path,
"domain_name_unknown_chain",
moves)

Expand Down
32 changes: 17 additions & 15 deletions tests/ragger/test_eip191.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from pathlib import Path
import pytest

from client.client import EthAppClient, StatusWord
Expand All @@ -9,16 +10,15 @@
from ragger.firmware import Firmware
from ragger.navigator import Navigator, NavInsID

from constants import ROOT_SNAPSHOT_PATH


BIP32_PATH = "m/44'/60'/0'/0/0"


def test_personal_sign_metamask(firmware: Firmware,
backend: BackendInterface,
navigator: Navigator,
test_name: str):
test_name: str,
default_screenshot_path: Path):

msg = "Example `personal_sign` message"

Expand All @@ -43,7 +43,7 @@ def test_personal_sign_metamask(firmware: Firmware,
navigator.navigate_until_text_and_compare(next_action,
[confirm_action],
"Sign",
ROOT_SNAPSHOT_PATH,
default_screenshot_path,
test_name)

# verify signature
Expand All @@ -55,7 +55,8 @@ def test_personal_sign_metamask(firmware: Firmware,
def test_personal_sign_non_ascii(firmware: Firmware,
backend: BackendInterface,
navigator: Navigator,
test_name: str):
test_name: str,
default_screenshot_path: Path):

msg = "0x9c22ff5f21f0b81b113e63f7db6da94fedef11b2119b4088b89664fb9a3cb658"

Expand All @@ -81,7 +82,7 @@ def test_personal_sign_non_ascii(firmware: Firmware,
navigator.navigate_until_text_and_compare(next_action,
[confirm_action],
"Sign",
ROOT_SNAPSHOT_PATH,
default_screenshot_path,
test_name)

# verify signature
Expand All @@ -93,7 +94,8 @@ def test_personal_sign_non_ascii(firmware: Firmware,
def test_personal_sign_opensea(firmware: Firmware,
backend: BackendInterface,
navigator: Navigator,
test_name: str):
test_name: str,
default_screenshot_path: Path):

msg = "Welcome to OpenSea!\n\nClick to sign in and accept the OpenSea Terms of Service: https://opensea.io/tos\n\nThis request will not trigger a blockchain transaction or cost any gas fees.\n\nYour authentication status will reset after 24 hours.\n\nWallet address:\n0x9858effd232b4033e47d90003d41ec34ecaeda94\n\nNonce:\n2b02c8a0-f74f-4554-9821-a28054dc9121"

Expand Down Expand Up @@ -121,7 +123,7 @@ def test_personal_sign_opensea(firmware: Firmware,
navigator.navigate_until_text_and_compare(next_action,
[confirm_action],
"Sign",
ROOT_SNAPSHOT_PATH,
default_screenshot_path,
test_name)

# verify signature
Expand All @@ -133,7 +135,8 @@ def test_personal_sign_opensea(firmware: Firmware,
def test_personal_sign_reject(firmware: Firmware,
backend: BackendInterface,
navigator: Navigator,
test_name: str):
test_name: str,
default_screenshot_path: Path):

msg = "This is an reject sign"

Expand All @@ -145,20 +148,19 @@ def test_personal_sign_reject(firmware: Firmware,
next_action = NavInsID.RIGHT_CLICK
confirm_action = NavInsID.BOTH_CLICK
navigator.navigate_until_text_and_compare(next_action,
[confirm_action],
"Cancel",
ROOT_SNAPSHOT_PATH,
test_name)
[confirm_action],
"Cancel",
default_screenshot_path,
test_name)
else:
# instructions = [NavInsID.USE_CASE_REVIEW_TAP]
instructions = [NavInsID.USE_CASE_CHOICE_REJECT,
NavInsID.USE_CASE_CHOICE_CONFIRM,
NavInsID.USE_CASE_STATUS_DISMISS]
navigator.navigate_and_compare(ROOT_SNAPSHOT_PATH,
navigator.navigate_and_compare(default_screenshot_path,
test_name,
instructions)


except ExceptionRAPDU as e:
assert e.status == StatusWord.CONDITION_NOT_SATISFIED
else:
Expand Down
15 changes: 9 additions & 6 deletions tests/ragger/test_eip712.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
from ragger.firmware import Firmware
from ragger.navigator import Navigator, NavInsID

from constants import ROOT_SNAPSHOT_PATH


class SnapshotsConfig:
test_name: str
Expand Down Expand Up @@ -90,14 +88,14 @@ def test_eip712_legacy(firmware: Firmware,
assert s == bytes.fromhex("52d8ba9153de9255da220ffd36762c0b027701a3b5110f0a765f94b16a9dfb55")


def autonext(firmware: Firmware, navigator: Navigator):
def autonext(firmware: Firmware, navigator: Navigator, default_screenshot_path: Path):
moves = []
if firmware.device.startswith("nano"):
moves = [NavInsID.RIGHT_CLICK]
else:
moves = [NavInsID.USE_CASE_REVIEW_TAP]
if snaps_config is not None:
navigator.navigate_and_compare(ROOT_SNAPSHOT_PATH,
navigator.navigate_and_compare(default_screenshot_path,
snaps_config.test_name,
moves,
screen_change_before_first_instruction=False,
Expand All @@ -112,14 +110,15 @@ def autonext(firmware: Firmware, navigator: Navigator):

def eip712_new_common(firmware: Firmware,
navigator: Navigator,
default_screenshot_path: Path,
app_client: EthAppClient,
json_data: dict,
filters: Optional[dict],
verbose: bool):
assert InputData.process_data(app_client,
json_data,
filters,
partial(autonext, firmware, navigator))
partial(autonext, firmware, navigator, default_screenshot_path))
with app_client.eip712_sign_new(BIP32_PATH):
moves = []
if firmware.device.startswith("nano"):
Expand All @@ -134,7 +133,7 @@ def eip712_new_common(firmware: Firmware,
moves += [NavInsID.USE_CASE_REVIEW_TAP]
moves += [NavInsID.USE_CASE_REVIEW_CONFIRM]
if snaps_config is not None:
navigator.navigate_and_compare(ROOT_SNAPSHOT_PATH,
navigator.navigate_and_compare(default_screenshot_path,
snaps_config.test_name,
moves,
snap_start_idx=snaps_config.idx)
Expand All @@ -147,6 +146,7 @@ def eip712_new_common(firmware: Firmware,
def test_eip712_new(firmware: Firmware,
backend: BackendInterface,
navigator: Navigator,
default_screenshot_path: Path,
input_file: Path,
verbose: bool,
filtering: bool):
Expand Down Expand Up @@ -181,6 +181,7 @@ def test_eip712_new(firmware: Firmware,
with open(input_file, encoding="utf-8") as file:
v, r, s = eip712_new_common(firmware,
navigator,
default_screenshot_path,
app_client,
json.load(file),
filters,
Expand All @@ -194,6 +195,7 @@ def test_eip712_new(firmware: Firmware,
def test_eip712_address_substitution(firmware: Firmware,
backend: BackendInterface,
navigator: Navigator,
default_screenshot_path: Path,
verbose: bool):
global snaps_config

Expand Down Expand Up @@ -237,6 +239,7 @@ def test_eip712_address_substitution(firmware: Firmware,

vrs = eip712_new_common(firmware,
navigator,
default_screenshot_path,
app_client,
data,
filters,
Expand Down
14 changes: 8 additions & 6 deletions tests/ragger/test_get_address.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from pathlib import Path
from typing import Optional
import pytest

Expand All @@ -12,8 +13,6 @@
from ragger.navigator import Navigator, NavInsID
from ragger.bip import calculate_public_key_and_chaincode, CurveChoice

from constants import ROOT_SNAPSHOT_PATH

from client.client import EthAppClient, StatusWord
import client.response_parser as ResponseParser

Expand Down Expand Up @@ -70,13 +69,14 @@ def get_moves(firmware: Firmware,
def test_get_pk_rejected(firmware: Firmware,
backend: BackendInterface,
navigator: Navigator,
default_screenshot_path: Path,
path,
suffix):
app_client = EthAppClient(backend)

with pytest.raises(ExceptionRAPDU) as e:
with app_client.get_public_addr(bip32_path=path):
navigator.navigate_and_compare(ROOT_SNAPSHOT_PATH,
navigator.navigate_and_compare(default_screenshot_path,
f"get_pk_rejected_{suffix}",
get_moves(firmware, reject=True))
assert e.value.status == StatusWord.CONDITION_NOT_SATISFIED
Expand All @@ -85,12 +85,13 @@ def test_get_pk_rejected(firmware: Firmware,
def test_get_pk(firmware: Firmware,
backend: BackendInterface,
navigator: Navigator,
default_screenshot_path: Path,
with_chaincode: bool,
chain: Optional[int]):
app_client = EthAppClient(backend)

with app_client.get_public_addr(chaincode=with_chaincode, chain_id=chain):
navigator.navigate_and_compare(ROOT_SNAPSHOT_PATH,
navigator.navigate_and_compare(default_screenshot_path,
f"get_pk_{chain}",
get_moves(firmware, chain=chain))
pk, _, chaincode = ResponseParser.pk_addr(app_client.response().data, with_chaincode)
Expand All @@ -104,12 +105,13 @@ def test_get_pk(firmware: Firmware,
def test_get_eth2_pk(firmware: Firmware,
backend: BackendInterface,
navigator: Navigator,
test_name: str):
test_name: str,
default_screenshot_path: Path):
app_client = EthAppClient(backend)

path="m/12381/3600/0/0"
with app_client.get_eth2_public_addr(bip32_path=path):
navigator.navigate_and_compare(ROOT_SNAPSHOT_PATH,
navigator.navigate_and_compare(default_screenshot_path,
test_name,
get_moves(firmware, pk_eth2=True))

Expand Down
Loading

0 comments on commit c9436ab

Please sign in to comment.