From eedfef19fa46ec5fe76cd173727ce0d933e571ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Palmer?= Date: Mon, 9 Dec 2024 09:32:17 +0100 Subject: [PATCH] [test] rename TezosAppScreen to TezosNavigator - move functions and value not related to navigator out of `navigator.py` --- tests/integration/nano/conftest.py | 13 +- tests/integration/nano/test_menu.py | 32 ++--- tests/integration/nano/test_public_key.py | 16 +-- .../test_sign/operations/test_sign_ballot.py | 15 +- .../test_sign_batched_operations.py | 45 +++--- .../operations/test_sign_delegation.py | 15 +- .../operations/test_sign_failing_noop.py | 15 +- .../test_sign_increase_paid_storage.py | 15 +- .../operations/test_sign_origination.py | 17 ++- .../operations/test_sign_proposals.py | 15 +- .../test_sign_register_global_constant.py | 17 ++- .../test_sign/operations/test_sign_reveal.py | 15 +- .../test_sign_sc_rollup_add_messages.py | 15 +- ...t_sign_sc_rollup_execute_outbox_message.py | 17 ++- .../test_sign_sc_rollup_originate.py | 16 ++- .../operations/test_sign_set_consensus_key.py | 15 +- .../operations/test_sign_set_deposit_limit.py | 15 +- .../operations/test_sign_transaction.py | 135 ++++++++++-------- .../operations/test_sign_transfer_ticket.py | 31 ++-- .../nano/test_sign/test_apdu_sign.py | 40 ++++-- .../nano/test_sign/test_blindsign.py | 116 ++++++++------- tests/integration/nano/test_sign/test_key.py | 29 ++-- .../nano/test_sign/test_parsing_errors.py | 17 +-- tests/integration/nano/test_version.py | 11 +- tests/integration/nano/test_wrong_apdu.py | 125 ++++++++-------- tests/integration/nano/utils/backend.py | 43 ++++++ .../nano/utils/{app.py => navigator.py} | 92 +++--------- 27 files changed, 523 insertions(+), 424 deletions(-) rename tests/integration/nano/utils/{app.py => navigator.py} (77%) diff --git a/tests/integration/nano/conftest.py b/tests/integration/nano/conftest.py index 1268f3d3e..2e6248bd1 100644 --- a/tests/integration/nano/conftest.py +++ b/tests/integration/nano/conftest.py @@ -21,9 +21,11 @@ import pytest from ragger.firmware import Firmware +from ragger.navigator import NanoNavigator from utils.account import Account, DEFAULT_ACCOUNT, DEFAULT_SEED -from utils.app import TezosAppScreen, SpeculosTezosBackend +from utils.backend import TezosBackend, SpeculosTezosBackend +from utils.navigator import TezosNavigator FIRMWARES: List[Firmware] = [ Firmware.NANOS, @@ -163,7 +165,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: @@ -183,9 +185,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 : diff --git a/tests/integration/nano/test_menu.py b/tests/integration/nano/test_menu.py index 97ceb37bd..d29e0ca65 100755 --- a/tests/integration/nano/test_menu.py +++ b/tests/integration/nano/test_menu.py @@ -24,10 +24,10 @@ 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 @@ -35,48 +35,48 @@ def test_home_menu(app: TezosAppScreen, snapshot_dir: Path): 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 diff --git a/tests/integration/nano/test_public_key.py b/tests/integration/nano/test_public_key.py index 2484e75a5..59215aa48 100644 --- a/tests/integration/nano/test_public_key.py +++ b/tests/integration/nano/test_public_key.py @@ -21,8 +21,8 @@ import pytest from utils.account import Account, PublicKey, SigType -from utils.app import TezosAppScreen -from utils.backend import StatusCode +from utils.backend import TezosBackend, StatusCode +from utils.navigator import TezosNavigator accounts = [ Account("m/44'/1729'/0'/0'", @@ -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) @@ -54,12 +54,12 @@ 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) @@ -67,8 +67,8 @@ def test_provide_pk(app: TezosAppScreen, account: Account, snapshot_dir: Path): f"Expected public key {expected_public_key} but got {public_key}" -def test_reject_pk(app: TezosAppScreen, account: Account, snapshot_dir: Path): +def test_reject_pk(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path): """Check reject pk behaviour""" with StatusCode.REJECT.expected(): - app.reject_public_key(account, snap_path=snapshot_dir) + tezos_navigator.reject_public_key(account, snap_path=snapshot_dir) diff --git a/tests/integration/nano/test_sign/operations/test_sign_ballot.py b/tests/integration/nano/test_sign/operations/test_sign_ballot.py index 39835e16d..3ddeafb65 100755 --- a/tests/integration/nano/test_sign/operations/test_sign_ballot.py +++ b/tests/integration/nano/test_sign/operations/test_sign_ballot.py @@ -19,10 +19,11 @@ from pathlib import Path from utils.account import Account -from utils.app import TezosAppScreen from utils.message import Ballot +from utils.navigator import TezosNavigator -def test_sign_ballot(app: TezosAppScreen, account: Account, snapshot_dir: Path): + +def test_sign_ballot(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path): """Check signing ballot""" message = Ballot( @@ -32,10 +33,12 @@ def test_sign_ballot(app: TezosAppScreen, account: Account, snapshot_dir: Path): period = 32 ) - data = app.sign(account, - message, - with_hash=True, - snap_path=snapshot_dir) + data = tezos_navigator.sign( + account, + message, + with_hash=True, + snap_path=snapshot_dir + ) account.check_signature( message=message, diff --git a/tests/integration/nano/test_sign/operations/test_sign_batched_operations.py b/tests/integration/nano/test_sign/operations/test_sign_batched_operations.py index 6875f8296..f3665a36a 100644 --- a/tests/integration/nano/test_sign/operations/test_sign_batched_operations.py +++ b/tests/integration/nano/test_sign/operations/test_sign_batched_operations.py @@ -21,19 +21,20 @@ from conftest import requires_device from utils.account import Account -from utils.app import TezosAppScreen from utils.message import ( OperationGroup, Origination, Transaction, TransferTicket ) +from utils.navigator import TezosNavigator + @requires_device("nanos") -def test_nanos_regression_batched_ops(app: TezosAppScreen, account: Account, snapshot_dir: Path): +def test_nanos_regression_batched_ops(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path): """Check signing batch operation""" - app.toggle_expert_mode() + tezos_navigator.toggle_expert_mode() message = OperationGroup([ Transaction( @@ -58,10 +59,12 @@ def test_nanos_regression_batched_ops(app: TezosAppScreen, account: Account, sna ) ]) - data = app.sign(account, - message, - with_hash=True, - snap_path=snapshot_dir) + data = tezos_navigator.sign( + account, + message, + with_hash=True, + snap_path=snapshot_dir + ) account.check_signature( message=message, @@ -69,10 +72,10 @@ def test_nanos_regression_batched_ops(app: TezosAppScreen, account: Account, sna data=data) @requires_device("nanox") -def test_nanox_regression_batched_ops(app: TezosAppScreen, account: Account, snapshot_dir: Path): +def test_nanox_regression_batched_ops(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path): """Check signing batch operation""" - app.toggle_expert_mode() + tezos_navigator.toggle_expert_mode() message = OperationGroup([ Transaction( @@ -97,20 +100,22 @@ def test_nanox_regression_batched_ops(app: TezosAppScreen, account: Account, sna ) ]) - data = app.sign(account, - message, - with_hash=True, - snap_path=snapshot_dir) + data = tezos_navigator.sign( + account, + message, + with_hash=True, + snap_path=snapshot_dir + ) account.check_signature( message=message, with_hash=True, data=data) -def test_sign_complex_operation(app: TezosAppScreen, account: Account, snapshot_dir: Path): +def test_sign_complex_operation(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path): """Check signing complex operation""" - app.toggle_expert_mode() + tezos_navigator.toggle_expert_mode() message = OperationGroup([ Origination( @@ -137,10 +142,12 @@ def test_sign_complex_operation(app: TezosAppScreen, account: Account, snapshot_ ) ]) - data = app.sign(account, - message, - with_hash=True, - snap_path=snapshot_dir) + data = tezos_navigator.sign( + account, + message, + with_hash=True, + snap_path=snapshot_dir + ) account.check_signature( message=message, diff --git a/tests/integration/nano/test_sign/operations/test_sign_delegation.py b/tests/integration/nano/test_sign/operations/test_sign_delegation.py index b777d0c5f..c91749d6e 100755 --- a/tests/integration/nano/test_sign/operations/test_sign_delegation.py +++ b/tests/integration/nano/test_sign/operations/test_sign_delegation.py @@ -19,10 +19,11 @@ from pathlib import Path from utils.account import Account -from utils.app import TezosAppScreen from utils.message import Delegation +from utils.navigator import TezosNavigator -def test_sign_delegation(app: TezosAppScreen, account: Account, snapshot_dir: Path): + +def test_sign_delegation(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path): """Check signing delegation""" message = Delegation( @@ -34,10 +35,12 @@ def test_sign_delegation(app: TezosAppScreen, account: Account, snapshot_dir: Pa delegate = 'tz1TmFPVZsGQ8MnrBJtnECJgkFUwLa6EWYDm' ) - data = app.sign(account, - message, - with_hash=True, - snap_path=snapshot_dir) + data = tezos_navigator.sign( + account, + message, + with_hash=True, + snap_path=snapshot_dir + ) account.check_signature( message=message, diff --git a/tests/integration/nano/test_sign/operations/test_sign_failing_noop.py b/tests/integration/nano/test_sign/operations/test_sign_failing_noop.py index f1983ef53..86b358050 100755 --- a/tests/integration/nano/test_sign/operations/test_sign_failing_noop.py +++ b/tests/integration/nano/test_sign/operations/test_sign_failing_noop.py @@ -19,18 +19,21 @@ from pathlib import Path from utils.account import Account -from utils.app import TezosAppScreen from utils.message import FailingNoop +from utils.navigator import TezosNavigator -def test_sign_failing_noop(app: TezosAppScreen, account: Account, snapshot_dir: Path): + +def test_sign_failing_noop(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path): """Check signing failing noop""" message = FailingNoop("9f09f2952d34528c733f94615cfc39bc555619fc550dd4a67ba2208ce8e867aa3d13a6ef99dfbe32c6974aa9a2150d21eca29c3349e59c13b9081f1c11b440ac4d3455dedbe4ee0de15a8af620d4c86247d9d132de1bb6da23d5ff9d8dffda22ba9a84") - data = app.sign(account, - message, - with_hash=True, - snap_path=snapshot_dir) + data = tezos_navigator.sign( + account, + message, + with_hash=True, + snap_path=snapshot_dir + ) account.check_signature( message=message, diff --git a/tests/integration/nano/test_sign/operations/test_sign_increase_paid_storage.py b/tests/integration/nano/test_sign/operations/test_sign_increase_paid_storage.py index 69a456847..e7b3dd7ea 100755 --- a/tests/integration/nano/test_sign/operations/test_sign_increase_paid_storage.py +++ b/tests/integration/nano/test_sign/operations/test_sign_increase_paid_storage.py @@ -19,10 +19,11 @@ from pathlib import Path from utils.account import Account -from utils.app import TezosAppScreen from utils.message import IncreasePaidStorage +from utils.navigator import TezosNavigator -def test_sign_increase_paid_storage(app: TezosAppScreen, account: Account, snapshot_dir: Path): + +def test_sign_increase_paid_storage(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path): """Check signing increase paid storage""" message = IncreasePaidStorage( @@ -35,10 +36,12 @@ def test_sign_increase_paid_storage(app: TezosAppScreen, account: Account, snaps destination = "KT18amZmM5W7qDWVt2pH6uj7sCEd3kbzLrHT" ) - data = app.sign(account, - message, - with_hash=True, - snap_path=snapshot_dir) + data = tezos_navigator.sign( + account, + message, + with_hash=True, + snap_path=snapshot_dir + ) account.check_signature( message=message, diff --git a/tests/integration/nano/test_sign/operations/test_sign_origination.py b/tests/integration/nano/test_sign/operations/test_sign_origination.py index c3cc05b3a..5c167483f 100755 --- a/tests/integration/nano/test_sign/operations/test_sign_origination.py +++ b/tests/integration/nano/test_sign/operations/test_sign_origination.py @@ -19,13 +19,14 @@ from pathlib import Path from utils.account import Account -from utils.app import TezosAppScreen from utils.message import Origination +from utils.navigator import TezosNavigator -def test_sign_origination(app: TezosAppScreen, account: Account, snapshot_dir: Path): + +def test_sign_origination(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path): """Check signing origination""" - app.toggle_expert_mode() + tezos_navigator.toggle_expert_mode() message = Origination( source = 'tz1ixvCiPJYyMjsp2nKBVaq54f6AdbV8hCKa', @@ -38,10 +39,12 @@ def test_sign_origination(app: TezosAppScreen, account: Account, snapshot_dir: P balance = 500000 ) - data = app.sign(account, - message, - with_hash=True, - snap_path=snapshot_dir) + data = tezos_navigator.sign( + account, + message, + with_hash=True, + snap_path=snapshot_dir + ) account.check_signature( message=message, diff --git a/tests/integration/nano/test_sign/operations/test_sign_proposals.py b/tests/integration/nano/test_sign/operations/test_sign_proposals.py index 2f81eb770..556a3f6fe 100755 --- a/tests/integration/nano/test_sign/operations/test_sign_proposals.py +++ b/tests/integration/nano/test_sign/operations/test_sign_proposals.py @@ -19,10 +19,11 @@ from pathlib import Path from utils.account import Account -from utils.app import TezosAppScreen from utils.message import Proposals +from utils.navigator import TezosNavigator -def test_sign_proposals(app: TezosAppScreen, account: Account, snapshot_dir: Path): + +def test_sign_proposals(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path): """Check signing proposals""" message = Proposals( @@ -34,10 +35,12 @@ def test_sign_proposals(app: TezosAppScreen, account: Account, snapshot_dir: Pat period = 32 ) - data = app.sign(account, - message, - with_hash=True, - snap_path=snapshot_dir) + data = tezos_navigator.sign( + account, + message, + with_hash=True, + snap_path=snapshot_dir + ) account.check_signature( message=message, diff --git a/tests/integration/nano/test_sign/operations/test_sign_register_global_constant.py b/tests/integration/nano/test_sign/operations/test_sign_register_global_constant.py index e30604297..9b5fc069b 100755 --- a/tests/integration/nano/test_sign/operations/test_sign_register_global_constant.py +++ b/tests/integration/nano/test_sign/operations/test_sign_register_global_constant.py @@ -19,13 +19,14 @@ from pathlib import Path from utils.account import Account -from utils.app import TezosAppScreen from utils.message import RegisterGlobalConstant +from utils.navigator import TezosNavigator -def test_sign_register_global_constant(app: TezosAppScreen, account: Account, snapshot_dir: Path): + +def test_sign_register_global_constant(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path): """Check signing register global constant""" - app.toggle_expert_mode() + tezos_navigator.toggle_expert_mode() message = RegisterGlobalConstant( source = 'tz1ixvCiPJYyMjsp2nKBVaq54f6AdbV8hCKa', @@ -36,10 +37,12 @@ def test_sign_register_global_constant(app: TezosAppScreen, account: Account, sn value = {'prim': 'Pair', 'args': [{'string': '1'}, {'int': 2}]} ) - data = app.sign(account, - message, - with_hash=True, - snap_path=snapshot_dir) + data = tezos_navigator.sign( + account, + message, + with_hash=True, + snap_path=snapshot_dir + ) account.check_signature( message=message, diff --git a/tests/integration/nano/test_sign/operations/test_sign_reveal.py b/tests/integration/nano/test_sign/operations/test_sign_reveal.py index 48d1db68c..485f1c335 100755 --- a/tests/integration/nano/test_sign/operations/test_sign_reveal.py +++ b/tests/integration/nano/test_sign/operations/test_sign_reveal.py @@ -19,10 +19,11 @@ from pathlib import Path from utils.account import Account -from utils.app import TezosAppScreen from utils.message import Reveal +from utils.navigator import TezosNavigator -def test_sign_reveal(app: TezosAppScreen, account: Account, snapshot_dir: Path): + +def test_sign_reveal(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path): """Check signing reveal""" message = Reveal( @@ -34,10 +35,12 @@ def test_sign_reveal(app: TezosAppScreen, account: Account, snapshot_dir: Path): public_key = 'edpkuXX2VdkdXzkN11oLCb8Aurdo1BTAtQiK8ZY9UPj2YMt3AHEpcY' ) - data = app.sign(account, - message, - with_hash=True, - snap_path=snapshot_dir) + data = tezos_navigator.sign( + account, + message, + with_hash=True, + snap_path=snapshot_dir + ) account.check_signature( message=message, diff --git a/tests/integration/nano/test_sign/operations/test_sign_sc_rollup_add_messages.py b/tests/integration/nano/test_sign/operations/test_sign_sc_rollup_add_messages.py index b91fdd592..230af2121 100755 --- a/tests/integration/nano/test_sign/operations/test_sign_sc_rollup_add_messages.py +++ b/tests/integration/nano/test_sign/operations/test_sign_sc_rollup_add_messages.py @@ -19,10 +19,11 @@ from pathlib import Path from utils.account import Account -from utils.app import TezosAppScreen from utils.message import ScRollupAddMessage +from utils.navigator import TezosNavigator -def test_sign_sc_rollup_add_messages(app: TezosAppScreen, account: Account, snapshot_dir: Path): + +def test_sign_sc_rollup_add_messages(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path): """Check signing smart rollup add message""" message = ScRollupAddMessage( @@ -34,10 +35,12 @@ def test_sign_sc_rollup_add_messages(app: TezosAppScreen, account: Account, snap message = [bytes.fromhex('012345'), bytes.fromhex('67'), bytes.fromhex('89abcdef')] ) - data = app.sign(account, - message, - with_hash=True, - snap_path=snapshot_dir) + data = tezos_navigator.sign( + account, + message, + with_hash=True, + snap_path=snapshot_dir + ) account.check_signature( message=message, diff --git a/tests/integration/nano/test_sign/operations/test_sign_sc_rollup_execute_outbox_message.py b/tests/integration/nano/test_sign/operations/test_sign_sc_rollup_execute_outbox_message.py index 81e04a07f..c67918903 100755 --- a/tests/integration/nano/test_sign/operations/test_sign_sc_rollup_execute_outbox_message.py +++ b/tests/integration/nano/test_sign/operations/test_sign_sc_rollup_execute_outbox_message.py @@ -19,13 +19,14 @@ from pathlib import Path from utils.account import Account -from utils.app import TezosAppScreen from utils.message import ScRollupExecuteOutboxMessage +from utils.navigator import TezosNavigator -def test_sign_sc_rollup_execute_outbox_message(app: TezosAppScreen, account: Account, snapshot_dir: Path): + +def test_sign_sc_rollup_execute_outbox_message(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path): """Check signing smart rollup execute outbox message""" - app.toggle_expert_mode() + tezos_navigator.toggle_expert_mode() message = ScRollupExecuteOutboxMessage( source = 'tz1ixvCiPJYyMjsp2nKBVaq54f6AdbV8hCKa', @@ -38,10 +39,12 @@ def test_sign_sc_rollup_execute_outbox_message(app: TezosAppScreen, account: Acc output_proof = b'9f09f2952d34528c733f94615cfc39bc555619fc550dd4a67ba2208ce8e867aa3d13a6ef99dfbe32c6974aa9a2150d21eca29c3349e59c13b9081f1c11b440ac4d3455dedbe4ee0de15a8af620d4c86247d9d132de1bb6da23d5ff9d8dffda22ba9a84' ) - data = app.sign(account, - message, - with_hash=True, - snap_path=snapshot_dir) + data = tezos_navigator.sign( + account, + message, + with_hash=True, + snap_path=snapshot_dir + ) account.check_signature( message=message, diff --git a/tests/integration/nano/test_sign/operations/test_sign_sc_rollup_originate.py b/tests/integration/nano/test_sign/operations/test_sign_sc_rollup_originate.py index 3743adcf2..00829ae8f 100755 --- a/tests/integration/nano/test_sign/operations/test_sign_sc_rollup_originate.py +++ b/tests/integration/nano/test_sign/operations/test_sign_sc_rollup_originate.py @@ -22,8 +22,8 @@ import pytest from utils.account import Account -from utils.app import TezosAppScreen from utils.message import ScRollupOriginate +from utils.navigator import TezosNavigator @pytest.mark.parametrize( @@ -42,10 +42,10 @@ "with_whitelist", ], ) -def test_sign_sc_rollup_originate(app: TezosAppScreen, account: Account, whitelist: Optional[List[str]], snapshot_dir: Path): +def test_sign_sc_rollup_originate(tezos_navigator: TezosNavigator, account: Account, whitelist: Optional[List[str]], snapshot_dir: Path): """Check signing smart rollup originate""" - app.toggle_expert_mode() + tezos_navigator.toggle_expert_mode() message = ScRollupOriginate( source = 'tz1ixvCiPJYyMjsp2nKBVaq54f6AdbV8hCKa', @@ -59,10 +59,12 @@ def test_sign_sc_rollup_originate(app: TezosAppScreen, account: Account, whiteli whitelist = whitelist ) - data = app.sign(account, - message, - with_hash=True, - snap_path=snapshot_dir) + data = tezos_navigator.sign( + account, + message, + with_hash=True, + snap_path=snapshot_dir + ) account.check_signature( message=message, diff --git a/tests/integration/nano/test_sign/operations/test_sign_set_consensus_key.py b/tests/integration/nano/test_sign/operations/test_sign_set_consensus_key.py index f385b90e9..38cc77024 100755 --- a/tests/integration/nano/test_sign/operations/test_sign_set_consensus_key.py +++ b/tests/integration/nano/test_sign/operations/test_sign_set_consensus_key.py @@ -19,10 +19,11 @@ from pathlib import Path from utils.account import Account -from utils.app import TezosAppScreen from utils.message import UpdateConsensusKey +from utils.navigator import TezosNavigator -def test_sign_set_consensus_key(app: TezosAppScreen, account: Account, snapshot_dir: Path): + +def test_sign_set_consensus_key(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path): """Check signing set consensus key""" message = UpdateConsensusKey( @@ -34,10 +35,12 @@ def test_sign_set_consensus_key(app: TezosAppScreen, account: Account, snapshot_ pk = "edpkuXX2VdkdXzkN11oLCb8Aurdo1BTAtQiK8ZY9UPj2YMt3AHEpcY" ) - data = app.sign(account, - message, - with_hash=True, - snap_path=snapshot_dir) + data = tezos_navigator.sign( + account, + message, + with_hash=True, + snap_path=snapshot_dir + ) account.check_signature( message=message, diff --git a/tests/integration/nano/test_sign/operations/test_sign_set_deposit_limit.py b/tests/integration/nano/test_sign/operations/test_sign_set_deposit_limit.py index 217917bd2..3bbe4c06f 100755 --- a/tests/integration/nano/test_sign/operations/test_sign_set_deposit_limit.py +++ b/tests/integration/nano/test_sign/operations/test_sign_set_deposit_limit.py @@ -19,10 +19,11 @@ from pathlib import Path from utils.account import Account -from utils.app import TezosAppScreen from utils.message import SetDepositLimit +from utils.navigator import TezosNavigator -def test_sign_set_deposit_limit(app: TezosAppScreen, account: Account, snapshot_dir: Path): + +def test_sign_set_deposit_limit(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path): """Check signing set deposit limit""" message = SetDepositLimit( @@ -34,10 +35,12 @@ def test_sign_set_deposit_limit(app: TezosAppScreen, account: Account, snapshot_ limit = 20000 ) - data = app.sign(account, - message, - with_hash=True, - snap_path=snapshot_dir) + data = tezos_navigator.sign( + account, + message, + with_hash=True, + snap_path=snapshot_dir + ) account.check_signature( message=message, diff --git a/tests/integration/nano/test_sign/operations/test_sign_transaction.py b/tests/integration/nano/test_sign/operations/test_sign_transaction.py index 1575c16ff..50540dd29 100755 --- a/tests/integration/nano/test_sign/operations/test_sign_transaction.py +++ b/tests/integration/nano/test_sign/operations/test_sign_transaction.py @@ -19,14 +19,15 @@ from pathlib import Path from utils.account import Account -from utils.app import ScreenText, TezosAppScreen from utils.backend import StatusCode from utils.message import Transaction +from utils.navigator import ScreenText, TezosNavigator -def test_sign_transaction(app: TezosAppScreen, account: Account, snapshot_dir: Path): + +def test_sign_transaction(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path): """Check signing transaction""" - app.toggle_expert_mode() + tezos_navigator.toggle_expert_mode() message = Transaction( source = 'tz2JPgTWZZpxZZLqHMfS69UAy1UHm4Aw5iHu', @@ -40,20 +41,22 @@ def test_sign_transaction(app: TezosAppScreen, account: Account, snapshot_dir: P parameter = {'prim': 'CAR'} ) - data = app.sign(account, - message, - with_hash=True, - snap_path=snapshot_dir) + data = tezos_navigator.sign( + account, + message, + with_hash=True, + snap_path=snapshot_dir + ) account.check_signature( message=message, with_hash=True, data=data) -def test_reject_transaction(app: TezosAppScreen, account: Account, snapshot_dir: Path): +def test_reject_transaction(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path): """Check reject transaction""" - app.toggle_expert_mode() + tezos_navigator.toggle_expert_mode() message = Transaction( source = 'tz1ixvCiPJYyMjsp2nKBVaq54f6AdbV8hCKa', @@ -68,15 +71,17 @@ def test_reject_transaction(app: TezosAppScreen, account: Account, snapshot_dir: ) with StatusCode.REJECT.expected(): - app.reject_signing(account, - message, - with_hash=True, - snap_path=snapshot_dir) + tezos_navigator.reject_signing( + account, + message, + with_hash=True, + snap_path=snapshot_dir + ) -def test_sign_simple_transaction(app: TezosAppScreen, account: Account, snapshot_dir: Path): +def test_sign_simple_transaction(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path): """Check sign not complex transaction""" - app.toggle_expert_mode() + tezos_navigator.toggle_expert_mode() message = Transaction( source = 'tz1ixvCiPJYyMjsp2nKBVaq54f6AdbV8hCKa', @@ -88,17 +93,19 @@ def test_sign_simple_transaction(app: TezosAppScreen, account: Account, snapshot amount = 10000 ) - data = app.sign(account, - message, - with_hash=True, - snap_path=snapshot_dir) + data = tezos_navigator.sign( + account, + message, + with_hash=True, + snap_path=snapshot_dir + ) account.check_signature( message=message, with_hash=True, data=data) -def test_too_complex_transaction(app: TezosAppScreen, account: Account, snapshot_dir: Path): +def test_too_complex_transaction(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path): """Check sign complex transaction""" message = Transaction( @@ -114,17 +121,17 @@ def test_too_complex_transaction(app: TezosAppScreen, account: Account, snapshot ) with StatusCode.REJECT.expected(): - app.sign( + tezos_navigator.sign( account, message, with_hash=True, - navigate=lambda: app.navigate_review(text=ScreenText.BACK_HOME, snap_path=snapshot_dir) + navigate=lambda: tezos_navigator.navigate_review(text=ScreenText.BACK_HOME, snap_path=snapshot_dir) ) -def test_sign_stake_transaction(app: TezosAppScreen, account: Account, snapshot_dir: Path): +def test_sign_stake_transaction(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path): """Check sign stake""" - app.toggle_expert_mode() + tezos_navigator.toggle_expert_mode() message = Transaction( source = 'tz2WmivuMG8MMRKMEmzKRMMxMApxZQWYNS4W', @@ -137,20 +144,22 @@ def test_sign_stake_transaction(app: TezosAppScreen, account: Account, snapshot_ entrypoint = 'stake', ) - data = app.sign(account, - message, - with_hash=True, - snap_path=snapshot_dir) + data = tezos_navigator.sign( + account, + message, + with_hash=True, + snap_path=snapshot_dir + ) account.check_signature( message=message, with_hash=True, data=data) -def test_sign_unstake_transaction(app: TezosAppScreen, account: Account, snapshot_dir: Path): +def test_sign_unstake_transaction(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path): """Check sign unstake""" - app.toggle_expert_mode() + tezos_navigator.toggle_expert_mode() message = Transaction( source = 'tz2WmivuMG8MMRKMEmzKRMMxMApxZQWYNS4W', @@ -163,20 +172,22 @@ def test_sign_unstake_transaction(app: TezosAppScreen, account: Account, snapsho entrypoint = 'unstake' ) - data = app.sign(account, - message, - with_hash=True, - snap_path=snapshot_dir) + data = tezos_navigator.sign( + account, + message, + with_hash=True, + snap_path=snapshot_dir + ) account.check_signature( message=message, with_hash=True, data=data) -def test_sign_finalize_unstake_transaction(app: TezosAppScreen, account: Account, snapshot_dir: Path): +def test_sign_finalize_unstake_transaction(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path): """Check sign finalize_unstake""" - app.toggle_expert_mode() + tezos_navigator.toggle_expert_mode() message = Transaction( source = 'tz2WmivuMG8MMRKMEmzKRMMxMApxZQWYNS4W', @@ -189,20 +200,22 @@ def test_sign_finalize_unstake_transaction(app: TezosAppScreen, account: Account entrypoint = 'finalize_unstake' ) - data = app.sign(account, - message, - with_hash=True, - snap_path=snapshot_dir) + data = tezos_navigator.sign( + account, + message, + with_hash=True, + snap_path=snapshot_dir + ) account.check_signature( message=message, with_hash=True, data=data) -def test_sign_set_delegate_parameters_transaction(app: TezosAppScreen, account: Account, snapshot_dir: Path): +def test_sign_set_delegate_parameters_transaction(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path): """Check sign set delegate parameters""" - app.toggle_expert_mode() + tezos_navigator.toggle_expert_mode() message = Transaction( source = 'tz2WmivuMG8MMRKMEmzKRMMxMApxZQWYNS4W', @@ -224,20 +237,22 @@ def test_sign_set_delegate_parameters_transaction(app: TezosAppScreen, account: ]} ) - data = app.sign(account, - message, - with_hash=True, - snap_path=snapshot_dir) + data = tezos_navigator.sign( + account, + message, + with_hash=True, + snap_path=snapshot_dir + ) account.check_signature( message=message, with_hash=True, data=data) -def test_sign_with_long_hash(app: TezosAppScreen, account: Account, snapshot_dir: Path): +def test_sign_with_long_hash(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path): """Check signing transaction with a long destination hash""" - app.toggle_expert_mode() + tezos_navigator.toggle_expert_mode() message = Transaction( source = 'tz1ixvCiPJYyMjsp2nKBVaq54f6AdbV8hCKa', @@ -251,20 +266,22 @@ def test_sign_with_long_hash(app: TezosAppScreen, account: Account, snapshot_dir parameter = {'int': 0} ) - data = app.sign(account, - message, - with_hash=True, - snap_path=snapshot_dir) + data = tezos_navigator.sign( + account, + message, + with_hash=True, + snap_path=snapshot_dir + ) account.check_signature( message=message, with_hash=True, data=data) -def test_ensure_always_clearsign(app: TezosAppScreen, account: Account, snapshot_dir: Path): +def test_ensure_always_clearsign(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path): """Check clear signing never blindsign""" - app.toggle_expert_mode() + tezos_navigator.toggle_expert_mode() message = Transaction( source = 'tz1ixvCiPJYyMjsp2nKBVaq54f6AdbV8hCKa', @@ -278,10 +295,12 @@ def test_ensure_always_clearsign(app: TezosAppScreen, account: Account, snapshot parameter = [{'prim':'pair','args':[{'string':"["},{'prim':'pair','args':[{'string':"Z"},{'prim':'pair','args':[{'string':"Y"},{'prim':'pair','args':[{'string':"X"},{'prim':'pair','args':[{'string':"W"},{'prim':'pair','args':[{'string':"V"},{'prim':'pair','args':[{'string':"U"},{'prim':'pair','args':[{'string':"T"},{'prim':'pair','args':[{'string':"S"},{'prim':'pair','args':[{'string':"R"},{'prim':'pair','args':[{'string':"Q"},{'prim':'pair','args':[{'string':"P"},{'prim':'pair','args':[{'string':"O"},{'prim':'pair','args':[{'string':"N"},{'prim':'pair','args':[{'string':"M"},{'prim':'pair','args':[{'string':"L"},{'prim':'pair','args':[{'string':"K"},{'prim':'pair','args':[{'string':"J"},{'prim':'pair','args':[{'string':"I"},{'prim':'pair','args':[{'string':"H"},{'prim':'pair','args':[{'string':"G"},{'prim':'pair','args':[{'string':"F"},{'prim':'pair','args':[{'string':"E"},{'prim':'pair','args':[{'string':"D"},{'prim':'pair','args':[{'string':"C"},{'prim':'pair','args':[{'string':"B"},[]]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]},{'prim':'pair','args':[{'int':10},{'prim':'pair','args':[{'int':9},{'prim':'pair','args':[{'int':8},{'prim':'pair','args':[{'int':7},{'prim':'pair','args':[{'int':6},{'prim':'pair','args':[{'int':5},{'prim':'pair','args':[{'int':4},{'prim':'pair','args':[{'int':3},{'prim':'pair','args':[{'int':2},{'prim':'pair','args':[{'int':1},[]]}]}]}]}]}]}]}]}]}]}] ) - data = app.sign(account, - message, - with_hash=True, - snap_path=snapshot_dir) + data = tezos_navigator.sign( + account, + message, + with_hash=True, + snap_path=snapshot_dir + ) account.check_signature( message=message, diff --git a/tests/integration/nano/test_sign/operations/test_sign_transfer_ticket.py b/tests/integration/nano/test_sign/operations/test_sign_transfer_ticket.py index 7b205f289..c201a7df6 100755 --- a/tests/integration/nano/test_sign/operations/test_sign_transfer_ticket.py +++ b/tests/integration/nano/test_sign/operations/test_sign_transfer_ticket.py @@ -20,13 +20,14 @@ from conftest import requires_device from utils.account import Account -from utils.app import TezosAppScreen from utils.message import TransferTicket +from utils.navigator import TezosNavigator -def test_sign_transfer_ticket(app: TezosAppScreen, account: Account, snapshot_dir: Path): + +def test_sign_transfer_ticket(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path): """Check signing transfer ticket""" - app.toggle_expert_mode() + tezos_navigator.toggle_expert_mode() message = TransferTicket( source = 'tz1ixvCiPJYyMjsp2nKBVaq54f6AdbV8hCKa', @@ -41,10 +42,12 @@ def test_sign_transfer_ticket(app: TezosAppScreen, account: Account, snapshot_di destination = 'KT18amZmM5W7qDWVt2pH6uj7sCEd3kbzLrHT' ) - data = app.sign(account, - message, - with_hash=True, - snap_path=snapshot_dir) + data = tezos_navigator.sign( + account, + message, + with_hash=True, + snap_path=snapshot_dir + ) account.check_signature( message=message, @@ -52,10 +55,10 @@ def test_sign_transfer_ticket(app: TezosAppScreen, account: Account, snapshot_di data=data) @requires_device("nanosp") -def test_nanosp_regression_potential_empty_screen(app: TezosAppScreen, account: Account, snapshot_dir: Path): +def test_nanosp_regression_potential_empty_screen(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path): """Check signing operation that display potentially empty screens""" - app.toggle_expert_mode() + tezos_navigator.toggle_expert_mode() message = TransferTicket( source = 'tz1ixvCiPJYyMjsp2nKBVaq54f6AdbV8hCKa', @@ -71,10 +74,12 @@ def test_nanosp_regression_potential_empty_screen(app: TezosAppScreen, account: entrypoint = 'S\n\nS\nS\nS' ) - data = app.sign(account, - message, - with_hash=True, - snap_path=snapshot_dir) + data = tezos_navigator.sign( + account, + message, + with_hash=True, + snap_path=snapshot_dir + ) account.check_signature( message=message, diff --git a/tests/integration/nano/test_sign/test_apdu_sign.py b/tests/integration/nano/test_sign/test_apdu_sign.py index 353c03ead..4ca2c49ad 100644 --- a/tests/integration/nano/test_sign/test_apdu_sign.py +++ b/tests/integration/nano/test_sign/test_apdu_sign.py @@ -20,28 +20,36 @@ from conftest import requires_device from utils.account import Account -from utils.app import send_and_navigate, ScreenText, TezosAppScreen +from utils.backend import TezosBackend from utils.message import Message, MichelineExpr, Transaction +from utils.navigator import send_and_navigate, ScreenText, TezosNavigator -def test_sign_micheline_without_hash(app: TezosAppScreen, account: Account, snapshot_dir: Path): + +def test_sign_micheline_without_hash(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path): """Check signing micheline wihout getting hash""" message = MichelineExpr([{'string': 'CACA'}, {'string': 'POPO'}, {'string': 'BOUDIN'}]) - data = app.sign(account, - message, - with_hash=False, - snap_path=snapshot_dir) + data = tezos_navigator.sign( + account, + message, + with_hash=False, + snap_path=snapshot_dir + ) account.check_signature( message=message, with_hash=False, data=data) -def test_sign_with_small_packet(app: TezosAppScreen, account: Account, snapshot_dir: Path): +def test_sign_with_small_packet( + backend: TezosBackend, + tezos_navigator: TezosNavigator, + account: Account, + snapshot_dir: Path): """Check signing using small packet instead of full size packets""" - app.toggle_expert_mode() + tezos_navigator.toggle_expert_mode() def check_sign_with_small_packet( account: Account, @@ -49,8 +57,8 @@ def check_sign_with_small_packet( path: Path) -> None: data = send_and_navigate( - send=lambda: app.backend.sign(account, message, apdu_size=10), - navigate=lambda: app.navigate_review(text=ScreenText.SIGN_ACCEPT, snap_path=path) + send=lambda: backend.sign(account, message, apdu_size=10), + navigate=lambda: tezos_navigator.navigate_review(text=ScreenText.SIGN_ACCEPT, snap_path=path) ) account.check_signature( @@ -76,15 +84,17 @@ def check_sign_with_small_packet( path=snapshot_dir) @requires_device("nanosp") -def test_nanosp_regression_press_right_works_across_apdu_recieves(app: TezosAppScreen, account: Account, snapshot_dir: Path): +def test_nanosp_regression_press_right_works_across_apdu_recieves(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path): """Check no need to click right two times between APDUs during signing flow""" message = MichelineExpr([{'prim':'IF_NONE','args':[[[{'prim':'SWAP'},{'prim':'IF','args':[[{'prim':'DIP','args':[[[{'prim':'DROP','args':[{'int':1}]},{'prim':'PUSH','args':[{'prim':'unit'},{'prim':'Unit'}]},{'prim':'PUSH','args':[{'prim':'bool'},{'prim':'True'}]},{'prim':'PUSH','args':[{'prim':'string'},{'string':';L\\S?p$-Fq)VDg\n]te\no4v0_8)\"'}]}]]]}],[[{'prim':'DROP','args':[{'int':2}]},{'prim':'PUSH','args':[{'prim':'unit'},{'prim':'Unit'}]},{'prim':'PUSH','args':[{'prim':'bool'},{'prim':'False'}]},{'prim':'PUSH','args':[{'prim':'string'},{'string':'Li-%*edF6~?E[5Kmu?dyviwJ^2\"\\d$FyQ>>!>D$g(Qg'}]},{'prim':'PUSH','args':[{'prim':'string'},{'string':'*Tx None: - app.navigate_review(text=ScreenText.ACCEPT_RISK, snap_path=path / "clear_n_too_long_warning") - app.navigate_review(text=ScreenText.SIGN_ACCEPT, snap_path=path / "summary") + tezos_navigator.navigate_review(text=ScreenText.ACCEPT_RISK, snap_path=path / "clear_n_too_long_warning") + tezos_navigator.navigate_review(text=ScreenText.SIGN_ACCEPT, snap_path=path / "summary") - _sign_too_long(app, account, message, navigate) + _sign_too_long(tezos_navigator, account, message, navigate) def _reject_too_long( - app: TezosAppScreen, + tezos_navigator: TezosNavigator, account: Account, message: Message, status_code: StatusCode, navigate: Callable[[], None]): """Reject a too long message""" - app.toggle_expert_mode() - app.toggle_blindsign() + tezos_navigator.toggle_expert_mode() + tezos_navigator.toggle_blindsign() with status_code.expected(): - app.sign( + tezos_navigator.sign( account, message, with_hash=True, @@ -158,31 +159,31 @@ def _reject_too_long( ) ]) -def test_sign_basic_too_long_operation(app: TezosAppScreen, account: Account, snapshot_dir: Path): +def test_sign_basic_too_long_operation(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path): """Check sign too long operation""" - _sign_decodable_too_long(app, account, BASIC_OPERATION, snapshot_dir) + _sign_decodable_too_long(tezos_navigator, account, BASIC_OPERATION, snapshot_dir) -def test_reject_basic_too_long_operation_at_warning(app: TezosAppScreen, account: Account, snapshot_dir: Path): +def test_reject_basic_too_long_operation_at_warning(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path): """Check reject too long operation at warning""" def navigate() -> None: - app.navigate_review(text=ScreenText.SIGN_REJECT, snap_path=snapshot_dir / "clear_n_too_long_warning") + tezos_navigator.navigate_review(text=ScreenText.SIGN_REJECT, snap_path=snapshot_dir / "clear_n_too_long_warning") - _reject_too_long(app, account, BASIC_OPERATION, StatusCode.REJECT, navigate) + _reject_too_long(tezos_navigator, account, BASIC_OPERATION, StatusCode.REJECT, navigate) -def test_reject_basic_too_long_operation_at_summary(app: TezosAppScreen, account: Account, snapshot_dir: Path): +def test_reject_basic_too_long_operation_at_summary(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path): """Check reject too long operation at summary""" def navigate() -> None: - app.navigate_review(text=ScreenText.ACCEPT_RISK, snap_path=snapshot_dir / "clear_n_too_long_warning") - app.navigate_review(text=ScreenText.SIGN_REJECT, snap_path=snapshot_dir / "summary") + tezos_navigator.navigate_review(text=ScreenText.ACCEPT_RISK, snap_path=snapshot_dir / "clear_n_too_long_warning") + tezos_navigator.navigate_review(text=ScreenText.SIGN_REJECT, snap_path=snapshot_dir / "summary") - _reject_too_long(app, account, BASIC_OPERATION, StatusCode.REJECT, navigate) + _reject_too_long(tezos_navigator, account, BASIC_OPERATION, StatusCode.REJECT, navigate) ### Different kind of too long operation ### -def test_sign_too_long_operation_with_only_transactions(app: TezosAppScreen, account: Account, snapshot_dir: Path): +def test_sign_too_long_operation_with_only_transactions(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path): """Check sign too long operation that contains only transaction""" message = OperationGroup([ Transaction( @@ -240,9 +241,9 @@ def test_sign_too_long_operation_with_only_transactions(app: TezosAppScreen, acc amount = 5000000 ) ]) - _sign_decodable_too_long(app, account, message, snapshot_dir) + _sign_decodable_too_long(tezos_navigator, account, message, snapshot_dir) -def test_sign_too_long_operation_without_fee_or_amount(app: TezosAppScreen, account: Account, snapshot_dir: Path): +def test_sign_too_long_operation_without_fee_or_amount(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path): """Check sign too long operation that doesn't have fees or amount""" message = Proposals( source = 'tz1ixvCiPJYyMjsp2nKBVaq54f6AdbV8hCKa', @@ -270,7 +271,7 @@ def test_sign_too_long_operation_without_fee_or_amount(app: TezosAppScreen, acco ], period = 32 ) - _sign_decodable_too_long(app, account, message, snapshot_dir) + _sign_decodable_too_long(tezos_navigator, account, message, snapshot_dir) ### Too long operation containing a too large number ### @@ -325,39 +326,44 @@ def test_sign_too_long_operation_without_fee_or_amount(app: TezosAppScreen, acco ) ]) -def test_sign_too_long_operation_with_too_large(app: TezosAppScreen, account: Account, snapshot_dir: Path): +def test_sign_too_long_operation_with_too_large(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path): """Check sign too long operation that will also fail the parsing""" def navigate() -> None: - app.navigate_review(text=ScreenText.ACCEPT_RISK, snap_path=snapshot_dir / "clear_n_too_large_warning") - app.navigate_review(text=ScreenText.SIGN_ACCEPT, snap_path=snapshot_dir / "blindsigning") + tezos_navigator.navigate_review(text=ScreenText.ACCEPT_RISK, snap_path=snapshot_dir / "clear_n_too_large_warning") + tezos_navigator.navigate_review(text=ScreenText.SIGN_ACCEPT, snap_path=snapshot_dir / "blindsigning") - _sign_too_long(app, account, OPERATION_WITH_TOO_LARGE, navigate) + _sign_too_long(tezos_navigator, account, OPERATION_WITH_TOO_LARGE, navigate) -def test_reject_too_long_operation_with_too_large_at_too_large_warning(app: TezosAppScreen, account: Account, snapshot_dir: Path): +def test_reject_too_long_operation_with_too_large_at_too_large_warning(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path): """Check reject too long operation that will also fail the parsing at too large warning""" def navigate() -> None: - app.navigate_review(text=ScreenText.SIGN_REJECT, snap_path=snapshot_dir / "clear_n_too_large_warning") + tezos_navigator.navigate_review(text=ScreenText.SIGN_REJECT, snap_path=snapshot_dir / "clear_n_too_large_warning") - _reject_too_long(app, account, OPERATION_WITH_TOO_LARGE, StatusCode.PARSE_ERROR, navigate) + _reject_too_long(tezos_navigator, account, OPERATION_WITH_TOO_LARGE, StatusCode.PARSE_ERROR, navigate) -def test_reject_too_long_operation_with_too_large_at_blindsigning(app: TezosAppScreen, account: Account, snapshot_dir: Path): +def test_reject_too_long_operation_with_too_large_at_blindsigning(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path): """Check reject too long operation that will also fail the parsing at blindsigning""" def navigate() -> None: - app.navigate_review(text=ScreenText.ACCEPT_RISK, snap_path=snapshot_dir / "clear_n_too_large_warning") - app.navigate_review(text=ScreenText.SIGN_REJECT, snap_path=snapshot_dir / "blindsigning") + tezos_navigator.navigate_review(text=ScreenText.ACCEPT_RISK, snap_path=snapshot_dir / "clear_n_too_large_warning") + tezos_navigator.navigate_review(text=ScreenText.SIGN_REJECT, snap_path=snapshot_dir / "blindsigning") - _reject_too_long(app, account, OPERATION_WITH_TOO_LARGE, StatusCode.REJECT, navigate) + _reject_too_long(tezos_navigator, account, OPERATION_WITH_TOO_LARGE, StatusCode.REJECT, navigate) -def test_blindsign_too_deep(app: TezosAppScreen, account: Account, snapshot_dir: Path): +def test_blindsign_too_deep( + backend: TezosBackend, + firmware: Firmware, + tezos_navigator: TezosNavigator, + account: Account, + snapshot_dir: Path): """Check blindsigning on too deep expression""" expression = MichelineExpr([[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[{'int':42}]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]) def navigate() -> None: - if app.backend.firmware.device == "nanos": + if firmware == Firmware.NANOS: ### Simulate `navigate_review` up to `ACCEPT_RISK` because the nanos screen can look like it hasn't changed. instructions: List[Union[NavIns, NavInsID]] = [ @@ -371,18 +377,18 @@ def navigate() -> None: NavInsID.BOTH_CLICK, ] - app.unsafe_navigate( + tezos_navigator.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") + tezos_navigator.navigate_review(text=ScreenText.ACCEPT_RISK, snap_path=snapshot_dir / "clear") - app.navigate_review(text=ScreenText.SIGN_ACCEPT, snap_path=snapshot_dir / "blind") + tezos_navigator.navigate_review(text=ScreenText.SIGN_ACCEPT, snap_path=snapshot_dir / "blind") - data = app.sign( + data = tezos_navigator.sign( account, expression, with_hash=True, @@ -394,16 +400,16 @@ def navigate() -> None: with_hash=True, data=data) -def test_blindsign_too_large(app: TezosAppScreen, account: Account, snapshot_dir: Path): +def test_blindsign_too_large(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path): """Check blindsigning on too large expression""" message = MichelineExpr({'int':12345678901234567890123456789012345678901234567890123456789012345678901234567890}) def navigate() -> None: - app.navigate_review(text=ScreenText.ACCEPT_RISK, snap_path=snapshot_dir / "clear") - app.navigate_review(text=ScreenText.SIGN_ACCEPT, snap_path=snapshot_dir / "blind") + tezos_navigator.navigate_review(text=ScreenText.ACCEPT_RISK, snap_path=snapshot_dir / "clear") + tezos_navigator.navigate_review(text=ScreenText.SIGN_ACCEPT, snap_path=snapshot_dir / "blind") - data = app.sign( + data = tezos_navigator.sign( account, message, with_hash=True, @@ -415,30 +421,30 @@ def navigate() -> None: with_hash=True, data=data) -def test_blindsign_reject_from_clear(app: TezosAppScreen, account: Account, snapshot_dir: Path): +def test_blindsign_reject_from_clear(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path): """Check blindsigning rejection""" expression = MichelineExpr({'int':12345678901234567890123456789012345678901234567890123456789012345678901234567890}) with StatusCode.PARSE_ERROR.expected(): - app.reject_signing( + tezos_navigator.reject_signing( account, expression, with_hash=False, snap_path=snapshot_dir ) -def test_blindsign_reject_from_blind(app: TezosAppScreen, account: Account, snapshot_dir: Path): +def test_blindsign_reject_from_blind(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path): """Check blindsigning rejection""" expression = MichelineExpr({'int':12345678901234567890123456789012345678901234567890123456789012345678901234567890}) def navigate() -> None: - app.navigate_review(text=ScreenText.ACCEPT_RISK, snap_path=snapshot_dir / "clear") - app.navigate_review(text=ScreenText.SIGN_REJECT, snap_path=snapshot_dir / "blind") + tezos_navigator.navigate_review(text=ScreenText.ACCEPT_RISK, snap_path=snapshot_dir / "clear") + tezos_navigator.navigate_review(text=ScreenText.SIGN_REJECT, snap_path=snapshot_dir / "blind") with StatusCode.REJECT.expected(): - app.sign( + tezos_navigator.sign( account, expression, with_hash=False, diff --git a/tests/integration/nano/test_sign/test_key.py b/tests/integration/nano/test_sign/test_key.py index 1db218a6d..680f9a4f4 100644 --- a/tests/integration/nano/test_sign/test_key.py +++ b/tests/integration/nano/test_sign/test_key.py @@ -21,8 +21,9 @@ import pytest from utils.account import Account, SigType -from utils.app import TezosAppScreen from utils.message import MichelineExpr, Transaction +from utils.navigator import TezosNavigator + @pytest.mark.parametrize( "account", [ @@ -41,15 +42,17 @@ ], ids=lambda account: f"{account.sig_type}" ) -def test_sign_micheline_basic(app: TezosAppScreen, account: Account, snapshot_dir: Path): +def test_sign_micheline_basic(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path): """Check signing with ed25519""" message = MichelineExpr([{'string': 'CACA'}, {'string': 'POPO'}, {'string': 'BOUDIN'}]) - data = app.sign(account, - message, - with_hash=True, - snap_path=snapshot_dir) + data = tezos_navigator.sign( + account, + message, + with_hash=True, + snap_path=snapshot_dir + ) account.check_signature( message=message, @@ -63,10 +66,10 @@ def test_sign_micheline_basic(app: TezosAppScreen, account: Account, snapshot_di ], ids=["seed21"] ) -def test_sign_with_another_seed(app: TezosAppScreen, snapshot_dir: Path): +def test_sign_with_another_seed(tezos_navigator: TezosNavigator, snapshot_dir: Path): """Check signing using another seed than [zebra*24]""" - app.toggle_expert_mode() + tezos_navigator.toggle_expert_mode() account = Account("m/44'/1729'/0'/0'", SigType.ED25519, @@ -84,10 +87,12 @@ def test_sign_with_another_seed(app: TezosAppScreen, snapshot_dir: Path): parameter = {'prim': 'CAR'} ) - data = app.sign(account, - message, - with_hash=True, - snap_path=snapshot_dir) + data = tezos_navigator.sign( + account, + message, + with_hash=True, + snap_path=snapshot_dir + ) account.check_signature( message=message, diff --git a/tests/integration/nano/test_sign/test_parsing_errors.py b/tests/integration/nano/test_sign/test_parsing_errors.py index 766df7453..fcd152cca 100755 --- a/tests/integration/nano/test_sign/test_parsing_errors.py +++ b/tests/integration/nano/test_sign/test_parsing_errors.py @@ -21,9 +21,10 @@ import pytest from utils.account import Account -from utils.app import ScreenText, TezosAppScreen from utils.backend import StatusCode from utils.message import RawMessage +from utils.navigator import ScreenText, TezosNavigator + # Operation (0): Transaction # Source: tz2JPgTWZZpxZZLqHMfS69UAy1UHm4Aw5iHu @@ -54,13 +55,13 @@ "one_byte_added_inside", ] ) -def test_parsing_error(app: TezosAppScreen, raw_msg: str, account: Account, snapshot_dir: Path): +def test_parsing_error(tezos_navigator: TezosNavigator, raw_msg: str, account: Account, snapshot_dir: Path): """Check parsing error handling""" - app.toggle_expert_mode() + tezos_navigator.toggle_expert_mode() with StatusCode.PARSE_ERROR.expected(): - app.reject_signing( + tezos_navigator.reject_signing( account, RawMessage(raw_msg), with_hash=True, @@ -75,17 +76,17 @@ def test_parsing_error(app: TezosAppScreen, raw_msg: str, account: Account, snap "wrong_last_packet", ] ) -def test_parsing_hard_fail(app: TezosAppScreen, raw_msg: str, account: Account, snapshot_dir: Path): +def test_parsing_hard_fail(tezos_navigator: TezosNavigator, raw_msg: str, account: Account, snapshot_dir: Path): """Check parsing error hard failing""" - app.toggle_expert_mode() + tezos_navigator.toggle_expert_mode() with StatusCode.UNEXPECTED_SIGN_STATE.expected(): - app.sign( + tezos_navigator.sign( account, RawMessage(raw_msg), with_hash=True, - navigate=lambda: app.navigate_review( + navigate=lambda: tezos_navigator.navigate_review( text=ScreenText.HOME, snap_path=snapshot_dir ) diff --git a/tests/integration/nano/test_version.py b/tests/integration/nano/test_version.py index 021237055..e394df716 100755 --- a/tests/integration/nano/test_version.py +++ b/tests/integration/nano/test_version.py @@ -18,15 +18,14 @@ import git -from utils.app import TezosAppScreen -from utils.backend import Version +from utils.backend import TezosBackend, Version -def test_version(app: TezosAppScreen): +def test_version(backend: TezosBackend): """Test that the app version is the same as the current version.""" current_version = Version(Version.AppKind.WALLET, 3, 0, 5) - data = app.backend.version() + data = backend.version() app_version = Version.from_bytes(data) @@ -34,7 +33,7 @@ def test_version(app: TezosAppScreen): f"Expected {current_version} but got {app_version}" -def test_git(app: TezosAppScreen): +def test_git(backend: TezosBackend): """Test that the app commit is the same as the current git commit.""" git_repo = git.Repo(search_parent_directories=True) git_describe = git_repo.git.describe( @@ -46,7 +45,7 @@ def test_git(app: TezosAppScreen): ) current_commit = git_describe.replace('-dirty', '*') - data = app.backend.git() + data = backend.git() assert data.endswith(b'\x00'), \ f"Should end with by '\x00' but got {data.hex()}" diff --git a/tests/integration/nano/test_wrong_apdu.py b/tests/integration/nano/test_wrong_apdu.py index 7715ae6a8..1bc728668 100644 --- a/tests/integration/nano/test_wrong_apdu.py +++ b/tests/integration/nano/test_wrong_apdu.py @@ -22,19 +22,24 @@ import pytest from utils.account import Account, SigType -from utils.app import TezosAppScreen -from utils.backend import Cla, Index, Ins, StatusCode +from utils.backend import Cla, TezosBackend, Index, Ins, StatusCode from utils.message import Transaction +from utils.navigator import TezosNavigator -def test_regression_continue_after_reject(app: TezosAppScreen, account: Account, snapshot_dir: Path): + +def test_regression_continue_after_reject( + backend: TezosBackend, + tezos_navigator: TezosNavigator, + account: Account, + snapshot_dir: Path): """Check the app still runs after rejects signing""" - app.toggle_expert_mode() + tezos_navigator.toggle_expert_mode() with StatusCode.REJECT.expected(): - app.reject_public_key(account, snap_path=snapshot_dir / "reject_public_key") + tezos_navigator.reject_public_key(account, snap_path=snapshot_dir / "reject_public_key") - app.backend.wait_for_home_screen() + backend.wait_for_home_screen() message = Transaction( source = 'tz1ixvCiPJYyMjsp2nKBVaq54f6AdbV8hCKa', @@ -49,15 +54,17 @@ def test_regression_continue_after_reject(app: TezosAppScreen, account: Account, ) with StatusCode.REJECT.expected(): - app.reject_signing(account, - message, - with_hash=True, - snap_path=snapshot_dir / "reject_signing") + tezos_navigator.reject_signing( + account, + message, + with_hash=True, + snap_path=snapshot_dir / "reject_signing" + ) - app.backend.get_public_key(account, with_prompt=False) + backend.get_public_key(account, with_prompt=False) -def test_change_sign_instruction(app: TezosAppScreen, account: Account): +def test_change_sign_instruction(backend: TezosBackend, account: Account): """Check signing instruction changes behaviour""" message = Transaction( @@ -73,66 +80,70 @@ def test_change_sign_instruction(app: TezosAppScreen, account: Account): ) payload=bytes(message) - app.backend._ask_sign(Ins.SIGN_WITH_HASH, account) + backend._ask_sign(Ins.SIGN_WITH_HASH, account) with StatusCode.INVALID_INS.expected(): - app.backend._continue_sign(Ins.SIGN, - payload, - last=True) + backend._continue_sign( + Ins.SIGN, + payload, + last=True) - app.backend._ask_sign(Ins.SIGN, account) + backend._ask_sign(Ins.SIGN, account) with StatusCode.INVALID_INS.expected(): - app.backend._continue_sign(Ins.SIGN_WITH_HASH, - payload, - last=True) + backend._continue_sign( + Ins.SIGN_WITH_HASH, + payload, + last=True) -def test_mixing_command(app: TezosAppScreen, account: Account): +def test_mixing_command(backend: TezosBackend, account: Account): """Check that mixing instruction fails""" - app.backend._ask_sign(Ins.SIGN, account) + backend._ask_sign(Ins.SIGN, account) with StatusCode.UNEXPECTED_STATE.expected(): - app.backend.version() + backend.version() - app.backend._ask_sign(Ins.SIGN_WITH_HASH, account) + backend._ask_sign(Ins.SIGN_WITH_HASH, account) with StatusCode.UNEXPECTED_STATE.expected(): - app.backend._ask_sign(Ins.SIGN, account) + backend._ask_sign(Ins.SIGN, account) - app.backend._ask_sign(Ins.SIGN, account) + backend._ask_sign(Ins.SIGN, account) with StatusCode.UNEXPECTED_STATE.expected(): - app.backend._ask_sign(Ins.SIGN_WITH_HASH, account) + backend._ask_sign(Ins.SIGN_WITH_HASH, account) - app.backend._ask_sign(Ins.SIGN, account) + backend._ask_sign(Ins.SIGN, account) with StatusCode.UNEXPECTED_STATE.expected(): - app.backend.get_public_key(account, with_prompt=True) + backend.get_public_key(account, with_prompt=True) - app.backend._ask_sign(Ins.SIGN, account) + backend._ask_sign(Ins.SIGN, account) with StatusCode.UNEXPECTED_STATE.expected(): - app.backend.get_public_key(account, with_prompt=False) + backend.get_public_key(account, with_prompt=False) - app.backend._ask_sign(Ins.SIGN, account) + backend._ask_sign(Ins.SIGN, account) with StatusCode.UNEXPECTED_STATE.expected(): - app.backend.git() + backend.git() @pytest.mark.parametrize("ins", [Ins.GET_PUBLIC_KEY, Ins.PROMPT_PUBLIC_KEY], ids=lambda ins: f"{ins}") @pytest.mark.parametrize("index", [Index.OTHER, Index.LAST], ids=lambda index: f"{index}") -def test_wrong_index(app: TezosAppScreen, account: Account, ins: Ins, index: Index): +def test_wrong_index(backend: TezosBackend, account: Account, ins: Ins, index: Index): """Check wrong apdu index behaviour""" with StatusCode.WRONG_PARAM.expected(): - app.backend._exchange(ins, - index=index, - sig_type=account.sig_type, - payload=account.path) + backend._exchange( + ins, + index=index, + sig_type=account.sig_type, + payload=account.path + ) @pytest.mark.parametrize( "sender", [ - lambda app, account: app.backend.get_public_key(account, with_prompt=False), - lambda app, account: app.backend.get_public_key(account, with_prompt=True), - lambda app, account: app.backend._ask_sign(Ins.SIGN, account), - lambda app, account: app.backend._ask_sign(Ins.SIGN_WITH_HASH, account) + lambda backend, account: backend.get_public_key(account, with_prompt=False), + lambda backend, account: backend.get_public_key(account, with_prompt=True), + lambda backend, account: backend._ask_sign(Ins.SIGN, account), + lambda backend, account: backend._ask_sign(Ins.SIGN_WITH_HASH, account) ], ids=[ "get_pk_without_prompt", @@ -141,21 +152,21 @@ def test_wrong_index(app: TezosAppScreen, account: Account, ins: Ins, index: Ind "sign_with_hash", ] ) -def test_wrong_derivation_type(app: TezosAppScreen, sender: Callable[[TezosAppScreen, Account], Any]): +def test_wrong_derivation_type(backend: TezosBackend, sender: Callable[[TezosBackend, Account], Any]): """Check wrong derivation type behaviour""" account = Account("m/44'/1729'/0'/0'", 0x04, "__unused__") with StatusCode.WRONG_PARAM.expected(): - sender(app, account) + sender(backend, account) @pytest.mark.parametrize( "sender", [ - lambda app, account: app.backend.get_public_key(account, with_prompt=False), - lambda app, account: app.backend.get_public_key(account, with_prompt=True), - lambda app, account: app.backend._ask_sign(Ins.SIGN, account), - lambda app, account: app.backend._ask_sign(Ins.SIGN_WITH_HASH, account) + lambda backend, account: backend.get_public_key(account, with_prompt=False), + lambda backend, account: backend.get_public_key(account, with_prompt=True), + lambda backend, account: backend._ask_sign(Ins.SIGN, account), + lambda backend, account: backend._ask_sign(Ins.SIGN_WITH_HASH, account) ], ids=[ "get_pk_without_prompt", @@ -187,16 +198,16 @@ def test_wrong_derivation_type(app: TezosAppScreen, sender: Callable[[TezosAppSc ] ) def test_wrong_derivation_path( - app: TezosAppScreen, + backend: TezosBackend, account: Account, - sender: Callable[[TezosAppScreen, Account], Any]): + sender: Callable[[TezosBackend, Account], Any]): """Check wrong derivation path behaviour""" with StatusCode.WRONG_LENGTH_FOR_INS.expected(): - sender(app, account) + sender(backend, account) @pytest.mark.parametrize("class_", [0x00, 0x81]) -def test_wrong_class(app: TezosAppScreen, class_: int): +def test_wrong_class(backend: TezosBackend, class_: int): """Check wrong apdu class behaviour""" raw = \ @@ -207,7 +218,7 @@ def test_wrong_class(app: TezosAppScreen, class_: int): int(0x00).to_bytes(1, 'big') with StatusCode.CLASS.expected(): - app.backend.exchange_raw(raw) + backend.exchange_raw(raw) @pytest.mark.parametrize( "size, data", @@ -217,7 +228,7 @@ def test_wrong_class(app: TezosAppScreen, class_: int): ], ids=lambda param: f"size={param}" if isinstance(param, int) else f"data={param}" ) -def test_wrong_apdu_length(app: TezosAppScreen, size: int, data: bytes): +def test_wrong_apdu_length(backend: TezosBackend, size: int, data: bytes): """Check wrong apdu length behaviour""" raw = \ @@ -229,7 +240,7 @@ def test_wrong_apdu_length(app: TezosAppScreen, size: int, data: bytes): data with StatusCode.WRONG_LENGTH_FOR_INS.expected(): - app.backend.exchange_raw(raw) + backend.exchange_raw(raw) @pytest.mark.parametrize( "ins", @@ -248,8 +259,8 @@ def test_wrong_apdu_length(app: TezosAppScreen, size: int, data: bytes): ], ids=lambda ins: f"ins={ins}" ) -def test_unimplemented_commands(app: TezosAppScreen, ins: Union[int, Ins]): +def test_unimplemented_commands(backend: TezosBackend, ins: Union[int, Ins]): """Check unimplemented commands""" with StatusCode.INVALID_INS.expected(): - app.backend._exchange(ins) + backend._exchange(ins) diff --git a/tests/integration/nano/utils/backend.py b/tests/integration/nano/utils/backend.py index 4912226ae..6a87676b0 100644 --- a/tests/integration/nano/utils/backend.py +++ b/tests/integration/nano/utils/backend.py @@ -16,9 +16,11 @@ from contextlib import contextmanager from enum import IntEnum +import time from struct import unpack from typing import Generator, Union +from ragger.backend import SpeculosBackend from ragger.backend.interface import BackendInterface, RAPDU from ragger.error import ExceptionRAPDU @@ -238,3 +240,44 @@ def sign(self, assert not data, f"No data expected but got {data.hex()}" assert False, "We should have already returned" + +MAX_ATTEMPTS = 50 + +def with_retry(f, attempts=MAX_ATTEMPTS): + """Try f until it succeeds or has been executed attempts times.""" + while True: + try: + return f() + except Exception as e: + if attempts <= 0: + print("- with_retry: attempts exhausted -") + raise e + attempts -= 1 + # Give plenty of time for speculos to update - can take a long time on CI machines + time.sleep(0.5) + +class SpeculosTezosBackend(TezosBackend, SpeculosBackend): + """Class representing Tezos app running on Speculos.""" + + # speculos can be slow to start up in a slow environment. + # Here, we expect a little more + def __enter__(self) -> "SpeculosTezosBackend": + try: + super().__enter__() + return self + except Exception: + process = self._client.process + try: + with_retry(self._client._wait_until_ready, attempts=5) + super().__enter__() + except Exception as e: + self._client.stop() + # do not forget to close the first process + self._client.process = process + self._client.stop() + raise e + # replace the new process by the first one + self._client.process.kill() + self._client.process.wait() + self._client.process = process + return self diff --git a/tests/integration/nano/utils/app.py b/tests/integration/nano/utils/navigator.py similarity index 77% rename from tests/integration/nano/utils/app.py rename to tests/integration/nano/utils/navigator.py index ce64a14d8..b67f228c4 100644 --- a/tests/integration/nano/utils/app.py +++ b/tests/integration/nano/utils/navigator.py @@ -16,35 +16,19 @@ """Tezos app backend.""" from enum import Enum -from io import BytesIO from multiprocessing.pool import ThreadPool from pathlib import Path import time from typing import Callable, List, Optional, TypeVar, Union -from ragger.backend import SpeculosBackend -from ragger.navigator import NavIns, NavInsID, NanoNavigator +from ragger.firmware import Firmware +from ragger.navigator import NavIns, NavInsID, Navigator from .message import Message from .account import Account, SigType from .backend import TezosBackend -MAX_ATTEMPTS = 50 - -def with_retry(f, attempts=MAX_ATTEMPTS): - """Try f until it succeeds or has been executed attempts times.""" - while True: - try: - return f() - except Exception as e: - if attempts <= 0: - print("- with_retry: attempts exhausted -") - raise e - attempts -= 1 - # Give plenty of time for speculos to update - can take a long time on CI machines - time.sleep(0.5) - RESPONSE = TypeVar('RESPONSE') def send_and_navigate( @@ -76,32 +60,6 @@ def send_and_navigate( return result -class SpeculosTezosBackend(TezosBackend, SpeculosBackend): - """Class representing Tezos app running on Speculos.""" - - # speculos can be slow to start up in a slow environment. - # Here, we expect a little more - def __enter__(self) -> "SpeculosTezosBackend": - try: - super().__enter__() - return self - except Exception: - process = self._client.process - try: - with_retry(self._client._wait_until_ready, attempts=5) - super().__enter__() - except Exception as e: - self._client.stop() - # do not forget to close the first process - self._client.process = process - self._client.stop() - raise e - # replace the new process by the first one - self._client.process.kill() - self._client.process.wait() - self._client.process = process - return self - class ScreenText(str, Enum): """Class representing common, known app screen's text.""" @@ -117,40 +75,34 @@ class ScreenText(str, Enum): BLINDSIGN_NANOS = "Blindsign" @classmethod - def blindsign(cls, backend: SpeculosTezosBackend) -> "ScreenText": + def blindsign(cls, backend: TezosBackend) -> "ScreenText": """Get blindsign text depending on device.""" - if backend.firmware.device == "nanos": + if backend.firmware == Firmware.NANOS: return cls.BLINDSIGN_NANOS return cls.BLINDSIGN -class TezosAppScreen(): - """Class representing Tezos app management.""" - backend: SpeculosTezosBackend +class TezosNavigator(): + """Class representing Tezos app navigation.""" + + _backend: TezosBackend _root_dir: Path - navigator: NanoNavigator + _navigator: Navigator def __init__(self, - backend: SpeculosTezosBackend, - golden_run: bool): - self.backend = backend + backend: TezosBackend, + navigator: Navigator): + self._backend = backend self._root_dir = Path(__file__).resolve().parent.parent - self.navigator = NanoNavigator(backend, backend.firmware, golden_run) - - def __enter__(self) -> "TezosAppScreen": - with_retry(self.backend.__enter__, attempts=3) - return self - - def __exit__(self, *args): - self.backend.__exit__(*args) + self._navigator = navigator def navigate(self, snap_path: Optional[Path] = None, screen_change_before_first_instruction: bool = False, **kwargs) -> None: """Wrapper of `navigator.navigate_and_compare`""" - self.navigator.navigate_and_compare( + self._navigator.navigate_and_compare( path=self._root_dir, test_case_name=snap_path, screen_change_before_first_instruction=screen_change_before_first_instruction, @@ -162,7 +114,7 @@ def navigate_until_text(self, screen_change_before_first_instruction: bool = False, **kwargs) -> None: """Wrapper of `navigator.navigate_until_text_and_compare`""" - self.navigator.navigate_until_text_and_compare( + self._navigator.navigate_until_text_and_compare( path=self._root_dir, test_case_name=snap_path, screen_change_before_first_instruction=screen_change_before_first_instruction, @@ -184,8 +136,8 @@ def unsafe_navigate( Function based on `ragger.navigator.navigate_and_compare` """ - self.backend.pause_ticker() - self.navigator._run_instruction( + self._backend.pause_ticker() + self._navigator._run_instruction( NavIns(NavInsID.WAIT, (0, )), timeout, wait_for_screen_change=screen_change_before_first_instruction, @@ -195,7 +147,7 @@ def unsafe_navigate( ) for idx, instruction in enumerate(instructions): if idx + 1 != len(instructions) or screen_change_after_last_instruction: - self.navigator._run_instruction( + self._navigator._run_instruction( instruction, timeout, wait_for_screen_change=False, @@ -204,13 +156,13 @@ def unsafe_navigate( snap_idx=snap_start_idx + idx + 1 ) else: - self.navigator._run_instruction( + self._navigator._run_instruction( instruction, timeout, wait_for_screen_change=False, snap_idx=snap_start_idx + idx + 1 ) - self.backend.resume_ticker() + self._backend.resume_ticker() def navigate_to_settings(self, **kwargs) -> int: """Navigate from Home screen to settings.""" @@ -290,7 +242,7 @@ def provide_public_key(self, def navigate(): self.navigate_review(text=ScreenText.PUBLIC_KEY_APPROVE, **kwargs) return send_and_navigate( - send=lambda: self.backend.get_public_key(account, with_prompt=True), + send=lambda: self._backend.get_public_key(account, with_prompt=True), navigate=navigate ) @@ -311,7 +263,7 @@ def sign(self, def navigate(): self.navigate_review(text=ScreenText.SIGN_ACCEPT, **kwargs) return send_and_navigate( - send=lambda: self.backend.sign(account, message, with_hash), + send=lambda: self._backend.sign(account, message, with_hash), navigate=navigate )