mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-22 22:38:08 +00:00
test: update click tests
[no changelog]
This commit is contained in:
parent
900dfd388f
commit
01d04c12c2
@ -21,7 +21,9 @@ from typing import TYPE_CHECKING
|
||||
import pytest
|
||||
|
||||
from trezorlib import btc, device, exceptions, messages
|
||||
from trezorlib.client import PASSPHRASE_ON_DEVICE
|
||||
from trezorlib.debuglink import LayoutType
|
||||
from trezorlib.debuglink import SessionDebugWrapper as Session
|
||||
from trezorlib.protobuf import MessageType
|
||||
from trezorlib.tools import parse_path
|
||||
|
||||
@ -58,8 +60,8 @@ CENTER_BUTTON = buttons.grid35(1, 2)
|
||||
|
||||
def set_autolock_delay(device_handler: "BackgroundDeviceHandler", delay_ms: int):
|
||||
debug = device_handler.debuglink()
|
||||
|
||||
device_handler.run(device.apply_settings, auto_lock_delay_ms=delay_ms) # type: ignore
|
||||
Session(device_handler.client.get_management_session()).lock()
|
||||
device_handler.run_with_session(device.apply_settings, auto_lock_delay_ms=delay_ms) # type: ignore
|
||||
|
||||
assert "PinKeyboard" in debug.read_layout().all_components()
|
||||
|
||||
@ -97,7 +99,7 @@ def test_autolock_interrupts_signing(device_handler: "BackgroundDeviceHandler"):
|
||||
script_type=messages.OutputScriptType.PAYTOADDRESS,
|
||||
)
|
||||
|
||||
device_handler.run(btc.sign_tx, "Bitcoin", [inp1], [out1], prev_txes=TX_CACHE_MAINNET) # type: ignore
|
||||
device_handler.run_with_session(btc.sign_tx, "Bitcoin", [inp1], [out1], prev_txes=TX_CACHE_MAINNET) # type: ignore
|
||||
|
||||
assert (
|
||||
"1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1"
|
||||
@ -132,6 +134,10 @@ def test_autolock_does_not_interrupt_signing(device_handler: "BackgroundDeviceHa
|
||||
set_autolock_delay(device_handler, 10_000)
|
||||
|
||||
debug = device_handler.debuglink()
|
||||
|
||||
# Prepare session to use later
|
||||
session = Session(device_handler.client.get_session())
|
||||
|
||||
# try to sign a transaction
|
||||
inp1 = messages.TxInputType(
|
||||
address_n=parse_path("86h/0h/0h/0/0"),
|
||||
@ -147,8 +153,8 @@ def test_autolock_does_not_interrupt_signing(device_handler: "BackgroundDeviceHa
|
||||
script_type=messages.OutputScriptType.PAYTOADDRESS,
|
||||
)
|
||||
|
||||
device_handler.run(
|
||||
btc.sign_tx, "Bitcoin", [inp1], [out1], prev_txes=TX_CACHE_MAINNET
|
||||
device_handler.run_with_provided_session(
|
||||
session, btc.sign_tx, "Bitcoin", [inp1], [out1], prev_txes=TX_CACHE_MAINNET
|
||||
)
|
||||
|
||||
assert (
|
||||
@ -175,11 +181,11 @@ def test_autolock_does_not_interrupt_signing(device_handler: "BackgroundDeviceHa
|
||||
|
||||
def sleepy_filter(msg: MessageType) -> MessageType:
|
||||
time.sleep(10.1)
|
||||
device_handler.client.set_filter(messages.TxAck, None)
|
||||
session.set_filter(messages.TxAck, None)
|
||||
return msg
|
||||
|
||||
with device_handler.client:
|
||||
device_handler.client.set_filter(messages.TxAck, sleepy_filter)
|
||||
with session, device_handler.client:
|
||||
session.set_filter(messages.TxAck, sleepy_filter)
|
||||
# confirm transaction
|
||||
# In all cases we set wait=False to avoid waiting for the screen and triggering
|
||||
# the layout deadlock detection. In reality there is no deadlock but the
|
||||
@ -187,7 +193,7 @@ def test_autolock_does_not_interrupt_signing(device_handler: "BackgroundDeviceHa
|
||||
# timeout is 3. In this test we don't need the result of the input event so
|
||||
# waiting for it is not necessary.
|
||||
if debug.layout_type is LayoutType.TT:
|
||||
debug.click(buttons.OK, wait=False)
|
||||
debug.click(buttons.OK, hold_ms=1000, wait=False)
|
||||
elif debug.layout_type is LayoutType.Mercury:
|
||||
debug.click(buttons.TAP_TO_CONFIRM, wait=False)
|
||||
elif debug.layout_type is LayoutType.TR:
|
||||
@ -196,7 +202,6 @@ def test_autolock_does_not_interrupt_signing(device_handler: "BackgroundDeviceHa
|
||||
signatures, tx = device_handler.result()
|
||||
assert len(signatures) == 1
|
||||
assert tx
|
||||
|
||||
assert device_handler.features().unlocked is False
|
||||
|
||||
|
||||
@ -206,8 +211,10 @@ def test_autolock_passphrase_keyboard(device_handler: "BackgroundDeviceHandler")
|
||||
debug = device_handler.debuglink()
|
||||
|
||||
# get address
|
||||
device_handler.run(common.get_test_address) # type: ignore
|
||||
|
||||
session = Session(
|
||||
device_handler.client.get_session(passphrase=PASSPHRASE_ON_DEVICE)
|
||||
)
|
||||
device_handler.run_with_provided_session(session, common.get_test_address) # type: ignore
|
||||
assert "PassphraseKeyboard" in debug.read_layout().all_components()
|
||||
|
||||
if debug.layout_type is LayoutType.TR:
|
||||
@ -248,8 +255,10 @@ def test_autolock_interrupts_passphrase(device_handler: "BackgroundDeviceHandler
|
||||
debug = device_handler.debuglink()
|
||||
|
||||
# get address
|
||||
device_handler.run(common.get_test_address) # type: ignore
|
||||
|
||||
session = Session(
|
||||
device_handler.client.get_session(passphrase=PASSPHRASE_ON_DEVICE)
|
||||
)
|
||||
device_handler.run_with_provided_session(session, common.get_test_address) # type: ignore
|
||||
assert "PassphraseKeyboard" in debug.read_layout().all_components()
|
||||
|
||||
if debug.layout_type is LayoutType.TR:
|
||||
@ -287,7 +296,7 @@ def test_dryrun_locks_at_number_of_words(device_handler: "BackgroundDeviceHandle
|
||||
set_autolock_delay(device_handler, 10_000)
|
||||
debug = device_handler.debuglink()
|
||||
|
||||
device_handler.run(device.recover, type=messages.RecoveryType.DryRun)
|
||||
device_handler.run_with_session(device.recover, type=messages.RecoveryType.DryRun)
|
||||
|
||||
layout = unlock_dry_run(debug)
|
||||
assert TR.recovery__num_of_words in debug.read_layout().text_content()
|
||||
@ -319,7 +328,7 @@ def test_dryrun_locks_at_word_entry(device_handler: "BackgroundDeviceHandler"):
|
||||
set_autolock_delay(device_handler, 10_000)
|
||||
debug = device_handler.debuglink()
|
||||
|
||||
device_handler.run(device.recover, type=messages.RecoveryType.DryRun)
|
||||
device_handler.run_with_session(device.recover, type=messages.RecoveryType.DryRun)
|
||||
|
||||
unlock_dry_run(debug)
|
||||
|
||||
@ -345,7 +354,7 @@ def test_dryrun_enter_word_slowly(device_handler: "BackgroundDeviceHandler"):
|
||||
set_autolock_delay(device_handler, 10_000)
|
||||
debug = device_handler.debuglink()
|
||||
|
||||
device_handler.run(device.recover, type=messages.RecoveryType.DryRun)
|
||||
device_handler.run_with_session(device.recover, type=messages.RecoveryType.DryRun)
|
||||
|
||||
unlock_dry_run(debug)
|
||||
|
||||
@ -405,7 +414,11 @@ def test_autolock_does_not_interrupt_preauthorized(
|
||||
|
||||
debug = device_handler.debuglink()
|
||||
|
||||
device_handler.run(
|
||||
# Prepare session to use later
|
||||
session = Session(device_handler.client.get_session())
|
||||
|
||||
device_handler.run_with_provided_session(
|
||||
session,
|
||||
btc.authorize_coinjoin,
|
||||
coordinator="www.example.com",
|
||||
max_rounds=2,
|
||||
@ -519,14 +532,15 @@ def test_autolock_does_not_interrupt_preauthorized(
|
||||
|
||||
def sleepy_filter(msg: MessageType) -> MessageType:
|
||||
time.sleep(10.1)
|
||||
device_handler.client.set_filter(messages.SignTx, None)
|
||||
session.set_filter(messages.SignTx, None)
|
||||
return msg
|
||||
|
||||
with device_handler.client:
|
||||
with session:
|
||||
# Start DoPreauthorized flow when device is unlocked. Wait 10s before
|
||||
# delivering SignTx, by that time autolock timer should have fired.
|
||||
device_handler.client.set_filter(messages.SignTx, sleepy_filter)
|
||||
device_handler.run(
|
||||
session.set_filter(messages.SignTx, sleepy_filter)
|
||||
device_handler.run_with_provided_session(
|
||||
session,
|
||||
btc.sign_tx,
|
||||
"Testnet",
|
||||
inputs,
|
||||
|
@ -53,7 +53,9 @@ def test_backup_slip39_custom(
|
||||
|
||||
assert features.initialized is False
|
||||
|
||||
device_handler.run(
|
||||
session = device_handler.client.get_management_session()
|
||||
device_handler.run_with_provided_session(
|
||||
session,
|
||||
device.reset,
|
||||
strength=128,
|
||||
backup_type=messages.BackupType.Slip39_Basic,
|
||||
@ -68,7 +70,7 @@ def test_backup_slip39_custom(
|
||||
|
||||
assert device_handler.result() == "Initialized"
|
||||
|
||||
device_handler.run(
|
||||
device_handler.run_with_session(
|
||||
device.backup,
|
||||
group_threshold=group_threshold,
|
||||
groups=[(share_threshold, share_count)],
|
||||
|
@ -19,7 +19,7 @@ from typing import TYPE_CHECKING
|
||||
|
||||
import pytest
|
||||
|
||||
from trezorlib import models
|
||||
from trezorlib import messages, models
|
||||
from trezorlib.debuglink import LayoutType
|
||||
|
||||
from .. import buttons, common
|
||||
@ -34,6 +34,9 @@ PIN4 = "1234"
|
||||
@pytest.mark.setup_client(pin=PIN4)
|
||||
def test_hold_to_lock(device_handler: "BackgroundDeviceHandler"):
|
||||
debug = device_handler.debuglink()
|
||||
session = device_handler.client.get_management_session()
|
||||
session.call(messages.LockDevice())
|
||||
session.refresh_features()
|
||||
|
||||
short_duration = {
|
||||
models.T1B1: 500,
|
||||
@ -59,22 +62,25 @@ def test_hold_to_lock(device_handler: "BackgroundDeviceHandler"):
|
||||
assert device_handler.features().unlocked is False
|
||||
|
||||
# unlock with message
|
||||
device_handler.run(common.get_test_address)
|
||||
device_handler.run_with_session(common.get_test_address)
|
||||
|
||||
assert "PinKeyboard" in debug.read_layout().all_components()
|
||||
debug.input("1234")
|
||||
assert device_handler.result()
|
||||
|
||||
session.refresh_features()
|
||||
assert device_handler.features().unlocked is True
|
||||
|
||||
# short touch
|
||||
hold(short_duration)
|
||||
|
||||
time.sleep(0.5) # so that the homescreen appears again (hacky)
|
||||
session.refresh_features()
|
||||
assert device_handler.features().unlocked is True
|
||||
|
||||
# lock
|
||||
hold(lock_duration)
|
||||
session.refresh_features()
|
||||
assert device_handler.features().unlocked is False
|
||||
|
||||
# unlock by touching
|
||||
@ -85,8 +91,10 @@ def test_hold_to_lock(device_handler: "BackgroundDeviceHandler"):
|
||||
assert "PinKeyboard" in layout.all_components()
|
||||
debug.input("1234")
|
||||
|
||||
session.refresh_features()
|
||||
assert device_handler.features().unlocked is True
|
||||
|
||||
# lock
|
||||
hold(lock_duration)
|
||||
session.refresh_features()
|
||||
assert device_handler.features().unlocked is False
|
||||
|
@ -97,7 +97,7 @@ def prepare_passphrase_dialogue(
|
||||
device_handler: "BackgroundDeviceHandler", address: Optional[str] = None
|
||||
) -> Generator["DebugLink", None, None]:
|
||||
debug = device_handler.debuglink()
|
||||
device_handler.run(get_test_address) # type: ignore
|
||||
device_handler.run_with_session(get_test_address) # type: ignore
|
||||
# TODO
|
||||
assert debug.read_layout().main_component() == "PassphraseKeyboard"
|
||||
|
||||
|
@ -91,7 +91,7 @@ def prepare_passphrase_dialogue(
|
||||
device_handler: "BackgroundDeviceHandler", address: Optional[str] = None
|
||||
) -> Generator["DebugLink", None, None]:
|
||||
debug = device_handler.debuglink()
|
||||
device_handler.run(get_test_address) # type: ignore
|
||||
device_handler.run_with_session(get_test_address) # type: ignore
|
||||
layout = debug.read_layout()
|
||||
assert "PassphraseKeyboard" in layout.all_components()
|
||||
assert layout.passphrase() == ""
|
||||
|
@ -69,7 +69,7 @@ def prepare_passphrase_dialogue(
|
||||
device_handler: "BackgroundDeviceHandler", address: Optional[str] = None
|
||||
) -> Generator["DebugLink", None, None]:
|
||||
debug = device_handler.debuglink()
|
||||
device_handler.run(get_test_address) # type: ignore
|
||||
device_handler.run_with_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
|
||||
|
@ -23,6 +23,7 @@ import pytest
|
||||
|
||||
from trezorlib import device, exceptions
|
||||
from trezorlib.debuglink import LayoutType
|
||||
from trezorlib.debuglink import SessionDebugWrapper as Session
|
||||
|
||||
from .. import buttons
|
||||
from .. import translations as TR
|
||||
@ -91,17 +92,19 @@ def prepare(
|
||||
|
||||
tap = False
|
||||
|
||||
Session(device_handler.client.get_management_session()).lock()
|
||||
|
||||
# Setup according to the wanted situation
|
||||
if situation == Situation.PIN_INPUT:
|
||||
# Any action triggering the PIN dialogue
|
||||
device_handler.run(device.apply_settings, auto_lock_delay_ms=300_000) # type: ignore
|
||||
device_handler.run_with_session(device.apply_settings, auto_lock_delay_ms=300_000) # type: ignore
|
||||
tap = True
|
||||
if situation == Situation.PIN_INPUT_CANCEL:
|
||||
# Any action triggering the PIN dialogue
|
||||
device_handler.run(device.apply_settings, auto_lock_delay_ms=300_000) # type: ignore
|
||||
device_handler.run_with_session(device.apply_settings, auto_lock_delay_ms=300_000) # type: ignore
|
||||
elif situation == Situation.PIN_SETUP:
|
||||
# Set new PIN
|
||||
device_handler.run(device.change_pin) # type: ignore
|
||||
device_handler.run_with_session(device.change_pin) # type: ignore
|
||||
assert (
|
||||
TR.pin__turn_on in debug.read_layout().text_content()
|
||||
or TR.pin__info in debug.read_layout().text_content()
|
||||
@ -115,14 +118,14 @@ def prepare(
|
||||
go_next(debug)
|
||||
elif situation == Situation.PIN_CHANGE:
|
||||
# Change PIN
|
||||
device_handler.run(device.change_pin) # type: ignore
|
||||
device_handler.run_with_session(device.change_pin) # type: ignore
|
||||
_input_see_confirm(debug, old_pin)
|
||||
assert TR.pin__change in debug.read_layout().text_content()
|
||||
go_next(debug)
|
||||
_input_see_confirm(debug, old_pin)
|
||||
elif situation == Situation.WIPE_CODE_SETUP:
|
||||
# Set wipe code
|
||||
device_handler.run(device.change_wipe_code) # type: ignore
|
||||
device_handler.run_with_session(device.change_wipe_code) # type: ignore
|
||||
if old_pin:
|
||||
_input_see_confirm(debug, old_pin)
|
||||
assert TR.wipe_code__turn_on in debug.read_layout().text_content()
|
||||
|
@ -40,7 +40,7 @@ def prepare_recovery_and_evaluate(
|
||||
features = device_handler.features()
|
||||
debug = device_handler.debuglink()
|
||||
assert features.initialized is False
|
||||
device_handler.run(device.recover, pin_protection=False) # type: ignore
|
||||
device_handler.run_with_session(device.recover, pin_protection=False) # type: ignore
|
||||
|
||||
yield debug
|
||||
|
||||
|
@ -42,7 +42,7 @@ def test_repeated_backup(
|
||||
|
||||
assert features.initialized is False
|
||||
|
||||
device_handler.run(
|
||||
device_handler.run_with_session(
|
||||
device.reset,
|
||||
strength=128,
|
||||
backup_type=messages.BackupType.Slip39_Basic,
|
||||
@ -94,7 +94,7 @@ def test_repeated_backup(
|
||||
assert features.recovery_status == messages.RecoveryStatus.Nothing
|
||||
|
||||
# run recovery to unlock backup
|
||||
device_handler.run(
|
||||
device_handler.run_with_session(
|
||||
device.recover,
|
||||
type=messages.RecoveryType.UnlockRepeatedBackup,
|
||||
)
|
||||
@ -161,7 +161,7 @@ def test_repeated_backup(
|
||||
assert features.recovery_status == messages.RecoveryStatus.Nothing
|
||||
|
||||
# try to unlock backup again...
|
||||
device_handler.run(
|
||||
device_handler.run_with_session(
|
||||
device.recover,
|
||||
type=messages.RecoveryType.UnlockRepeatedBackup,
|
||||
)
|
||||
|
@ -40,7 +40,7 @@ def test_reset_bip39(device_handler: "BackgroundDeviceHandler"):
|
||||
|
||||
assert features.initialized is False
|
||||
|
||||
device_handler.run(
|
||||
device_handler.run_with_session(
|
||||
device.reset,
|
||||
strength=128,
|
||||
backup_type=messages.BackupType.Bip39,
|
||||
|
@ -52,7 +52,7 @@ def test_reset_slip39_advanced(
|
||||
|
||||
assert features.initialized is False
|
||||
|
||||
device_handler.run(
|
||||
device_handler.run_with_session(
|
||||
device.reset,
|
||||
backup_type=messages.BackupType.Slip39_Advanced,
|
||||
pin_protection=False,
|
||||
|
@ -48,7 +48,7 @@ def test_reset_slip39_basic(
|
||||
|
||||
assert features.initialized is False
|
||||
|
||||
device_handler.run(
|
||||
device_handler.run_with_session(
|
||||
device.reset,
|
||||
strength=128,
|
||||
backup_type=messages.BackupType.Slip39_Basic,
|
||||
|
@ -36,7 +36,7 @@ pytestmark = [
|
||||
|
||||
def test_tutorial_ignore_menu(device_handler: "BackgroundDeviceHandler"):
|
||||
debug = device_handler.debuglink()
|
||||
device_handler.run(device.show_device_tutorial)
|
||||
device_handler.run_with_session(device.show_device_tutorial)
|
||||
|
||||
layout = debug.read_layout()
|
||||
assert layout.title() == TR.tutorial__welcome_safe5
|
||||
@ -57,7 +57,7 @@ def test_tutorial_ignore_menu(device_handler: "BackgroundDeviceHandler"):
|
||||
|
||||
def test_tutorial_menu_open_close(device_handler: "BackgroundDeviceHandler"):
|
||||
debug = device_handler.debuglink()
|
||||
device_handler.run(device.show_device_tutorial)
|
||||
device_handler.run_with_session(device.show_device_tutorial)
|
||||
|
||||
layout = debug.read_layout()
|
||||
assert layout.title() == TR.tutorial__welcome_safe5
|
||||
@ -84,7 +84,7 @@ def test_tutorial_menu_open_close(device_handler: "BackgroundDeviceHandler"):
|
||||
|
||||
def test_tutorial_menu_exit(device_handler: "BackgroundDeviceHandler"):
|
||||
debug = device_handler.debuglink()
|
||||
device_handler.run(device.show_device_tutorial)
|
||||
device_handler.run_with_session(device.show_device_tutorial)
|
||||
|
||||
layout = debug.read_layout()
|
||||
assert layout.title() == TR.tutorial__welcome_safe5
|
||||
@ -108,7 +108,7 @@ def test_tutorial_menu_exit(device_handler: "BackgroundDeviceHandler"):
|
||||
|
||||
def test_tutorial_menu_repeat(device_handler: "BackgroundDeviceHandler"):
|
||||
debug = device_handler.debuglink()
|
||||
device_handler.run(device.show_device_tutorial)
|
||||
device_handler.run_with_session(device.show_device_tutorial)
|
||||
|
||||
layout = debug.read_layout()
|
||||
assert layout.title() == TR.tutorial__welcome_safe5
|
||||
@ -139,7 +139,7 @@ def test_tutorial_menu_repeat(device_handler: "BackgroundDeviceHandler"):
|
||||
|
||||
def test_tutorial_menu_funfact(device_handler: "BackgroundDeviceHandler"):
|
||||
debug = device_handler.debuglink()
|
||||
device_handler.run(device.show_device_tutorial)
|
||||
device_handler.run_with_session(device.show_device_tutorial)
|
||||
|
||||
layout = debug.read_layout()
|
||||
assert layout.title() == TR.tutorial__welcome_safe5
|
||||
|
@ -39,7 +39,7 @@ def prepare_tutorial_and_cancel_after_it(
|
||||
device_handler: "BackgroundDeviceHandler", cancelled: bool = False
|
||||
) -> Generator["DebugLink", None, None]:
|
||||
debug = device_handler.debuglink()
|
||||
device_handler.run(device.show_device_tutorial)
|
||||
device_handler.run_with_session(device.show_device_tutorial)
|
||||
|
||||
yield debug
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user