Skip to content

Commit

Permalink
[test] rename TezosAppScreen to TezosNavigator
Browse files Browse the repository at this point in the history
  • Loading branch information
spalmer25 committed Dec 9, 2024
1 parent 0d0cef2 commit 58f80f5
Show file tree
Hide file tree
Showing 27 changed files with 507 additions and 485 deletions.
15 changes: 10 additions & 5 deletions tests/integration/nano/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@

import pytest
from ragger.firmware import Firmware
from ragger.navigator import NanoNavigator

from utils.app import TezosAppScreen, SpeculosTezosBackend, DEFAULT_SEED
from utils.backend import TezosBackend, SpeculosTezosBackend
from utils.navigator import TezosNavigator

FIRMWARES: List[Firmware] = [
Firmware.NANOS,
Expand Down Expand Up @@ -144,6 +146,8 @@ def speculos_args(pytestconfig) -> List[str]:
return []
return speculos_args.split()

DEFAULT_SEED = 'zebra zebra zebra zebra zebra zebra zebra zebra zebra zebra zebra zebra zebra zebra zebra zebra zebra zebra zebra zebra zebra zebra zebra zebra'

@pytest.fixture(scope="function")
def seed(request) -> str:
"""Get `seed` for pytest."""
Expand All @@ -156,7 +160,7 @@ def backend(app_path: Path,
port: int,
display: bool,
seed: str,
speculos_args: List[str]) -> Generator[SpeculosTezosBackend, None, None]:
speculos_args: List[str]) -> Generator[TezosBackend, None, None]:
"""Get `backend` for pytest."""

if display:
Expand All @@ -176,9 +180,10 @@ def backend(app_path: Path,
yield b

@pytest.fixture(scope="function")
def app(backend: SpeculosTezosBackend, golden_run: bool) -> TezosAppScreen:
"""Get `app` for pytest."""
return TezosAppScreen(backend, golden_run)
def tezos_navigator(backend: TezosBackend, golden_run: bool) -> TezosNavigator:
"""Get `navigator` for pytest."""
navigator = NanoNavigator(backend, backend.firmware, golden_run)
return TezosNavigator(backend, navigator)

@pytest.fixture(scope="function")
def snapshot_dir(request) -> Path :
Expand Down
32 changes: 16 additions & 16 deletions tests/integration/nano/test_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,59 +24,59 @@
from ragger.navigator import NavIns, NavInsID

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


def test_home_menu(app: TezosAppScreen, snapshot_dir: Path):
def test_home_menu(tezos_navigator: TezosNavigator, 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(
tezos_navigator.navigate(
instructions=instructions,
snap_path=snapshot_dir,
)


def test_settings_menu(app: TezosAppScreen, snapshot_dir: Path):
def test_settings_menu(tezos_navigator: TezosNavigator, snapshot_dir: Path):
"""Check settings menu flow"""
app.navigate_to_settings()
tezos_navigator.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(
tezos_navigator.navigate(
instructions=instructions,
snap_path=snapshot_dir
)


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


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


def test_quit(app: TezosAppScreen):
def test_quit(backend: TezosBackend):
"""Check quit app"""
# Home
app.backend.left_click()
app.backend.wait_for_screen_change() # Quit
backend.left_click()
backend.wait_for_screen_change() # Quit
try:
app.backend.both_click()
backend.both_click()
assert False, "Must have lost connection with speculos"
except requests.exceptions.ConnectionError:
pass
16 changes: 8 additions & 8 deletions tests/integration/nano/test_public_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import pytest

from utils.account import Account, PublicKey, SigType
from utils.app import Screen, TezosAppScreen, DEFAULT_ACCOUNT
from utils.backend import StatusCode
from utils.backend import TezosBackend, StatusCode
from utils.navigator import TezosNavigator, DEFAULT_ACCOUNT

accounts = [
Account("m/44'/1729'/0'/0'",
Expand All @@ -40,12 +40,12 @@
]

@pytest.mark.parametrize("account", accounts, ids=lambda account: f"{account.sig_type}")
def test_get_pk(app: TezosAppScreen, account: Account):
def test_get_pk(backend: TezosBackend, account: Account):
"""Test that public keys get from the app are correct."""

expected_public_key = account.key.public_key()

data = app.backend.get_public_key(account, with_prompt=False)
data = backend.get_public_key(account, with_prompt=False)

public_key = PublicKey.from_bytes(data, account.sig_type)

Expand All @@ -54,21 +54,21 @@ def test_get_pk(app: TezosAppScreen, account: Account):


@pytest.mark.parametrize("account", accounts, ids=lambda account: f"{account.sig_type}")
def test_provide_pk(app: TezosAppScreen, account: Account, snapshot_dir: Path):
def test_provide_pk(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path):
"""Test that public keys get from the app are correct and correctly displayed."""

expected_public_key = account.key.public_key()

data = app.provide_public_key(account, snap_path=snapshot_dir)
data = tezos_navigator.provide_public_key(account, snap_path=snapshot_dir)

public_key = PublicKey.from_bytes(data, account.sig_type)

assert public_key == expected_public_key.encode(), \
f"Expected public key {expected_public_key} but got {public_key}"


def test_reject_pk(app: TezosAppScreen, snapshot_dir: Path):
def test_reject_pk(tezos_navigator: TezosNavigator, snapshot_dir: Path):
"""Check reject pk behaviour"""

with StatusCode.REJECT.expected():
app.reject_public_key(DEFAULT_ACCOUNT, snap_path=snapshot_dir)
tezos_navigator.reject_public_key(DEFAULT_ACCOUNT, snap_path=snapshot_dir)
15 changes: 9 additions & 6 deletions tests/integration/nano/test_sign/operations/test_sign_ballot.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@

from pathlib import Path

from utils.app import Screen, TezosAppScreen, DEFAULT_ACCOUNT
from utils.message import Ballot
from utils.navigator import TezosNavigator, DEFAULT_ACCOUNT

def test_sign_ballot(app: TezosAppScreen, snapshot_dir: Path):

def test_sign_ballot(tezos_navigator: TezosNavigator, snapshot_dir: Path):
"""Check signing ballot"""

message = Ballot(
Expand All @@ -31,10 +32,12 @@ def test_sign_ballot(app: TezosAppScreen, snapshot_dir: Path):
period = 32
)

data = app.sign(DEFAULT_ACCOUNT,
message,
with_hash=True,
snap_path=snapshot_dir)
data = tezos_navigator.sign(
DEFAULT_ACCOUNT,
message,
with_hash=True,
snap_path=snapshot_dir
)

DEFAULT_ACCOUNT.check_signature(
message=message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,20 @@

from conftest import requires_device

from utils.app import Screen, TezosAppScreen, DEFAULT_ACCOUNT
from utils.message import (
OperationGroup,
Origination,
Transaction,
TransferTicket
)
from utils.navigator import TezosNavigator, DEFAULT_ACCOUNT


@requires_device("nanos")
def test_nanos_regression_batched_ops(app: TezosAppScreen, snapshot_dir: Path):
def test_nanos_regression_batched_ops(tezos_navigator: TezosNavigator, snapshot_dir: Path):
"""Check signing batch operation"""

app.toggle_expert_mode()
tezos_navigator.toggle_expert_mode()

message = OperationGroup([
Transaction(
Expand All @@ -57,21 +58,23 @@ def test_nanos_regression_batched_ops(app: TezosAppScreen, snapshot_dir: Path):
)
])

data = app.sign(DEFAULT_ACCOUNT,
message,
with_hash=True,
snap_path=snapshot_dir)
data = tezos_navigator.sign(
DEFAULT_ACCOUNT,
message,
with_hash=True,
snap_path=snapshot_dir
)

DEFAULT_ACCOUNT.check_signature(
message=message,
with_hash=True,
data=data)

@requires_device("nanox")
def test_nanox_regression_batched_ops(app: TezosAppScreen, snapshot_dir: Path):
def test_nanox_regression_batched_ops(tezos_navigator: TezosNavigator, snapshot_dir: Path):
"""Check signing batch operation"""

app.toggle_expert_mode()
tezos_navigator.toggle_expert_mode()

message = OperationGroup([
Transaction(
Expand All @@ -96,20 +99,22 @@ def test_nanox_regression_batched_ops(app: TezosAppScreen, snapshot_dir: Path):
)
])

data = app.sign(DEFAULT_ACCOUNT,
message,
with_hash=True,
snap_path=snapshot_dir)
data = tezos_navigator.sign(
DEFAULT_ACCOUNT,
message,
with_hash=True,
snap_path=snapshot_dir
)

DEFAULT_ACCOUNT.check_signature(
message=message,
with_hash=True,
data=data)

def test_sign_complex_operation(app: TezosAppScreen, snapshot_dir: Path):
def test_sign_complex_operation(tezos_navigator: TezosNavigator, snapshot_dir: Path):
"""Check signing complex operation"""

app.toggle_expert_mode()
tezos_navigator.toggle_expert_mode()

message = OperationGroup([
Origination(
Expand All @@ -136,10 +141,12 @@ def test_sign_complex_operation(app: TezosAppScreen, snapshot_dir: Path):
)
])

data = app.sign(DEFAULT_ACCOUNT,
message,
with_hash=True,
snap_path=snapshot_dir)
data = tezos_navigator.sign(
DEFAULT_ACCOUNT,
message,
with_hash=True,
snap_path=snapshot_dir
)

DEFAULT_ACCOUNT.check_signature(
message=message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@

from pathlib import Path

from utils.app import Screen, TezosAppScreen, DEFAULT_ACCOUNT
from utils.message import Delegation
from utils.navigator import TezosNavigator, DEFAULT_ACCOUNT

def test_sign_delegation(app: TezosAppScreen, snapshot_dir: Path):

def test_sign_delegation(tezos_navigator: TezosNavigator, snapshot_dir: Path):
"""Check signing delegation"""

message = Delegation(
Expand All @@ -33,10 +34,12 @@ def test_sign_delegation(app: TezosAppScreen, snapshot_dir: Path):
delegate = 'tz1TmFPVZsGQ8MnrBJtnECJgkFUwLa6EWYDm'
)

data = app.sign(DEFAULT_ACCOUNT,
message,
with_hash=True,
snap_path=snapshot_dir)
data = tezos_navigator.sign(
DEFAULT_ACCOUNT,
message,
with_hash=True,
snap_path=snapshot_dir
)

DEFAULT_ACCOUNT.check_signature(
message=message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,21 @@

from pathlib import Path

from utils.app import Screen, TezosAppScreen, DEFAULT_ACCOUNT
from utils.message import FailingNoop
from utils.navigator import TezosNavigator, DEFAULT_ACCOUNT

def test_sign_failing_noop(app: TezosAppScreen, snapshot_dir: Path):

def test_sign_failing_noop(tezos_navigator: TezosNavigator, snapshot_dir: Path):
"""Check signing failing noop"""

message = FailingNoop("9f09f2952d34528c733f94615cfc39bc555619fc550dd4a67ba2208ce8e867aa3d13a6ef99dfbe32c6974aa9a2150d21eca29c3349e59c13b9081f1c11b440ac4d3455dedbe4ee0de15a8af620d4c86247d9d132de1bb6da23d5ff9d8dffda22ba9a84")

data = app.sign(DEFAULT_ACCOUNT,
message,
with_hash=True,
snap_path=snapshot_dir)
data = tezos_navigator.sign(
DEFAULT_ACCOUNT,
message,
with_hash=True,
snap_path=snapshot_dir
)

DEFAULT_ACCOUNT.check_signature(
message=message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@

from pathlib import Path

from utils.app import Screen, TezosAppScreen, DEFAULT_ACCOUNT
from utils.message import IncreasePaidStorage
from utils.navigator import TezosNavigator, DEFAULT_ACCOUNT

def test_sign_increase_paid_storage(app: TezosAppScreen, snapshot_dir: Path):

def test_sign_increase_paid_storage(tezos_navigator: TezosNavigator, snapshot_dir: Path):
"""Check signing increase paid storage"""

message = IncreasePaidStorage(
Expand All @@ -34,10 +35,12 @@ def test_sign_increase_paid_storage(app: TezosAppScreen, snapshot_dir: Path):
destination = "KT18amZmM5W7qDWVt2pH6uj7sCEd3kbzLrHT"
)

data = app.sign(DEFAULT_ACCOUNT,
message,
with_hash=True,
snap_path=snapshot_dir)
data = tezos_navigator.sign(
DEFAULT_ACCOUNT,
message,
with_hash=True,
snap_path=snapshot_dir
)

DEFAULT_ACCOUNT.check_signature(
message=message,
Expand Down
Loading

0 comments on commit 58f80f5

Please sign in to comment.