diff --git a/tests/integration/nano/conftest.py b/tests/integration/nano/conftest.py index dddd236a7..bc63e20b9 100644 --- a/tests/integration/nano/conftest.py +++ b/tests/integration/nano/conftest.py @@ -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, @@ -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.""" @@ -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: @@ -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 : 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 c175568dc..af87647fa 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 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'", @@ -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, 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) 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 cc1270013..63b0c58c0 100755 --- a/tests/integration/nano/test_sign/operations/test_sign_ballot.py +++ b/tests/integration/nano/test_sign/operations/test_sign_ballot.py @@ -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( @@ -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, 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 2a31707f7..d40e0a247 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 @@ -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( @@ -57,10 +58,12 @@ 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, @@ -68,10 +71,10 @@ def test_nanos_regression_batched_ops(app: TezosAppScreen, snapshot_dir: Path): 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( @@ -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( @@ -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, 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 acf55cd50..2be9e3679 100755 --- a/tests/integration/nano/test_sign/operations/test_sign_delegation.py +++ b/tests/integration/nano/test_sign/operations/test_sign_delegation.py @@ -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( @@ -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, 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 de1233ef6..77f95bb53 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 @@ -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, 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 ade361c0b..dd1319084 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 @@ -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( @@ -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, 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 53a6a92f7..e70467474 100755 --- a/tests/integration/nano/test_sign/operations/test_sign_origination.py +++ b/tests/integration/nano/test_sign/operations/test_sign_origination.py @@ -18,13 +18,14 @@ from pathlib import Path -from utils.app import TezosAppScreen, DEFAULT_ACCOUNT from utils.message import Origination +from utils.navigator import TezosNavigator, DEFAULT_ACCOUNT -def test_sign_origination(app: TezosAppScreen, snapshot_dir: Path): + +def test_sign_origination(tezos_navigator: TezosNavigator, snapshot_dir: Path): """Check signing origination""" - app.toggle_expert_mode() + tezos_navigator.toggle_expert_mode() message = Origination( source = 'tz1ixvCiPJYyMjsp2nKBVaq54f6AdbV8hCKa', @@ -37,10 +38,12 @@ def test_sign_origination(app: TezosAppScreen, snapshot_dir: Path): balance = 500000 ) - 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, 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 2662a796d..2bc0e83ad 100755 --- a/tests/integration/nano/test_sign/operations/test_sign_proposals.py +++ b/tests/integration/nano/test_sign/operations/test_sign_proposals.py @@ -18,10 +18,11 @@ from pathlib import Path -from utils.app import Screen, TezosAppScreen, DEFAULT_ACCOUNT from utils.message import Proposals +from utils.navigator import TezosNavigator, DEFAULT_ACCOUNT -def test_sign_proposals(app: TezosAppScreen, snapshot_dir: Path): + +def test_sign_proposals(tezos_navigator: TezosNavigator, snapshot_dir: Path): """Check signing proposals""" message = Proposals( @@ -33,10 +34,12 @@ def test_sign_proposals(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, 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 ef485011f..60620860d 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 @@ -18,13 +18,14 @@ from pathlib import Path -from utils.app import TezosAppScreen, DEFAULT_ACCOUNT from utils.message import RegisterGlobalConstant +from utils.navigator import TezosNavigator, DEFAULT_ACCOUNT -def test_sign_register_global_constant(app: TezosAppScreen, snapshot_dir: Path): + +def test_sign_register_global_constant(tezos_navigator: TezosNavigator, snapshot_dir: Path): """Check signing register global constant""" - app.toggle_expert_mode() + tezos_navigator.toggle_expert_mode() message = RegisterGlobalConstant( source = 'tz1ixvCiPJYyMjsp2nKBVaq54f6AdbV8hCKa', @@ -35,10 +36,12 @@ def test_sign_register_global_constant(app: TezosAppScreen, snapshot_dir: Path): value = {'prim': 'Pair', 'args': [{'string': '1'}, {'int': 2}]} ) - 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, 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 ad8e4f827..6cd0418bd 100755 --- a/tests/integration/nano/test_sign/operations/test_sign_reveal.py +++ b/tests/integration/nano/test_sign/operations/test_sign_reveal.py @@ -18,10 +18,11 @@ from pathlib import Path -from utils.app import Screen, TezosAppScreen, DEFAULT_ACCOUNT from utils.message import Reveal +from utils.navigator import TezosNavigator, DEFAULT_ACCOUNT -def test_sign_reveal(app: TezosAppScreen, snapshot_dir: Path): + +def test_sign_reveal(tezos_navigator: TezosNavigator, snapshot_dir: Path): """Check signing reveal""" message = Reveal( @@ -33,10 +34,12 @@ def test_sign_reveal(app: TezosAppScreen, snapshot_dir: Path): public_key = 'edpkuXX2VdkdXzkN11oLCb8Aurdo1BTAtQiK8ZY9UPj2YMt3AHEpcY' ) - 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, 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 519a7150a..08445362a 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 @@ -18,10 +18,11 @@ from pathlib import Path -from utils.app import Screen, TezosAppScreen, DEFAULT_ACCOUNT from utils.message import ScRollupAddMessage +from utils.navigator import TezosNavigator, DEFAULT_ACCOUNT -def test_sign_sc_rollup_add_messages(app: TezosAppScreen, snapshot_dir: Path): + +def test_sign_sc_rollup_add_messages(tezos_navigator: TezosNavigator, snapshot_dir: Path): """Check signing smart rollup add message""" message = ScRollupAddMessage( @@ -33,10 +34,12 @@ def test_sign_sc_rollup_add_messages(app: TezosAppScreen, snapshot_dir: Path): message = [bytes.fromhex('012345'), bytes.fromhex('67'), bytes.fromhex('89abcdef')] ) - 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, 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 f391921a2..4fea4df2f 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 @@ -18,13 +18,14 @@ from pathlib import Path -from utils.app import TezosAppScreen, DEFAULT_ACCOUNT from utils.message import ScRollupExecuteOutboxMessage +from utils.navigator import TezosNavigator, DEFAULT_ACCOUNT -def test_sign_sc_rollup_execute_outbox_message(app: TezosAppScreen, snapshot_dir: Path): + +def test_sign_sc_rollup_execute_outbox_message(tezos_navigator: TezosNavigator, snapshot_dir: Path): """Check signing smart rollup execute outbox message""" - app.toggle_expert_mode() + tezos_navigator.toggle_expert_mode() message = ScRollupExecuteOutboxMessage( source = 'tz1ixvCiPJYyMjsp2nKBVaq54f6AdbV8hCKa', @@ -37,10 +38,12 @@ def test_sign_sc_rollup_execute_outbox_message(app: TezosAppScreen, snapshot_dir output_proof = b'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, 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 0e9e1c12a..e958f87c7 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 @@ -21,8 +21,8 @@ import pytest -from utils.app import TezosAppScreen, DEFAULT_ACCOUNT from utils.message import ScRollupOriginate +from utils.navigator import TezosNavigator, DEFAULT_ACCOUNT @pytest.mark.parametrize( @@ -41,10 +41,10 @@ "with_whitelist", ], ) -def test_sign_sc_rollup_originate(app: TezosAppScreen, whitelist: Optional[List[str]], snapshot_dir: Path): +def test_sign_sc_rollup_originate(tezos_navigator: TezosNavigator, 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', @@ -58,10 +58,12 @@ def test_sign_sc_rollup_originate(app: TezosAppScreen, whitelist: Optional[List[ whitelist = whitelist ) - 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, 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 2077d1cde..0d1b0fb52 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 @@ -18,10 +18,11 @@ from pathlib import Path -from utils.app import Screen, TezosAppScreen, DEFAULT_ACCOUNT from utils.message import UpdateConsensusKey +from utils.navigator import TezosNavigator, DEFAULT_ACCOUNT -def test_sign_set_consensus_key(app: TezosAppScreen, snapshot_dir: Path): + +def test_sign_set_consensus_key(tezos_navigator: TezosNavigator, snapshot_dir: Path): """Check signing set consensus key""" message = UpdateConsensusKey( @@ -33,10 +34,12 @@ def test_sign_set_consensus_key(app: TezosAppScreen, snapshot_dir: Path): pk = "edpkuXX2VdkdXzkN11oLCb8Aurdo1BTAtQiK8ZY9UPj2YMt3AHEpcY" ) - 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, 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 6ce1ad6cb..34b052839 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 @@ -18,10 +18,11 @@ from pathlib import Path -from utils.app import Screen, TezosAppScreen, DEFAULT_ACCOUNT from utils.message import SetDepositLimit +from utils.navigator import TezosNavigator, DEFAULT_ACCOUNT -def test_sign_set_deposit_limit(app: TezosAppScreen, snapshot_dir: Path): + +def test_sign_set_deposit_limit(tezos_navigator: TezosNavigator, snapshot_dir: Path): """Check signing set deposit limit""" message = SetDepositLimit( @@ -33,10 +34,12 @@ def test_sign_set_deposit_limit(app: TezosAppScreen, snapshot_dir: Path): limit = 20000 ) - 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, 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 dd3843ece..0f2ec8307 100755 --- a/tests/integration/nano/test_sign/operations/test_sign_transaction.py +++ b/tests/integration/nano/test_sign/operations/test_sign_transaction.py @@ -18,14 +18,15 @@ from pathlib import Path -from utils.app import Screen, ScreenText, TezosAppScreen, DEFAULT_ACCOUNT from utils.backend import StatusCode from utils.message import Transaction +from utils.navigator import ScreenText, TezosNavigator, DEFAULT_ACCOUNT -def test_sign_transaction(app: TezosAppScreen, snapshot_dir: Path): + +def test_sign_transaction(tezos_navigator: TezosNavigator, snapshot_dir: Path): """Check signing transaction""" - app.toggle_expert_mode() + tezos_navigator.toggle_expert_mode() message = Transaction( source = 'tz2JPgTWZZpxZZLqHMfS69UAy1UHm4Aw5iHu', @@ -39,20 +40,22 @@ def test_sign_transaction(app: TezosAppScreen, snapshot_dir: Path): parameter = {'prim': 'CAR'} ) - 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_reject_transaction(app: TezosAppScreen, snapshot_dir: Path): +def test_reject_transaction(tezos_navigator: TezosNavigator, snapshot_dir: Path): """Check reject transaction""" - app.toggle_expert_mode() + tezos_navigator.toggle_expert_mode() message = Transaction( source = 'tz1ixvCiPJYyMjsp2nKBVaq54f6AdbV8hCKa', @@ -67,15 +70,17 @@ def test_reject_transaction(app: TezosAppScreen, snapshot_dir: Path): ) with StatusCode.REJECT.expected(): - app.reject_signing(DEFAULT_ACCOUNT, - message, - with_hash=True, - snap_path=snapshot_dir) + tezos_navigator.reject_signing( + DEFAULT_ACCOUNT, + message, + with_hash=True, + snap_path=snapshot_dir + ) -def test_sign_simple_transaction(app: TezosAppScreen, snapshot_dir: Path): +def test_sign_simple_transaction(tezos_navigator: TezosNavigator, snapshot_dir: Path): """Check sign not complex transaction""" - app.toggle_expert_mode() + tezos_navigator.toggle_expert_mode() message = Transaction( source = 'tz1ixvCiPJYyMjsp2nKBVaq54f6AdbV8hCKa', @@ -87,17 +92,19 @@ def test_sign_simple_transaction(app: TezosAppScreen, snapshot_dir: Path): amount = 10000 ) - 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_too_complex_transaction(app: TezosAppScreen, snapshot_dir: Path): +def test_too_complex_transaction(tezos_navigator: TezosNavigator, snapshot_dir: Path): """Check sign complex transaction""" message = Transaction( @@ -113,17 +120,17 @@ def test_too_complex_transaction(app: TezosAppScreen, snapshot_dir: Path): ) with StatusCode.REJECT.expected(): - app.sign( + tezos_navigator.sign( DEFAULT_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, snapshot_dir: Path): +def test_sign_stake_transaction(tezos_navigator: TezosNavigator, snapshot_dir: Path): """Check sign stake""" - app.toggle_expert_mode() + tezos_navigator.toggle_expert_mode() message = Transaction( source = 'tz2WmivuMG8MMRKMEmzKRMMxMApxZQWYNS4W', @@ -136,20 +143,22 @@ def test_sign_stake_transaction(app: TezosAppScreen, snapshot_dir: Path): entrypoint = 'stake', ) - 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_unstake_transaction(app: TezosAppScreen, snapshot_dir: Path): +def test_sign_unstake_transaction(tezos_navigator: TezosNavigator, snapshot_dir: Path): """Check sign unstake""" - app.toggle_expert_mode() + tezos_navigator.toggle_expert_mode() message = Transaction( source = 'tz2WmivuMG8MMRKMEmzKRMMxMApxZQWYNS4W', @@ -162,20 +171,22 @@ def test_sign_unstake_transaction(app: TezosAppScreen, snapshot_dir: Path): entrypoint = 'unstake' ) - 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_finalize_unstake_transaction(app: TezosAppScreen, snapshot_dir: Path): +def test_sign_finalize_unstake_transaction(tezos_navigator: TezosNavigator, snapshot_dir: Path): """Check sign finalize_unstake""" - app.toggle_expert_mode() + tezos_navigator.toggle_expert_mode() message = Transaction( source = 'tz2WmivuMG8MMRKMEmzKRMMxMApxZQWYNS4W', @@ -188,20 +199,22 @@ def test_sign_finalize_unstake_transaction(app: TezosAppScreen, snapshot_dir: Pa entrypoint = 'finalize_unstake' ) - 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_set_delegate_parameters_transaction(app: TezosAppScreen, snapshot_dir: Path): +def test_sign_set_delegate_parameters_transaction(tezos_navigator: TezosNavigator, snapshot_dir: Path): """Check sign set delegate parameters""" - app.toggle_expert_mode() + tezos_navigator.toggle_expert_mode() message = Transaction( source = 'tz2WmivuMG8MMRKMEmzKRMMxMApxZQWYNS4W', @@ -223,20 +236,22 @@ def test_sign_set_delegate_parameters_transaction(app: TezosAppScreen, snapshot_ ]} ) - 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_with_long_hash(app: TezosAppScreen, snapshot_dir: Path): +def test_sign_with_long_hash(tezos_navigator: TezosNavigator, snapshot_dir: Path): """Check signing transaction with a long destination hash""" - app.toggle_expert_mode() + tezos_navigator.toggle_expert_mode() message = Transaction( source = 'tz1ixvCiPJYyMjsp2nKBVaq54f6AdbV8hCKa', @@ -250,20 +265,22 @@ def test_sign_with_long_hash(app: TezosAppScreen, snapshot_dir: Path): parameter = {'int': 0} ) - 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_ensure_always_clearsign(app: TezosAppScreen, snapshot_dir: Path): +def test_ensure_always_clearsign(tezos_navigator: TezosNavigator, snapshot_dir: Path): """Check clear signing never blindsign""" - app.toggle_expert_mode() + tezos_navigator.toggle_expert_mode() message = Transaction( source = 'tz1ixvCiPJYyMjsp2nKBVaq54f6AdbV8hCKa', @@ -277,10 +294,12 @@ def test_ensure_always_clearsign(app: TezosAppScreen, snapshot_dir: Path): 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(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, 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 6ba362b2a..d76bb87b2 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 @@ -19,13 +19,14 @@ from pathlib import Path from conftest import requires_device -from utils.app import TezosAppScreen, DEFAULT_ACCOUNT from utils.message import TransferTicket +from utils.navigator import TezosNavigator, DEFAULT_ACCOUNT -def test_sign_transfer_ticket(app: TezosAppScreen, snapshot_dir: Path): + +def test_sign_transfer_ticket(tezos_navigator: TezosNavigator, snapshot_dir: Path): """Check signing transfer ticket""" - app.toggle_expert_mode() + tezos_navigator.toggle_expert_mode() message = TransferTicket( source = 'tz1ixvCiPJYyMjsp2nKBVaq54f6AdbV8hCKa', @@ -40,10 +41,12 @@ def test_sign_transfer_ticket(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, @@ -51,10 +54,10 @@ def test_sign_transfer_ticket(app: TezosAppScreen, snapshot_dir: Path): data=data) @requires_device("nanosp") -def test_nanosp_regression_potential_empty_screen(app: TezosAppScreen, snapshot_dir: Path): +def test_nanosp_regression_potential_empty_screen(tezos_navigator: TezosNavigator, snapshot_dir: Path): """Check signing operation that display potentially empty screens""" - app.toggle_expert_mode() + tezos_navigator.toggle_expert_mode() message = TransferTicket( source = 'tz1ixvCiPJYyMjsp2nKBVaq54f6AdbV8hCKa', @@ -70,10 +73,12 @@ def test_nanosp_regression_potential_empty_screen(app: TezosAppScreen, snapshot_ entrypoint = 'S\n\nS\nS\nS' ) - 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, diff --git a/tests/integration/nano/test_sign/test_apdu_sign.py b/tests/integration/nano/test_sign/test_apdu_sign.py index 0fa4a89a9..36508b83d 100644 --- a/tests/integration/nano/test_sign/test_apdu_sign.py +++ b/tests/integration/nano/test_sign/test_apdu_sign.py @@ -20,28 +20,35 @@ from conftest import requires_device from utils.account import Account -from utils.app import send_and_navigate, Screen, ScreenText, TezosAppScreen, DEFAULT_ACCOUNT +from utils.backend import TezosBackend from utils.message import Message, MichelineExpr, Transaction +from utils.navigator import send_and_navigate, ScreenText, TezosNavigator, DEFAULT_ACCOUNT -def test_sign_micheline_without_hash(app: TezosAppScreen, snapshot_dir: Path): + +def test_sign_micheline_without_hash(tezos_navigator: TezosNavigator, snapshot_dir: Path): """Check signing micheline wihout getting hash""" message = MichelineExpr([{'string': 'CACA'}, {'string': 'POPO'}, {'string': 'BOUDIN'}]) - data = app.sign(DEFAULT_ACCOUNT, - message, - with_hash=False, - snap_path=snapshot_dir) + data = tezos_navigator.sign( + DEFAULT_ACCOUNT, + message, + with_hash=False, + snap_path=snapshot_dir + ) DEFAULT_ACCOUNT.check_signature( message=message, with_hash=False, data=data) -def test_sign_with_small_packet(app: TezosAppScreen, snapshot_dir: Path): +def test_sign_with_small_packet( + backend: TezosBackend, + tezos_navigator: TezosNavigator, + 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 +56,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 +83,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, snapshot_dir: Path): +def test_nanosp_regression_press_right_works_across_apdu_recieves(tezos_navigator: TezosNavigator, 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, message, navigate) + _sign_too_long(tezos_navigator, message, navigate) def _reject_too_long( - app: TezosAppScreen, + tezos_navigator: TezosNavigator, 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( DEFAULT_ACCOUNT, message, with_hash=True, @@ -154,31 +155,31 @@ def _reject_too_long( ) ]) -def test_sign_basic_too_long_operation(app: TezosAppScreen, snapshot_dir: Path): +def test_sign_basic_too_long_operation(tezos_navigator: TezosNavigator, snapshot_dir: Path): """Check sign too long operation""" - _sign_decodable_too_long(app, BASIC_OPERATION, snapshot_dir) + _sign_decodable_too_long(tezos_navigator, BASIC_OPERATION, snapshot_dir) -def test_reject_basic_too_long_operation_at_warning(app: TezosAppScreen, snapshot_dir: Path): +def test_reject_basic_too_long_operation_at_warning(tezos_navigator: TezosNavigator, 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, BASIC_OPERATION, StatusCode.REJECT, navigate) + _reject_too_long(tezos_navigator, BASIC_OPERATION, StatusCode.REJECT, navigate) -def test_reject_basic_too_long_operation_at_summary(app: TezosAppScreen, snapshot_dir: Path): +def test_reject_basic_too_long_operation_at_summary(tezos_navigator: TezosNavigator, 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, BASIC_OPERATION, StatusCode.REJECT, navigate) + _reject_too_long(tezos_navigator, BASIC_OPERATION, StatusCode.REJECT, navigate) ### Different kind of too long operation ### -def test_sign_too_long_operation_with_only_transactions(app: TezosAppScreen, snapshot_dir: Path): +def test_sign_too_long_operation_with_only_transactions(tezos_navigator: TezosNavigator, snapshot_dir: Path): """Check sign too long operation that contains only transaction""" message = OperationGroup([ Transaction( @@ -236,9 +237,9 @@ def test_sign_too_long_operation_with_only_transactions(app: TezosAppScreen, sna amount = 5000000 ) ]) - _sign_decodable_too_long(app, message, snapshot_dir) + _sign_decodable_too_long(tezos_navigator, message, snapshot_dir) -def test_sign_too_long_operation_without_fee_or_amount(app: TezosAppScreen, snapshot_dir: Path): +def test_sign_too_long_operation_without_fee_or_amount(tezos_navigator: TezosNavigator, snapshot_dir: Path): """Check sign too long operation that doesn't have fees or amount""" message = Proposals( source = 'tz1ixvCiPJYyMjsp2nKBVaq54f6AdbV8hCKa', @@ -266,7 +267,7 @@ def test_sign_too_long_operation_without_fee_or_amount(app: TezosAppScreen, snap ], period = 32 ) - _sign_decodable_too_long(app, message, snapshot_dir) + _sign_decodable_too_long(tezos_navigator, message, snapshot_dir) ### Too long operation containing a too large number ### @@ -321,39 +322,43 @@ def test_sign_too_long_operation_without_fee_or_amount(app: TezosAppScreen, snap ) ]) -def test_sign_too_long_operation_with_too_large(app: TezosAppScreen, snapshot_dir: Path): +def test_sign_too_long_operation_with_too_large(tezos_navigator: TezosNavigator, 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, OPERATION_WITH_TOO_LARGE, navigate) + _sign_too_long(tezos_navigator, OPERATION_WITH_TOO_LARGE, navigate) -def test_reject_too_long_operation_with_too_large_at_too_large_warning(app: TezosAppScreen, snapshot_dir: Path): +def test_reject_too_long_operation_with_too_large_at_too_large_warning(tezos_navigator: TezosNavigator, 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, OPERATION_WITH_TOO_LARGE, StatusCode.PARSE_ERROR, navigate) + _reject_too_long(tezos_navigator, OPERATION_WITH_TOO_LARGE, StatusCode.PARSE_ERROR, navigate) -def test_reject_too_long_operation_with_too_large_at_blindsigning(app: TezosAppScreen, snapshot_dir: Path): +def test_reject_too_long_operation_with_too_large_at_blindsigning(tezos_navigator: TezosNavigator, 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, OPERATION_WITH_TOO_LARGE, StatusCode.REJECT, navigate) + _reject_too_long(tezos_navigator, OPERATION_WITH_TOO_LARGE, StatusCode.REJECT, navigate) -def test_blindsign_too_deep(app: TezosAppScreen, snapshot_dir: Path): +def test_blindsign_too_deep( + backend: TezosBackend, + firmware: Firmware, + tezos_navigator: TezosNavigator, + 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]] = [ @@ -367,18 +372,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( DEFAULT_ACCOUNT, expression, with_hash=True, @@ -390,16 +395,16 @@ def navigate() -> None: with_hash=True, data=data) -def test_blindsign_too_large(app: TezosAppScreen, snapshot_dir: Path): +def test_blindsign_too_large(tezos_navigator: TezosNavigator, 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( DEFAULT_ACCOUNT, message, with_hash=True, @@ -411,30 +416,30 @@ def navigate() -> None: with_hash=True, data=data) -def test_blindsign_reject_from_clear(app: TezosAppScreen, snapshot_dir: Path): +def test_blindsign_reject_from_clear(tezos_navigator: TezosNavigator, snapshot_dir: Path): """Check blindsigning rejection""" expression = MichelineExpr({'int':12345678901234567890123456789012345678901234567890123456789012345678901234567890}) with StatusCode.PARSE_ERROR.expected(): - app.reject_signing( + tezos_navigator.reject_signing( DEFAULT_ACCOUNT, expression, with_hash=False, snap_path=snapshot_dir ) -def test_blindsign_reject_from_blind(app: TezosAppScreen, snapshot_dir: Path): +def test_blindsign_reject_from_blind(tezos_navigator: TezosNavigator, 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( DEFAULT_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 6ad9ead34..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 Screen, 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 6cddb4d15..bd0162ed2 100755 --- a/tests/integration/nano/test_sign/test_parsing_errors.py +++ b/tests/integration/nano/test_sign/test_parsing_errors.py @@ -20,9 +20,10 @@ import pytest -from utils.app import ScreenText, TezosAppScreen, DEFAULT_ACCOUNT from utils.backend import StatusCode from utils.message import RawMessage +from utils.navigator import ScreenText, TezosNavigator, DEFAULT_ACCOUNT + # Operation (0): Transaction # Source: tz2JPgTWZZpxZZLqHMfS69UAy1UHm4Aw5iHu @@ -53,13 +54,13 @@ "one_byte_added_inside", ] ) -def test_parsing_error(app: TezosAppScreen, raw_msg: str, snapshot_dir: Path): +def test_parsing_error(tezos_navigator: TezosNavigator, raw_msg: str, 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( DEFAULT_ACCOUNT, RawMessage(raw_msg), with_hash=True, @@ -74,17 +75,17 @@ def test_parsing_error(app: TezosAppScreen, raw_msg: str, snapshot_dir: Path): "wrong_last_packet", ] ) -def test_parsing_hard_fail(app: TezosAppScreen, raw_msg: str, snapshot_dir: Path): +def test_parsing_hard_fail(tezos_navigator: TezosNavigator, raw_msg: str, 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( DEFAULT_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 2db2f574b..845d85d09 100644 --- a/tests/integration/nano/test_wrong_apdu.py +++ b/tests/integration/nano/test_wrong_apdu.py @@ -22,19 +22,23 @@ import pytest from utils.account import Account, SigType -from utils.app import Screen, TezosAppScreen, DEFAULT_ACCOUNT -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, DEFAULT_ACCOUNT -def test_regression_continue_after_reject(app: TezosAppScreen, snapshot_dir: Path): + +def test_regression_continue_after_reject( + backend: TezosBackend, + tezos_navigator: TezosNavigator, + 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(DEFAULT_ACCOUNT, snap_path=snapshot_dir / "reject_public_key") + tezos_navigator.reject_public_key(DEFAULT_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 +53,17 @@ def test_regression_continue_after_reject(app: TezosAppScreen, snapshot_dir: Pat ) with StatusCode.REJECT.expected(): - app.reject_signing(DEFAULT_ACCOUNT, - message, - with_hash=True, - snap_path=snapshot_dir / "reject_signing") + tezos_navigator.reject_signing( + DEFAULT_ACCOUNT, + message, + with_hash=True, + snap_path=snapshot_dir / "reject_signing" + ) - app.backend.get_public_key(DEFAULT_ACCOUNT, with_prompt=False) + backend.get_public_key(DEFAULT_ACCOUNT, with_prompt=False) -def test_change_sign_instruction(app: TezosAppScreen): +def test_change_sign_instruction(backend: TezosBackend): """Check signing instruction changes behaviour""" message = Transaction( @@ -73,66 +79,70 @@ def test_change_sign_instruction(app: TezosAppScreen): ) payload=bytes(message) - app.backend._ask_sign(Ins.SIGN_WITH_HASH, DEFAULT_ACCOUNT) + backend._ask_sign(Ins.SIGN_WITH_HASH, DEFAULT_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, DEFAULT_ACCOUNT) + backend._ask_sign(Ins.SIGN, DEFAULT_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): +def test_mixing_command(backend: TezosBackend): """Check that mixing instruction fails""" - app.backend._ask_sign(Ins.SIGN, DEFAULT_ACCOUNT) + backend._ask_sign(Ins.SIGN, DEFAULT_ACCOUNT) with StatusCode.UNEXPECTED_STATE.expected(): - app.backend.version() + backend.version() - app.backend._ask_sign(Ins.SIGN_WITH_HASH, DEFAULT_ACCOUNT) + backend._ask_sign(Ins.SIGN_WITH_HASH, DEFAULT_ACCOUNT) with StatusCode.UNEXPECTED_STATE.expected(): - app.backend._ask_sign(Ins.SIGN, DEFAULT_ACCOUNT) + backend._ask_sign(Ins.SIGN, DEFAULT_ACCOUNT) - app.backend._ask_sign(Ins.SIGN, DEFAULT_ACCOUNT) + backend._ask_sign(Ins.SIGN, DEFAULT_ACCOUNT) with StatusCode.UNEXPECTED_STATE.expected(): - app.backend._ask_sign(Ins.SIGN_WITH_HASH, DEFAULT_ACCOUNT) + backend._ask_sign(Ins.SIGN_WITH_HASH, DEFAULT_ACCOUNT) - app.backend._ask_sign(Ins.SIGN, DEFAULT_ACCOUNT) + backend._ask_sign(Ins.SIGN, DEFAULT_ACCOUNT) with StatusCode.UNEXPECTED_STATE.expected(): - app.backend.get_public_key(DEFAULT_ACCOUNT, with_prompt=True) + backend.get_public_key(DEFAULT_ACCOUNT, with_prompt=True) - app.backend._ask_sign(Ins.SIGN, DEFAULT_ACCOUNT) + backend._ask_sign(Ins.SIGN, DEFAULT_ACCOUNT) with StatusCode.UNEXPECTED_STATE.expected(): - app.backend.get_public_key(DEFAULT_ACCOUNT, with_prompt=False) + backend.get_public_key(DEFAULT_ACCOUNT, with_prompt=False) - app.backend._ask_sign(Ins.SIGN, DEFAULT_ACCOUNT) + backend._ask_sign(Ins.SIGN, DEFAULT_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, ins: Ins, index: Index): +def test_wrong_index(backend: TezosBackend, ins: Ins, index: Index): """Check wrong apdu index behaviour""" with StatusCode.WRONG_PARAM.expected(): - app.backend._exchange(ins, - index=index, - sig_type=DEFAULT_ACCOUNT.sig_type, - payload=DEFAULT_ACCOUNT.path) + backend._exchange( + ins, + index=index, + sig_type=DEFAULT_ACCOUNT.sig_type, + payload=DEFAULT_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 +151,21 @@ def test_wrong_index(app: TezosAppScreen, ins: Ins, index: Index): "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 +197,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 +217,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 +227,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 +239,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 +258,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..fb493aff6 100644 --- a/tests/integration/nano/utils/backend.py +++ b/tests/integration/nano/utils/backend.py @@ -19,6 +19,7 @@ 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 +239,30 @@ def sign(self, assert not data, f"No data expected but got {data.hex()}" assert False, "We should have already returned" + + +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: + self._client._wait_until_ready() + 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 64% rename from tests/integration/nano/utils/app.py rename to tests/integration/nano/utils/navigator.py index 5579fe168..501fdb8af 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,47 +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 Screen(str, Enum): - """Class representing common, known app screens.""" - - HOME = "home" - VERSION = "version" - SETTINGS = "settings" - SETTINGS_EXPERT_MODE_DISABLED = "settings_expert_mode_disabled" - SETTINGS_EXPERT_MODE_ENABLED = "settings_expert_mode_enabled" - SETTINGS_BLINDSIGN_ON = "settings_blindsign_on" - SETTINGS_BLINDSIGN_OFF = "settings_blindsign_off" - SETTINGS_BACK = "back" - QUIT = "quit" - - def __str__(self) -> str: - return self.value class ScreenText(str, Enum): """Class representing common, known app screen's text.""" @@ -132,84 +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 - snapshots_dir: Path - tmp_snapshots_dir: Path - snapshotted: List[str] - golden_run: bool - 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.snapshots_dir = self._root_dir / "snapshots" / backend.firmware.name - self.tmp_snapshots_dir = self._root_dir / "snapshots-tmp" / backend.firmware.name - if not self.snapshots_dir.is_dir() and golden_run: - self.snapshots_dir.mkdir(parents=True) - if not self.tmp_snapshots_dir.is_dir(): - self.tmp_snapshots_dir.mkdir(parents=True) - self.snapshotted = [] - - self.golden_run = golden_run - 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) - - def assert_screen(self, - screen: Union[str, Screen], - path: Optional[Union[str, Path]] = None) -> None: - """Check if the screen is the one expected.""" - golden_run = self.golden_run and screen not in self.snapshotted - if golden_run: - self.snapshotted = self.snapshotted + [screen] - input(f"Press ENTER to snapshot {screen}") - - snapshots_dir = self.snapshots_dir if path is None \ - else self.snapshots_dir / path - tmp_snapshots_dir = self.tmp_snapshots_dir if path is None \ - else self.tmp_snapshots_dir / path - - if not snapshots_dir.is_dir() and golden_run: - snapshots_dir.mkdir(parents=True) - if not tmp_snapshots_dir.is_dir(): - tmp_snapshots_dir.mkdir(parents=True) - - path = snapshots_dir / f'{screen}.png' - tmp_path = tmp_snapshots_dir / f'{screen}.png' - def check(): - print(f"- Expecting {screen} -") - assert self.backend.compare_screen_with_snapshot( - path, - tmp_snap_path=tmp_path, - golden_run=golden_run) - - with_retry(check) - self.backend._last_screenshot = BytesIO(self.backend._client.get_screenshot()) + 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, @@ -221,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, @@ -243,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, @@ -254,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, @@ -263,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.""" @@ -349,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 ) @@ -370,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 ) @@ -384,8 +277,6 @@ def navigate(): self.navigate_review(text=ScreenText.SIGN_REJECT, **kwargs) self.sign(account, message, with_hash, navigate) -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' - DEFAULT_ACCOUNT = Account("m/44'/1729'/0'/0'", SigType.ED25519, "edpkuXX2VdkdXzkN11oLCb8Aurdo1BTAtQiK8ZY9UPj2YMt3AHEpcY")