1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-04-19 16:49:02 +00:00

fixup! test: update click tests

This commit is contained in:
M1nd3r 2025-03-31 20:26:15 +02:00
parent 0db8a24c3a
commit 80d9f53fdd
9 changed files with 81 additions and 23 deletions

View File

@ -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

View File

@ -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() == ""

View File

@ -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.

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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

View File

@ -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())