mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-06-16 13:09:00 +00:00
fixup! test: update click tests
This commit is contained in:
parent
0db8a24c3a
commit
80d9f53fdd
@ -20,9 +20,11 @@ from typing import TYPE_CHECKING, Generator, Optional
|
|||||||
|
|
||||||
import pytest
|
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
|
from .common import CommonPass, PassphraseCategory, get_char_category
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
@ -68,12 +70,27 @@ assert len(DA_51) == 51
|
|||||||
assert DA_51_ADDRESS == DA_50_ADDRESS
|
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
|
@contextmanager
|
||||||
def prepare_passphrase_dialogue(
|
def prepare_passphrase_dialogue(
|
||||||
device_handler: "BackgroundDeviceHandler", address: Optional[str] = None
|
device_handler: "BackgroundDeviceHandler", address: Optional[str] = None
|
||||||
) -> Generator["DebugLink", None, None]:
|
) -> Generator["DebugLink", None, None]:
|
||||||
debug = device_handler.debuglink()
|
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"
|
assert debug.read_layout().main_component() == "PassphraseKeyboard"
|
||||||
|
|
||||||
# Resetting the category as it could have been changed by previous tests
|
# Resetting the category as it could have been changed by previous tests
|
||||||
|
@ -19,9 +19,11 @@ from typing import TYPE_CHECKING, Generator, Optional
|
|||||||
|
|
||||||
import pytest
|
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 (
|
from .common import (
|
||||||
CommonPass,
|
CommonPass,
|
||||||
PassphraseCategory,
|
PassphraseCategory,
|
||||||
@ -77,6 +79,7 @@ SPECIAL_ACTIONS = [
|
|||||||
]
|
]
|
||||||
# fmt: on
|
# fmt: on
|
||||||
|
|
||||||
|
|
||||||
CATEGORY_ACTIONS = {
|
CATEGORY_ACTIONS = {
|
||||||
PassphraseCategory.MENU: MENU_ACTIONS,
|
PassphraseCategory.MENU: MENU_ACTIONS,
|
||||||
PassphraseCategory.DIGITS: DIGITS_ACTIONS,
|
PassphraseCategory.DIGITS: DIGITS_ACTIONS,
|
||||||
@ -84,6 +87,20 @@ CATEGORY_ACTIONS = {
|
|||||||
PassphraseCategory.UPPERCASE: UPPERCASE_ACTIONS,
|
PassphraseCategory.UPPERCASE: UPPERCASE_ACTIONS,
|
||||||
PassphraseCategory.SPECIAL: SPECIAL_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
|
@contextmanager
|
||||||
@ -91,7 +108,8 @@ def prepare_passphrase_dialogue(
|
|||||||
device_handler: "BackgroundDeviceHandler", address: Optional[str] = None
|
device_handler: "BackgroundDeviceHandler", address: Optional[str] = None
|
||||||
) -> Generator["DebugLink", None, None]:
|
) -> Generator["DebugLink", None, None]:
|
||||||
debug = device_handler.debuglink()
|
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()
|
layout = debug.read_layout()
|
||||||
assert "PassphraseKeyboard" in layout.all_components()
|
assert "PassphraseKeyboard" in layout.all_components()
|
||||||
assert layout.passphrase() == ""
|
assert layout.passphrase() == ""
|
||||||
|
@ -20,6 +20,7 @@ from typing import TYPE_CHECKING, Generator
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from trezorlib import device, exceptions, messages
|
from trezorlib import device, exceptions, messages
|
||||||
|
from trezorlib.transport.session import SessionV1
|
||||||
|
|
||||||
from ..common import MNEMONIC12, MNEMONIC_SLIP39_BASIC_20_3of6
|
from ..common import MNEMONIC12, MNEMONIC_SLIP39_BASIC_20_3of6
|
||||||
from . import recovery
|
from . import recovery
|
||||||
@ -40,7 +41,10 @@ def prepare_recovery_and_evaluate(
|
|||||||
features = device_handler.features()
|
features = device_handler.features()
|
||||||
debug = device_handler.debuglink()
|
debug = device_handler.debuglink()
|
||||||
assert features.initialized is False
|
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
|
yield debug
|
||||||
|
|
||||||
@ -58,7 +62,10 @@ def prepare_recovery_and_evaluate_cancel(
|
|||||||
features = device_handler.features()
|
features = device_handler.features()
|
||||||
debug = device_handler.debuglink()
|
debug = device_handler.debuglink()
|
||||||
assert features.initialized is False
|
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
|
yield debug
|
||||||
|
|
||||||
@ -113,7 +120,10 @@ def test_recovery_cancel_issue4613(device_handler: "BackgroundDeviceHandler"):
|
|||||||
debug = device_handler.debuglink()
|
debug = device_handler.debuglink()
|
||||||
|
|
||||||
# initiate and confirm the recovery
|
# 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")
|
recovery.confirm_recovery(debug, title="recovery__title_dry_run")
|
||||||
# select number of words
|
# select number of words
|
||||||
recovery.select_number_of_words(debug, num_of_words=12)
|
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)
|
# Ping the Trezor with an Initialize message (listed in DO_NOT_RESTART)
|
||||||
try:
|
try:
|
||||||
features = device_handler.client.get_seedless_session().call(
|
session = SessionV1(device_handler.client, id=b"")
|
||||||
messages.Initialize()
|
session.client._last_active_session = session
|
||||||
)
|
features = session.call(messages.Initialize())
|
||||||
except exceptions.Cancelled:
|
except exceptions.Cancelled:
|
||||||
# due to a related problem, the first call in this situation will return
|
# due to a related problem, the first call in this situation will return
|
||||||
# a Cancelled failure. This test does not care, we just retry.
|
# a Cancelled failure. This test does not care, we just retry.
|
||||||
|
@ -40,7 +40,9 @@ def test_repeated_backup(
|
|||||||
|
|
||||||
assert features.initialized is False
|
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,
|
device.setup,
|
||||||
strength=128,
|
strength=128,
|
||||||
backup_type=messages.BackupType.Slip39_Basic,
|
backup_type=messages.BackupType.Slip39_Basic,
|
||||||
|
@ -38,8 +38,9 @@ def test_reset_bip39(device_handler: "BackgroundDeviceHandler"):
|
|||||||
debug = device_handler.debuglink()
|
debug = device_handler.debuglink()
|
||||||
|
|
||||||
assert features.initialized is False
|
assert features.initialized is False
|
||||||
|
session = device_handler.client.get_seedless_session()
|
||||||
device_handler.run_with_session(
|
device_handler.run_with_provided_session(
|
||||||
|
session,
|
||||||
device.setup,
|
device.setup,
|
||||||
strength=128,
|
strength=128,
|
||||||
backup_type=messages.BackupType.Bip39,
|
backup_type=messages.BackupType.Bip39,
|
||||||
|
@ -50,7 +50,9 @@ def test_reset_slip39_advanced(
|
|||||||
|
|
||||||
assert features.initialized is False
|
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,
|
device.setup,
|
||||||
backup_type=messages.BackupType.Slip39_Advanced,
|
backup_type=messages.BackupType.Slip39_Advanced,
|
||||||
pin_protection=False,
|
pin_protection=False,
|
||||||
|
@ -46,7 +46,9 @@ def test_reset_slip39_basic(
|
|||||||
|
|
||||||
assert features.initialized is False
|
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,
|
device.setup,
|
||||||
strength=128,
|
strength=128,
|
||||||
backup_type=messages.BackupType.Slip39_Basic,
|
backup_type=messages.BackupType.Slip39_Basic,
|
||||||
|
@ -39,7 +39,8 @@ def prepare_tutorial_and_cancel_after_it(
|
|||||||
device_handler: "BackgroundDeviceHandler", cancelled: bool = False
|
device_handler: "BackgroundDeviceHandler", cancelled: bool = False
|
||||||
) -> Generator["DebugLink", None, None]:
|
) -> Generator["DebugLink", None, None]:
|
||||||
debug = device_handler.debuglink()
|
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
|
yield debug
|
||||||
|
|
||||||
|
@ -35,7 +35,8 @@ pytestmark = [
|
|||||||
|
|
||||||
def test_tutorial_ignore_menu(device_handler: "BackgroundDeviceHandler"):
|
def test_tutorial_ignore_menu(device_handler: "BackgroundDeviceHandler"):
|
||||||
debug = device_handler.debuglink()
|
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
|
assert debug.read_layout().title() == TR.tutorial__welcome_safe5
|
||||||
debug.click(debug.screen_buttons.tap_to_confirm())
|
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"):
|
def test_tutorial_menu_open_close(device_handler: "BackgroundDeviceHandler"):
|
||||||
debug = device_handler.debuglink()
|
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
|
assert debug.read_layout().title() == TR.tutorial__welcome_safe5
|
||||||
debug.click(debug.screen_buttons.tap_to_confirm())
|
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"):
|
def test_tutorial_menu_exit(device_handler: "BackgroundDeviceHandler"):
|
||||||
debug = device_handler.debuglink()
|
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
|
assert debug.read_layout().title() == TR.tutorial__welcome_safe5
|
||||||
debug.click(debug.screen_buttons.tap_to_confirm())
|
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"):
|
def test_tutorial_menu_repeat(device_handler: "BackgroundDeviceHandler"):
|
||||||
debug = device_handler.debuglink()
|
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
|
assert debug.read_layout().title() == TR.tutorial__welcome_safe5
|
||||||
debug.click(debug.screen_buttons.tap_to_confirm())
|
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"):
|
def test_tutorial_menu_funfact(device_handler: "BackgroundDeviceHandler"):
|
||||||
debug = device_handler.debuglink()
|
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
|
assert debug.read_layout().title() == TR.tutorial__welcome_safe5
|
||||||
debug.click(debug.screen_buttons.tap_to_confirm())
|
debug.click(debug.screen_buttons.tap_to_confirm())
|
||||||
|
Loading…
Reference in New Issue
Block a user