From 80d9f53fdd0d02ddbcec131a222a66d681483a2a Mon Sep 17 00:00:00 2001 From: M1nd3r Date: Mon, 31 Mar 2025 20:26:15 +0200 Subject: [PATCH] fixup! test: update click tests --- .../test_passphrase_bolt_delizia.py | 23 +++++++++++++++--- tests/click_tests/test_passphrase_caesar.py | 24 ++++++++++++++++--- tests/click_tests/test_recovery.py | 22 ++++++++++++----- tests/click_tests/test_repeated_backup.py | 4 +++- tests/click_tests/test_reset_bip39.py | 5 ++-- .../click_tests/test_reset_slip39_advanced.py | 4 +++- tests/click_tests/test_reset_slip39_basic.py | 4 +++- tests/click_tests/test_tutorial_caesar.py | 3 ++- tests/click_tests/test_tutorial_delizia.py | 15 ++++++++---- 9 files changed, 81 insertions(+), 23 deletions(-) diff --git a/tests/click_tests/test_passphrase_bolt_delizia.py b/tests/click_tests/test_passphrase_bolt_delizia.py index 095d1548ee..1bf613814f 100644 --- a/tests/click_tests/test_passphrase_bolt_delizia.py +++ b/tests/click_tests/test_passphrase_bolt_delizia.py @@ -20,9 +20,11 @@ from typing import TYPE_CHECKING, Generator, Optional import pytest -from trezorlib.debuglink import LayoutType +from trezorlib import messages +from trezorlib.debuglink import LayoutType, SessionDebugWrapper as Session +from trezorlib.transport.session import SessionV1 -from ..common import get_test_address +from ..common import TEST_ADDRESS_N from .common import CommonPass, PassphraseCategory, get_char_category if TYPE_CHECKING: @@ -68,12 +70,27 @@ assert len(DA_51) == 51 assert DA_51_ADDRESS == DA_50_ADDRESS +def _get_test_address(session: Session) -> None: + resp = session.call_raw( + messages.GetAddress(address_n=TEST_ADDRESS_N, coin_name="Testnet") + ) + if isinstance(resp, messages.ButtonRequest): + resp = session._callback_button(resp) + if isinstance(resp, messages.PassphraseRequest): + resp = session.call_raw(messages.PassphraseAck(on_device=True)) + if isinstance(resp, messages.ButtonRequest): + resp = session._callback_button(resp) + assert isinstance(resp, messages.Address) + return resp.address + + @contextmanager def prepare_passphrase_dialogue( device_handler: "BackgroundDeviceHandler", address: Optional[str] = None ) -> Generator["DebugLink", None, None]: debug = device_handler.debuglink() - device_handler.run_with_session(get_test_address) # type: ignore + session = SessionV1.new(device_handler.client) + device_handler.run_with_provided_session(session, _get_test_address) # type: ignore assert debug.read_layout().main_component() == "PassphraseKeyboard" # Resetting the category as it could have been changed by previous tests diff --git a/tests/click_tests/test_passphrase_caesar.py b/tests/click_tests/test_passphrase_caesar.py index 0affa4fbb6..29614abb21 100644 --- a/tests/click_tests/test_passphrase_caesar.py +++ b/tests/click_tests/test_passphrase_caesar.py @@ -19,9 +19,11 @@ from typing import TYPE_CHECKING, Generator, Optional import pytest -from trezorlib import exceptions +from trezorlib import exceptions, messages +from trezorlib.debuglink import SessionDebugWrapper as Session +from trezorlib.transport.session import SessionV1 -from ..common import get_test_address +from ..common import TEST_ADDRESS_N from .common import ( CommonPass, PassphraseCategory, @@ -77,6 +79,7 @@ SPECIAL_ACTIONS = [ ] # fmt: on + CATEGORY_ACTIONS = { PassphraseCategory.MENU: MENU_ACTIONS, PassphraseCategory.DIGITS: DIGITS_ACTIONS, @@ -84,6 +87,20 @@ CATEGORY_ACTIONS = { PassphraseCategory.UPPERCASE: UPPERCASE_ACTIONS, PassphraseCategory.SPECIAL: SPECIAL_ACTIONS, } +def _get_test_address(session: Session) -> None: + resp = session.call_raw( + messages.GetAddress(address_n=TEST_ADDRESS_N, coin_name="Testnet") + ) + if isinstance(resp, messages.ButtonRequest): + resp = session._callback_button(resp) + if isinstance(resp, messages.PassphraseRequest): + resp = session.call_raw(messages.PassphraseAck(on_device=True)) + if isinstance(resp, messages.ButtonRequest): + resp = session._callback_button(resp) + if isinstance(resp, messages.Address): + return resp.address + else: + raise exceptions.Cancelled @contextmanager @@ -91,7 +108,8 @@ def prepare_passphrase_dialogue( device_handler: "BackgroundDeviceHandler", address: Optional[str] = None ) -> Generator["DebugLink", None, None]: debug = device_handler.debuglink() - device_handler.run_with_session(get_test_address) # type: ignore + session = SessionV1.new(device_handler.client) + device_handler.run_with_provided_session(session, _get_test_address) # type: ignore layout = debug.read_layout() assert "PassphraseKeyboard" in layout.all_components() assert layout.passphrase() == "" diff --git a/tests/click_tests/test_recovery.py b/tests/click_tests/test_recovery.py index e68ebd18e9..8ba72b8eda 100644 --- a/tests/click_tests/test_recovery.py +++ b/tests/click_tests/test_recovery.py @@ -20,6 +20,7 @@ from typing import TYPE_CHECKING, Generator import pytest from trezorlib import device, exceptions, messages +from trezorlib.transport.session import SessionV1 from ..common import MNEMONIC12, MNEMONIC_SLIP39_BASIC_20_3of6 from . import recovery @@ -40,7 +41,10 @@ def prepare_recovery_and_evaluate( features = device_handler.features() debug = device_handler.debuglink() assert features.initialized is False - device_handler.run_with_session(device.recover, pin_protection=False) # type: ignore + session = device_handler.client.get_seedless_session() + device_handler.run_with_provided_session( + session, device.recover, pin_protection=False + ) # type: ignore yield debug @@ -58,7 +62,10 @@ def prepare_recovery_and_evaluate_cancel( features = device_handler.features() debug = device_handler.debuglink() assert features.initialized is False - device_handler.run_with_session(device.recover, pin_protection=False) # type: ignore + session = device_handler.client.get_seedless_session() + device_handler.run_with_provided_session( + session, device.recover, pin_protection=False + ) # type: ignore yield debug @@ -113,7 +120,10 @@ def test_recovery_cancel_issue4613(device_handler: "BackgroundDeviceHandler"): debug = device_handler.debuglink() # initiate and confirm the recovery - device_handler.run_with_session(device.recover, type=messages.RecoveryType.DryRun) + session = device_handler.client.get_seedless_session() + device_handler.run_with_provided_session( + session, device.recover, type=messages.RecoveryType.DryRun + ) recovery.confirm_recovery(debug, title="recovery__title_dry_run") # select number of words recovery.select_number_of_words(debug, num_of_words=12) @@ -130,9 +140,9 @@ def test_recovery_cancel_issue4613(device_handler: "BackgroundDeviceHandler"): # Ping the Trezor with an Initialize message (listed in DO_NOT_RESTART) try: - features = device_handler.client.get_seedless_session().call( - messages.Initialize() - ) + session = SessionV1(device_handler.client, id=b"") + session.client._last_active_session = session + features = session.call(messages.Initialize()) except exceptions.Cancelled: # due to a related problem, the first call in this situation will return # a Cancelled failure. This test does not care, we just retry. diff --git a/tests/click_tests/test_repeated_backup.py b/tests/click_tests/test_repeated_backup.py index ad6107d5f9..c08ade16f4 100644 --- a/tests/click_tests/test_repeated_backup.py +++ b/tests/click_tests/test_repeated_backup.py @@ -40,7 +40,9 @@ def test_repeated_backup( assert features.initialized is False - device_handler.run_with_session( + session = device_handler.client.get_seedless_session() + device_handler.run_with_provided_session( + session, device.setup, strength=128, backup_type=messages.BackupType.Slip39_Basic, diff --git a/tests/click_tests/test_reset_bip39.py b/tests/click_tests/test_reset_bip39.py index 2d9d400cb2..98e4b4b050 100644 --- a/tests/click_tests/test_reset_bip39.py +++ b/tests/click_tests/test_reset_bip39.py @@ -38,8 +38,9 @@ def test_reset_bip39(device_handler: "BackgroundDeviceHandler"): debug = device_handler.debuglink() assert features.initialized is False - - device_handler.run_with_session( + session = device_handler.client.get_seedless_session() + device_handler.run_with_provided_session( + session, device.setup, strength=128, backup_type=messages.BackupType.Bip39, diff --git a/tests/click_tests/test_reset_slip39_advanced.py b/tests/click_tests/test_reset_slip39_advanced.py index 903812a3a8..5c16a0532e 100644 --- a/tests/click_tests/test_reset_slip39_advanced.py +++ b/tests/click_tests/test_reset_slip39_advanced.py @@ -50,7 +50,9 @@ def test_reset_slip39_advanced( assert features.initialized is False - device_handler.run_with_session( + session = device_handler.client.get_seedless_session() + device_handler.run_with_provided_session( + session, device.setup, backup_type=messages.BackupType.Slip39_Advanced, pin_protection=False, diff --git a/tests/click_tests/test_reset_slip39_basic.py b/tests/click_tests/test_reset_slip39_basic.py index 714bf15a57..a690e51505 100644 --- a/tests/click_tests/test_reset_slip39_basic.py +++ b/tests/click_tests/test_reset_slip39_basic.py @@ -46,7 +46,9 @@ def test_reset_slip39_basic( assert features.initialized is False - device_handler.run_with_session( + session = device_handler.client.get_seedless_session() + device_handler.run_with_provided_session( + session, device.setup, strength=128, backup_type=messages.BackupType.Slip39_Basic, diff --git a/tests/click_tests/test_tutorial_caesar.py b/tests/click_tests/test_tutorial_caesar.py index de0e010f1d..aa03518a55 100644 --- a/tests/click_tests/test_tutorial_caesar.py +++ b/tests/click_tests/test_tutorial_caesar.py @@ -39,7 +39,8 @@ def prepare_tutorial_and_cancel_after_it( device_handler: "BackgroundDeviceHandler", cancelled: bool = False ) -> Generator["DebugLink", None, None]: debug = device_handler.debuglink() - device_handler.run_with_session(device.show_device_tutorial) + session = device_handler.client.get_seedless_session() + device_handler.run_with_provided_session(session, device.show_device_tutorial) yield debug diff --git a/tests/click_tests/test_tutorial_delizia.py b/tests/click_tests/test_tutorial_delizia.py index f1b45118f5..dfe04d4ccf 100644 --- a/tests/click_tests/test_tutorial_delizia.py +++ b/tests/click_tests/test_tutorial_delizia.py @@ -35,7 +35,8 @@ pytestmark = [ def test_tutorial_ignore_menu(device_handler: "BackgroundDeviceHandler"): debug = device_handler.debuglink() - device_handler.run_with_session(device.show_device_tutorial) + session = device_handler.client.get_seedless_session() + device_handler.run_with_provided_session(session, device.show_device_tutorial) assert debug.read_layout().title() == TR.tutorial__welcome_safe5 debug.click(debug.screen_buttons.tap_to_confirm()) @@ -55,7 +56,8 @@ def test_tutorial_ignore_menu(device_handler: "BackgroundDeviceHandler"): def test_tutorial_menu_open_close(device_handler: "BackgroundDeviceHandler"): debug = device_handler.debuglink() - device_handler.run_with_session(device.show_device_tutorial) + session = device_handler.client.get_seedless_session() + device_handler.run_with_provided_session(session, device.show_device_tutorial) assert debug.read_layout().title() == TR.tutorial__welcome_safe5 debug.click(debug.screen_buttons.tap_to_confirm()) @@ -81,7 +83,8 @@ def test_tutorial_menu_open_close(device_handler: "BackgroundDeviceHandler"): def test_tutorial_menu_exit(device_handler: "BackgroundDeviceHandler"): debug = device_handler.debuglink() - device_handler.run_with_session(device.show_device_tutorial) + session = device_handler.client.get_seedless_session() + device_handler.run_with_provided_session(session, device.show_device_tutorial) assert debug.read_layout().title() == TR.tutorial__welcome_safe5 debug.click(debug.screen_buttons.tap_to_confirm()) @@ -104,7 +107,8 @@ def test_tutorial_menu_exit(device_handler: "BackgroundDeviceHandler"): def test_tutorial_menu_repeat(device_handler: "BackgroundDeviceHandler"): debug = device_handler.debuglink() - device_handler.run_with_session(device.show_device_tutorial) + session = device_handler.client.get_seedless_session() + device_handler.run_with_provided_session(session, device.show_device_tutorial) assert debug.read_layout().title() == TR.tutorial__welcome_safe5 debug.click(debug.screen_buttons.tap_to_confirm()) @@ -134,7 +138,8 @@ def test_tutorial_menu_repeat(device_handler: "BackgroundDeviceHandler"): def test_tutorial_menu_funfact(device_handler: "BackgroundDeviceHandler"): debug = device_handler.debuglink() - device_handler.run_with_session(device.show_device_tutorial) + session = device_handler.client.get_seedless_session() + device_handler.run_with_provided_session(session, device.show_device_tutorial) assert debug.read_layout().title() == TR.tutorial__welcome_safe5 debug.click(debug.screen_buttons.tap_to_confirm())