Skip to content

Commit

Permalink
[test] add the missing tests specific to touch devices
Browse files Browse the repository at this point in the history
  • Loading branch information
spalmer25 committed Jan 21, 2025
1 parent 6d4afe4 commit 53f3147
Show file tree
Hide file tree
Showing 125 changed files with 264 additions and 3 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.
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.
13 changes: 13 additions & 0 deletions tests/integration/nano/test_public_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ def test_provide_pk(
f"Expected public key {expected_public_key} but got {public_key}"


@pytest.mark.use_on_device("touch")
def test_show_qr(
backend: TezosBackend,
tezos_navigator: TezosNavigator,
account: Account,
snapshot_dir: Path
):
"""Test QR code flow."""

with backend.prompt_public_key(account):
tezos_navigator.accept_public_key(show_qr=True, snap_path=snapshot_dir)


def test_reject_pk(
backend: TezosBackend,
tezos_navigator: TezosNavigator,
Expand Down
53 changes: 52 additions & 1 deletion tests/integration/nano/test_sign/test_apdu_sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@

import pytest

from ragger.navigator import NavInsID

from utils.account import Account
from utils.backend import StatusCode, TezosBackend
from utils.message import Transaction
from utils.navigator import TezosNavigator
from utils.navigator import TezosNavigator, TezosNavInsID


@pytest.mark.parametrize("with_hash", [True, False])
Expand Down Expand Up @@ -60,6 +62,55 @@ def test_reject_operation(
with backend.sign(account, message, with_hash=True):
tezos_navigator.reject_sign(snap_path=snapshot_dir)

@pytest.mark.use_on_device("touch")
def test_reject_operation_at_start(
backend: TezosBackend,
tezos_navigator: TezosNavigator,
account: Account,
snapshot_dir: Path
):
"""Check reject at first screen."""

message = Transaction()

with StatusCode.REJECT.expected():
with backend.sign(account, message):
tezos_navigator.navigate(
instructions=[
NavInsID.USE_CASE_REVIEW_REJECT,
TezosNavInsID.REJECT_CHOICE_CONFIRM,
NavInsID.USE_CASE_STATUS_DISMISS,
],
screen_change_before_first_instruction=True,
screen_change_after_last_instruction=False,
snap_path=snapshot_dir
)

@pytest.mark.use_on_device("touch")
def test_reject_operation_at_fields(
backend: TezosBackend,
tezos_navigator: TezosNavigator,
account: Account,
snapshot_dir: Path
):
"""Check reject at fields."""

message = Transaction()

with StatusCode.REJECT.expected():
with backend.sign(account, message):
tezos_navigator.navigate(
instructions=[
NavInsID.USE_CASE_REVIEW_TAP,
NavInsID.USE_CASE_REVIEW_REJECT,
TezosNavInsID.REJECT_CHOICE_CONFIRM,
NavInsID.USE_CASE_STATUS_DISMISS,
],
screen_change_before_first_instruction=True,
screen_change_after_last_instruction=False,
snap_path=snapshot_dir
)

def test_sign_with_small_packet(
backend: TezosBackend,
tezos_navigator: TezosNavigator,
Expand Down
42 changes: 42 additions & 0 deletions tests/integration/nano/test_sign/test_blindsign.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
from pathlib import Path
from typing import List, Union

import pytest

from ragger.firmware import Firmware
from ragger.navigator import NavIns, NavInsID

Expand Down Expand Up @@ -176,6 +178,28 @@ def test_reject_basic_too_long_operation_at_summary(
tezos_navigator.accept_sign_blindsign_risk(snap_path=snapshot_dir / "blindsign_warning")
tezos_navigator.reject_sign(snap_path=snapshot_dir / "summary")

@pytest.mark.use_on_device("touch")
def test_reject_at_skip(
backend: TezosBackend,
tezos_navigator: TezosNavigator,
account: Account,
snapshot_dir: Path
):
"""Check reject at skip."""

tezos_navigator.toggle_expert_mode()
tezos_navigator.toggle_blindsign()

with backend.sign(account, BASIC_OPERATION):
tezos_navigator.skip_reject(
snap_path=snapshot_dir,
screen_change_after_last_instruction=True,
)
# Just to end the flow
tezos_navigator.accept_sign(
screen_change_before_first_instruction=False,
)


### Different kind of too long operation ###

Expand Down Expand Up @@ -442,6 +466,24 @@ def test_reject_too_long_operation_with_too_large_at_blindsigning(
tezos_navigator.accept_sign_blindsign_risk(snap_path=snapshot_dir / "blindsigning_warning")
tezos_navigator.reject_sign(snap_path=snapshot_dir / "blindsigning")

@pytest.mark.use_on_device("touch")
def test_reject_too_long_operation_with_too_large_at_blindsigning_warning(
backend: TezosBackend,
tezos_navigator: TezosNavigator,
account: Account,
snapshot_dir: Path
):
"""Check reject too long operation that will also fail the parsing at blindsigning"""

tezos_navigator.toggle_expert_mode()
tezos_navigator.toggle_blindsign()

with StatusCode.PARSE_ERROR.expected():
with backend.sign(account, OPERATION_WITH_TOO_LARGE):
tezos_navigator.skip_sign(snap_path=snapshot_dir / "skip")
tezos_navigator.accept_sign_error_risk(snap_path=snapshot_dir / "too_large_warning")
tezos_navigator.refuse_sign_blindsign_risk(snap_path=snapshot_dir / "blindsigning_warning")

def test_blindsign_too_deep(
backend: TezosBackend,
firmware: Firmware,
Expand Down
114 changes: 114 additions & 0 deletions tests/integration/nano/test_sign/test_expert_mode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#!/usr/bin/env python3
# Copyright 2024 Functori <[email protected]>
# Copyright 2024 Trilitech <[email protected]>

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Gathering of tests related to Sign instructions."""

from pathlib import Path

import pytest

from ragger.navigator import NavInsID

from utils.account import Account
from utils.backend import StatusCode, TezosBackend
from utils.message import Default, RegisterGlobalConstant
from utils.navigator import TezosNavigator, TezosNavInsID


EXPERT_OPERATION = RegisterGlobalConstant(
{"prim": "constant", 'args': [{"string": Default.SCRIPT_EXPR_HASH}]}
)


def test_reject_expert_mode(
backend: TezosBackend,
tezos_navigator: TezosNavigator,
account: Account,
snapshot_dir: Path
):
"""Check expert mode reject."""

with StatusCode.REJECT.expected():
with backend.sign(account, EXPERT_OPERATION):
tezos_navigator.expert_reject_sign(snap_path=snapshot_dir)


@pytest.mark.use_on_device("touch")
def test_enable_expert_mode_in_review(
backend: TezosBackend,
tezos_navigator: TezosNavigator,
account: Account,
snapshot_dir: Path
):
"""Check that expert mode can be activated from review on touch devices."""

with backend.sign(account, EXPERT_OPERATION):
tezos_navigator.expert_accept_sign(snap_path=snapshot_dir / "review_expert")
tezos_navigator.accept_sign(snap_path=snapshot_dir / "review")

# To ensure that expert mode is ON
tezos_navigator.navigate_to_settings(
screen_change_before_first_instruction=True,
snap_path=snapshot_dir / "check"
)


@pytest.mark.use_on_device("touch")
def test_reject_sign_at_expert_mode_after_enabling(
backend: TezosBackend,
tezos_navigator: TezosNavigator,
account: Account,
snapshot_dir: Path
):
"""Check reject at expert splash screen after enabling expert mode"""

with StatusCode.REJECT.expected():
with backend.sign(account, EXPERT_OPERATION):
tezos_navigator.expert_accept_sign(
screen_change_after_last_instruction=False
)
tezos_navigator.navigate(
instructions=[
NavInsID.USE_CASE_REVIEW_REJECT,
TezosNavInsID.REJECT_CHOICE_CONFIRM,
NavInsID.USE_CASE_STATUS_DISMISS,
],
screen_change_before_first_instruction=True,
snap_path=snapshot_dir
)


@pytest.mark.use_on_device("touch")
def test_reject_sign_at_expert_mode_when_enabled(
backend: TezosBackend,
tezos_navigator: TezosNavigator,
account: Account,
snapshot_dir: Path
):
"""Check reject at expert splash screen if expert mode already enabled"""

tezos_navigator.toggle_expert_mode()

with StatusCode.REJECT.expected():
with backend.sign(account, EXPERT_OPERATION):
tezos_navigator.expert_splash_navigate(
validation_instructions=[
NavInsID.USE_CASE_REVIEW_REJECT,
TezosNavInsID.REJECT_CHOICE_CONFIRM,
NavInsID.USE_CASE_STATUS_DISMISS,
],
snap_path=snapshot_dir
)
45 changes: 43 additions & 2 deletions tests/integration/nano/utils/navigator.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,15 +436,20 @@ def _navigate_review(
**kwargs
)

def accept_public_key(self, **kwargs) -> None:
def accept_public_key(self, show_qr: bool = False, **kwargs) -> None:
"""Navigate through public key flow and accept public key"""
validation_instructions: List[Union[NavIns, BaseNavInsID]] = []
if self._firmware.is_nano:
text = "^Approve$"
validation_instructions = [NavInsID.BOTH_CLICK]
else:
text = "^Confirm$"
validation_instructions = [
if show_qr:
validation_instructions += [
TezosNavInsID.REVIEW_PK_SHOW_QR,
NavInsID.USE_CASE_ADDRESS_CONFIRMATION_EXIT_QR,
]
validation_instructions += [
NavInsID.USE_CASE_ADDRESS_CONFIRMATION_CONFIRM,
NavInsID.USE_CASE_STATUS_DISMISS,
]
Expand Down Expand Up @@ -524,6 +529,20 @@ def hard_reject_sign(self, **kwargs) -> None:
**kwargs
)

def expert_accept_sign(self, **kwargs) -> None:
"""Navigate through the signing expert requirement flow and accept.
Only available for Touch devices, fail otherwise.
"""
assert not self._firmware.is_nano, "Skip available only on Touch devices"
self._navigate_review(
text="^Enable expert mode$",
validation_instructions=[
TezosNavInsID.EXPERT_CHOICE_ENABLE,
NavInsID.USE_CASE_STATUS_DISMISS,
],
**kwargs
)

def expert_reject_sign(self, **kwargs) -> None:
"""Navigate through the signing expert requirement flow and reject."""
validation_instructions: List[Union[NavIns, BaseNavInsID]] = []
Expand All @@ -543,6 +562,14 @@ def expert_reject_sign(self, **kwargs) -> None:
**kwargs
)

def expert_splash_navigate(self, **kwargs) -> None:
"""Navigate until the expert mode splash screen."""
if self._firmware.is_nano:
text = "^Next field requires$"
else:
text = "^Expert mode$"
self._navigate_review(text=text, **kwargs)

def accept_sign_error_risk(self, **kwargs) -> None:
"""Navigate through signing risk warning flow and accept risk."""
validation_instructions: List[Union[NavIns, BaseNavInsID]] = []
Expand Down Expand Up @@ -626,3 +653,17 @@ def skip_sign(self, **kwargs) -> None:
],
**kwargs
)

def skip_reject(self, **kwargs) -> None:
"""Tap on the Skip button and reject to skip.
Only available for Touch devices, fail otherwise.
"""
assert not self._firmware.is_nano, "Skip available only on Touch devices"
self._navigate_review(
text="Skip",
validation_instructions=[
TezosNavInsID.REVIEW_TX_SKIP,
TezosNavInsID.SKIP_CHOICE_REJECT,
],
**kwargs
)

0 comments on commit 53f3147

Please sign in to comment.