Skip to content

Commit

Permalink
[test] use navigator instead of assert_screen
Browse files Browse the repository at this point in the history
  • Loading branch information
spalmer25 committed Dec 9, 2024
1 parent c78bbe7 commit 0d0cef2
Show file tree
Hide file tree
Showing 128 changed files with 206 additions and 163 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
127 changes: 63 additions & 64 deletions tests/integration/nano/test_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,68 +16,67 @@

"""Gathering of tests related to app menu."""

from utils.app import Screen, TezosAppScreen

def test_menu(app: TezosAppScreen):
"""Check main menu flow"""
app.assert_screen(Screen.HOME)
app.backend.right_click()
app.assert_screen(Screen.VERSION)
app.backend.both_click()
app.assert_screen(Screen.VERSION)
app.backend.right_click()
app.assert_screen(Screen.SETTINGS)
app.backend.right_click()
app.assert_screen(Screen.QUIT)
app.backend.left_click()
app.assert_screen(Screen.SETTINGS)
app.backend.left_click()
app.assert_screen(Screen.VERSION)
app.backend.left_click()
app.assert_screen(Screen.HOME)
app.backend.both_click()
app.assert_screen(Screen.HOME)
app.backend.left_click()
app.assert_screen(Screen.QUIT)
app.backend.right_click()
app.assert_screen(Screen.HOME)
app.backend.right_click()
app.assert_screen(Screen.VERSION)
app.backend.right_click()
app.assert_screen(Screen.SETTINGS)
app.backend.right_click()
app.assert_screen(Screen.QUIT)
app.backend.right_click()
app.assert_screen(Screen.HOME)
app.backend.right_click()
app.assert_screen(Screen.VERSION)

# Check Settings menu operation
app.backend.right_click()
app.assert_screen(Screen.SETTINGS)
app.backend.both_click()
app.assert_screen(Screen.SETTINGS_EXPERT_MODE_DISABLED)
app.backend.both_click()
app.assert_screen(Screen.SETTINGS_EXPERT_MODE_ENABLED)
app.backend.right_click()
app.assert_screen(Screen.SETTINGS_BLINDSIGN_OFF)
app.backend.both_click()
app.assert_screen(Screen.SETTINGS_BLINDSIGN_ON)
app.backend.both_click()
app.assert_screen(Screen.SETTINGS_BLINDSIGN_OFF)
app.backend.right_click()
app.assert_screen(Screen.SETTINGS_BACK)
app.backend.left_click()
app.assert_screen(Screen.SETTINGS_BLINDSIGN_OFF)
app.backend.left_click()
app.assert_screen(Screen.SETTINGS_EXPERT_MODE_ENABLED)
app.backend.left_click()
app.assert_screen(Screen.SETTINGS_BACK)
app.backend.right_click()
app.assert_screen(Screen.SETTINGS_EXPERT_MODE_ENABLED)
app.backend.left_click()
app.assert_screen(Screen.SETTINGS_BACK)
app.backend.both_click()
app.assert_screen(Screen.HOME)
from pathlib import Path
from typing import List, Union

import requests

from ragger.navigator import NavIns, NavInsID

from utils.backend import TezosBackend
from utils.app import TezosAppScreen


def test_home_menu(app: TezosAppScreen, snapshot_dir: Path):
"""Check home menu flow"""
instructions: List[Union[NavIns, NavInsID]] = [
# Home
NavInsID.RIGHT_CLICK, # Version
NavInsID.RIGHT_CLICK, # Settings
NavInsID.RIGHT_CLICK, # Quit
]
app.navigate(
instructions=instructions,
snap_path=snapshot_dir,
)


def test_settings_menu(app: TezosAppScreen, snapshot_dir: Path):
"""Check settings menu flow"""
app.navigate_to_settings()
instructions: List[Union[NavIns, NavInsID]] = [
# Expert Mode
NavInsID.RIGHT_CLICK, # Blind Sign
NavInsID.RIGHT_CLICK, # Back
NavInsID.BOTH_CLICK, # Home
]
app.navigate(
instructions=instructions,
snap_path=snapshot_dir
)


def test_toggle_expert_mode(app: TezosAppScreen, snapshot_dir: Path):
"""Check settings' expert_mode toggle"""
snap_idx = app.toggle_expert_mode(snap_path=snapshot_dir)
# Toggle back
app.toggle_expert_mode(snap_start_idx=snap_idx, snap_path=snapshot_dir)


def test_toggle_blindsign(app: TezosAppScreen, snapshot_dir: Path):
"""Check settings' blindsign toggle"""
snap_idx = app.toggle_blindsign(snap_path=snapshot_dir)
# Toggle back
app.toggle_blindsign(snap_start_idx=snap_idx, snap_path=snapshot_dir)


def test_quit(app: TezosAppScreen):
"""Check quit app"""
# Home
app.backend.left_click()
app._quit()
app.backend.wait_for_screen_change() # Quit
try:
app.backend.both_click()
assert False, "Must have lost connection with speculos"
except requests.exceptions.ConnectionError:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
def test_nanos_regression_batched_ops(app: TezosAppScreen, snapshot_dir: Path):
"""Check signing batch operation"""

app.setup_expert_mode()
app.toggle_expert_mode()

message = OperationGroup([
Transaction(
Expand Down Expand Up @@ -71,7 +71,7 @@ def test_nanos_regression_batched_ops(app: TezosAppScreen, snapshot_dir: Path):
def test_nanox_regression_batched_ops(app: TezosAppScreen, snapshot_dir: Path):
"""Check signing batch operation"""

app.setup_expert_mode()
app.toggle_expert_mode()

message = OperationGroup([
Transaction(
Expand Down Expand Up @@ -109,7 +109,7 @@ def test_nanox_regression_batched_ops(app: TezosAppScreen, snapshot_dir: Path):
def test_sign_complex_operation(app: TezosAppScreen, snapshot_dir: Path):
"""Check signing complex operation"""

app.setup_expert_mode()
app.toggle_expert_mode()

message = OperationGroup([
Origination(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
def test_sign_origination(app: TezosAppScreen, snapshot_dir: Path):
"""Check signing origination"""

app.setup_expert_mode()
app.toggle_expert_mode()

message = Origination(
source = 'tz1ixvCiPJYyMjsp2nKBVaq54f6AdbV8hCKa',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
def test_sign_register_global_constant(app: TezosAppScreen, snapshot_dir: Path):
"""Check signing register global constant"""

app.setup_expert_mode()
app.toggle_expert_mode()

message = RegisterGlobalConstant(
source = 'tz1ixvCiPJYyMjsp2nKBVaq54f6AdbV8hCKa',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
def test_sign_sc_rollup_execute_outbox_message(app: TezosAppScreen, snapshot_dir: Path):
"""Check signing smart rollup execute outbox message"""

app.setup_expert_mode()
app.toggle_expert_mode()

message = ScRollupExecuteOutboxMessage(
source = 'tz1ixvCiPJYyMjsp2nKBVaq54f6AdbV8hCKa',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
def test_sign_sc_rollup_originate(app: TezosAppScreen, whitelist: Optional[List[str]], snapshot_dir: Path):
"""Check signing smart rollup originate"""

app.setup_expert_mode()
app.toggle_expert_mode()

message = ScRollupOriginate(
source = 'tz1ixvCiPJYyMjsp2nKBVaq54f6AdbV8hCKa',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
def test_sign_transaction(app: TezosAppScreen, snapshot_dir: Path):
"""Check signing transaction"""

app.setup_expert_mode()
app.toggle_expert_mode()

message = Transaction(
source = 'tz2JPgTWZZpxZZLqHMfS69UAy1UHm4Aw5iHu',
Expand All @@ -52,7 +52,7 @@ def test_sign_transaction(app: TezosAppScreen, snapshot_dir: Path):
def test_reject_transaction(app: TezosAppScreen, snapshot_dir: Path):
"""Check reject transaction"""

app.setup_expert_mode()
app.toggle_expert_mode()

message = Transaction(
source = 'tz1ixvCiPJYyMjsp2nKBVaq54f6AdbV8hCKa',
Expand All @@ -75,7 +75,7 @@ def test_reject_transaction(app: TezosAppScreen, snapshot_dir: Path):
def test_sign_simple_transaction(app: TezosAppScreen, snapshot_dir: Path):
"""Check sign not complex transaction"""

app.setup_expert_mode()
app.toggle_expert_mode()

message = Transaction(
source = 'tz1ixvCiPJYyMjsp2nKBVaq54f6AdbV8hCKa',
Expand Down Expand Up @@ -123,7 +123,7 @@ def test_too_complex_transaction(app: TezosAppScreen, snapshot_dir: Path):
def test_sign_stake_transaction(app: TezosAppScreen, snapshot_dir: Path):
"""Check sign stake"""

app.setup_expert_mode()
app.toggle_expert_mode()

message = Transaction(
source = 'tz2WmivuMG8MMRKMEmzKRMMxMApxZQWYNS4W',
Expand All @@ -149,7 +149,7 @@ def test_sign_stake_transaction(app: TezosAppScreen, snapshot_dir: Path):
def test_sign_unstake_transaction(app: TezosAppScreen, snapshot_dir: Path):
"""Check sign unstake"""

app.setup_expert_mode()
app.toggle_expert_mode()

message = Transaction(
source = 'tz2WmivuMG8MMRKMEmzKRMMxMApxZQWYNS4W',
Expand All @@ -175,7 +175,7 @@ def test_sign_unstake_transaction(app: TezosAppScreen, snapshot_dir: Path):
def test_sign_finalize_unstake_transaction(app: TezosAppScreen, snapshot_dir: Path):
"""Check sign finalize_unstake"""

app.setup_expert_mode()
app.toggle_expert_mode()

message = Transaction(
source = 'tz2WmivuMG8MMRKMEmzKRMMxMApxZQWYNS4W',
Expand All @@ -201,7 +201,7 @@ def test_sign_finalize_unstake_transaction(app: TezosAppScreen, snapshot_dir: Pa
def test_sign_set_delegate_parameters_transaction(app: TezosAppScreen, snapshot_dir: Path):
"""Check sign set delegate parameters"""

app.setup_expert_mode()
app.toggle_expert_mode()

message = Transaction(
source = 'tz2WmivuMG8MMRKMEmzKRMMxMApxZQWYNS4W',
Expand Down Expand Up @@ -236,7 +236,7 @@ def test_sign_set_delegate_parameters_transaction(app: TezosAppScreen, snapshot_
def test_sign_with_long_hash(app: TezosAppScreen, snapshot_dir: Path):
"""Check signing transaction with a long destination hash"""

app.setup_expert_mode()
app.toggle_expert_mode()

message = Transaction(
source = 'tz1ixvCiPJYyMjsp2nKBVaq54f6AdbV8hCKa',
Expand All @@ -263,7 +263,7 @@ def test_sign_with_long_hash(app: TezosAppScreen, snapshot_dir: Path):
def test_ensure_always_clearsign(app: TezosAppScreen, snapshot_dir: Path):
"""Check clear signing never blindsign"""

app.setup_expert_mode()
app.toggle_expert_mode()

message = Transaction(
source = 'tz1ixvCiPJYyMjsp2nKBVaq54f6AdbV8hCKa',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
def test_sign_transfer_ticket(app: TezosAppScreen, snapshot_dir: Path):
"""Check signing transfer ticket"""

app.setup_expert_mode()
app.toggle_expert_mode()

message = TransferTicket(
source = 'tz1ixvCiPJYyMjsp2nKBVaq54f6AdbV8hCKa',
Expand Down Expand Up @@ -54,7 +54,7 @@ def test_sign_transfer_ticket(app: TezosAppScreen, snapshot_dir: Path):
def test_nanosp_regression_potential_empty_screen(app: TezosAppScreen, snapshot_dir: Path):
"""Check signing operation that display potentially empty screens"""

app.setup_expert_mode()
app.toggle_expert_mode()

message = TransferTicket(
source = 'tz1ixvCiPJYyMjsp2nKBVaq54f6AdbV8hCKa',
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/nano/test_sign/test_apdu_sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_sign_micheline_without_hash(app: TezosAppScreen, snapshot_dir: Path):
def test_sign_with_small_packet(app: TezosAppScreen, snapshot_dir: Path):
"""Check signing using small packet instead of full size packets"""

app.setup_expert_mode()
app.toggle_expert_mode()

def check_sign_with_small_packet(
account: Account,
Expand Down
45 changes: 24 additions & 21 deletions tests/integration/nano/test_sign/test_blindsign.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@

from multiprocessing import Process, Queue
from pathlib import Path
from typing import Callable
from typing import Callable, List, Union

from utils.app import Screen, ScreenText, TezosAppScreen, send_and_navigate, DEFAULT_ACCOUNT
from ragger.navigator import NavIns, NavInsID

from utils.app import ScreenText, TezosAppScreen, DEFAULT_ACCOUNT
from utils.backend import StatusCode
from utils.message import (
Message,
Expand All @@ -39,8 +41,8 @@ def _sign_too_long(app: TezosAppScreen,
message: Message,
navigate: Callable[[], None]):

app.setup_expert_mode()
app.setup_blindsign_on()
app.toggle_expert_mode()
app.toggle_blindsign()

data = app.sign(
DEFAULT_ACCOUNT,
Expand Down Expand Up @@ -71,8 +73,8 @@ def _reject_too_long(
navigate: Callable[[], None]):
"""Reject a too long message"""

app.setup_expert_mode()
app.setup_blindsign_on()
app.toggle_expert_mode()
app.toggle_blindsign()

with status_code.expected():
app.sign(
Expand Down Expand Up @@ -354,22 +356,23 @@ def navigate() -> None:
if app.backend.firmware.device == "nanos":
### Simulate `navigate_review` up to `ACCEPT_RISK` because the nanos screen can look like it hasn't changed.

def assert_screen_i(i):
app.assert_screen(f"{str(i).zfill(5)}", snapshot_dir / "clear")

app.backend.wait_for_text_not_on_screen(ScreenText.HOME)
for i in range(6):
instructions: List[Union[NavIns, NavInsID]] = [
# 'Review operation'
# 'Expression {{{...{{{'
# 'Expression {{{...{{{'
# 'The transaction cannot be trusted.'
# 'Parsing error ERR_TOO_DEEP'
# 'Learn More: bit.ly/ledger-tez'
assert_screen_i(i)
app.backend.right_click()
# 'Accept risk' screen
assert_screen_i(i+1)
app.backend.both_click()
NavInsID.RIGHT_CLICK, # 'Expression {{{...{{{'
NavInsID.RIGHT_CLICK, # 'Expression {{{...{{{'
NavInsID.RIGHT_CLICK, # 'The transaction cannot be trusted.'
NavInsID.RIGHT_CLICK, # 'Parsing error ERR_TOO_DEEP'
NavInsID.RIGHT_CLICK, # 'Learn More: bit.ly/ledger-tez'
NavInsID.RIGHT_CLICK, # 'Accept risk'
NavInsID.BOTH_CLICK,
]

app.unsafe_navigate(
instructions=instructions,
screen_change_before_first_instruction=True,
screen_change_after_last_instruction=False,
snap_path=snapshot_dir / "clear",
)
else:
app.navigate_review(text=ScreenText.ACCEPT_RISK, snap_path=snapshot_dir / "clear")

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/nano/test_sign/test_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def test_sign_micheline_basic(app: TezosAppScreen, account: Account, snapshot_di
def test_sign_with_another_seed(app: TezosAppScreen, snapshot_dir: Path):
"""Check signing using another seed than [zebra*24]"""

app.setup_expert_mode()
app.toggle_expert_mode()

account = Account("m/44'/1729'/0'/0'",
SigType.ED25519,
Expand Down
Loading

0 comments on commit 0d0cef2

Please sign in to comment.