mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-05-17 22:38:46 +00:00
test: update click tests
This commit is contained in:
parent
c62222e73e
commit
5a9bed41d9
@ -21,9 +21,12 @@ from typing import TYPE_CHECKING, Tuple
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from trezorlib import btc, device, exceptions, messages
|
from trezorlib import btc, device, exceptions, messages
|
||||||
|
from trezorlib.client import PASSPHRASE_ON_DEVICE
|
||||||
from trezorlib.debuglink import DebugLink, LayoutType
|
from trezorlib.debuglink import DebugLink, LayoutType
|
||||||
|
from trezorlib.debuglink import SessionDebugWrapper as Session
|
||||||
from trezorlib.protobuf import MessageType
|
from trezorlib.protobuf import MessageType
|
||||||
from trezorlib.tools import parse_path
|
from trezorlib.tools import parse_path
|
||||||
|
from trezorlib.transport.session import SessionV1, derive_seed
|
||||||
|
|
||||||
from .. import common
|
from .. import common
|
||||||
from .. import translations as TR
|
from .. import translations as TR
|
||||||
@ -66,8 +69,8 @@ def _center_button(debug: DebugLink) -> Tuple[int, int]:
|
|||||||
|
|
||||||
def set_autolock_delay(device_handler: "BackgroundDeviceHandler", delay_ms: int):
|
def set_autolock_delay(device_handler: "BackgroundDeviceHandler", delay_ms: int):
|
||||||
debug = device_handler.debuglink()
|
debug = device_handler.debuglink()
|
||||||
|
device_handler.client.get_seedless_session().lock()
|
||||||
device_handler.run(device.apply_settings, auto_lock_delay_ms=delay_ms) # type: ignore
|
device_handler.run_with_session(device.apply_settings, auto_lock_delay_ms=delay_ms) # type: ignore
|
||||||
|
|
||||||
assert "PinKeyboard" in debug.read_layout().all_components()
|
assert "PinKeyboard" in debug.read_layout().all_components()
|
||||||
|
|
||||||
@ -106,7 +109,7 @@ def test_autolock_interrupts_signing(device_handler: "BackgroundDeviceHandler"):
|
|||||||
script_type=messages.OutputScriptType.PAYTOADDRESS,
|
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 (
|
assert (
|
||||||
"1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1"
|
"1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1"
|
||||||
@ -144,6 +147,10 @@ def test_autolock_does_not_interrupt_signing(device_handler: "BackgroundDeviceHa
|
|||||||
set_autolock_delay(device_handler, 10_000)
|
set_autolock_delay(device_handler, 10_000)
|
||||||
|
|
||||||
debug = device_handler.debuglink()
|
debug = device_handler.debuglink()
|
||||||
|
|
||||||
|
# Prepare session to use later
|
||||||
|
session = device_handler.client.get_session()
|
||||||
|
|
||||||
# try to sign a transaction
|
# try to sign a transaction
|
||||||
inp1 = messages.TxInputType(
|
inp1 = messages.TxInputType(
|
||||||
address_n=parse_path("86h/0h/0h/0/0"),
|
address_n=parse_path("86h/0h/0h/0/0"),
|
||||||
@ -159,8 +166,8 @@ def test_autolock_does_not_interrupt_signing(device_handler: "BackgroundDeviceHa
|
|||||||
script_type=messages.OutputScriptType.PAYTOADDRESS,
|
script_type=messages.OutputScriptType.PAYTOADDRESS,
|
||||||
)
|
)
|
||||||
|
|
||||||
device_handler.run(
|
device_handler.run_with_provided_session(
|
||||||
btc.sign_tx, "Bitcoin", [inp1], [out1], prev_txes=TX_CACHE_MAINNET
|
session, btc.sign_tx, "Bitcoin", [inp1], [out1], prev_txes=TX_CACHE_MAINNET
|
||||||
)
|
)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
@ -190,14 +197,14 @@ def test_autolock_does_not_interrupt_signing(device_handler: "BackgroundDeviceHa
|
|||||||
|
|
||||||
def sleepy_filter(msg: MessageType) -> MessageType:
|
def sleepy_filter(msg: MessageType) -> MessageType:
|
||||||
time.sleep(10.1)
|
time.sleep(10.1)
|
||||||
device_handler.client.set_filter(messages.TxAck, None)
|
session.set_filter(messages.TxAck, None)
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
with device_handler.client:
|
with session, device_handler.client:
|
||||||
device_handler.client.set_filter(messages.TxAck, sleepy_filter)
|
session.set_filter(messages.TxAck, sleepy_filter)
|
||||||
# confirm transaction
|
# confirm transaction
|
||||||
if debug.layout_type is LayoutType.Bolt:
|
if debug.layout_type is LayoutType.Bolt:
|
||||||
debug.click(debug.screen_buttons.ok())
|
debug.click(debug.screen_buttons.ok(), hold_ms=1000)
|
||||||
elif debug.layout_type is LayoutType.Delizia:
|
elif debug.layout_type is LayoutType.Delizia:
|
||||||
debug.click(debug.screen_buttons.tap_to_confirm())
|
debug.click(debug.screen_buttons.tap_to_confirm())
|
||||||
elif debug.layout_type is LayoutType.Caesar:
|
elif debug.layout_type is LayoutType.Caesar:
|
||||||
@ -206,7 +213,6 @@ def test_autolock_does_not_interrupt_signing(device_handler: "BackgroundDeviceHa
|
|||||||
signatures, tx = device_handler.result()
|
signatures, tx = device_handler.result()
|
||||||
assert len(signatures) == 1
|
assert len(signatures) == 1
|
||||||
assert tx
|
assert tx
|
||||||
|
|
||||||
assert device_handler.features().unlocked is False
|
assert device_handler.features().unlocked is False
|
||||||
|
|
||||||
|
|
||||||
@ -215,9 +221,10 @@ def test_autolock_passphrase_keyboard(device_handler: "BackgroundDeviceHandler")
|
|||||||
set_autolock_delay(device_handler, 10_000)
|
set_autolock_delay(device_handler, 10_000)
|
||||||
debug = device_handler.debuglink()
|
debug = device_handler.debuglink()
|
||||||
|
|
||||||
# get address
|
session = Session(SessionV1.new(device_handler.client))
|
||||||
device_handler.run(common.get_test_address) # type: ignore
|
# session = device_handler.client.get_session(passphrase=PASSPHRASE_ON_DEVICE)
|
||||||
|
|
||||||
|
device_handler.run_with_provided_session(session, derive_seed, passphrase=PASSPHRASE_ON_DEVICE) # type: ignore
|
||||||
assert "PassphraseKeyboard" in debug.read_layout().all_components()
|
assert "PassphraseKeyboard" in debug.read_layout().all_components()
|
||||||
|
|
||||||
if debug.layout_type is LayoutType.Caesar:
|
if debug.layout_type is LayoutType.Caesar:
|
||||||
@ -243,7 +250,10 @@ def test_autolock_passphrase_keyboard(device_handler: "BackgroundDeviceHandler")
|
|||||||
elif debug.layout_type is LayoutType.Caesar:
|
elif debug.layout_type is LayoutType.Caesar:
|
||||||
debug.input("j" * 8)
|
debug.input("j" * 8)
|
||||||
|
|
||||||
# address corresponding to "jjjjjjjj" passphrase
|
device_handler.result()
|
||||||
|
|
||||||
|
# get address corresponding to "jjjjjjjj" passphrase
|
||||||
|
device_handler.run_with_provided_session(session, common.get_test_address)
|
||||||
assert device_handler.result() == "mnF4yRWJXmzRB6EuBzuVigqeqTqirQupxJ"
|
assert device_handler.result() == "mnF4yRWJXmzRB6EuBzuVigqeqTqirQupxJ"
|
||||||
|
|
||||||
|
|
||||||
@ -252,9 +262,11 @@ def test_autolock_interrupts_passphrase(device_handler: "BackgroundDeviceHandler
|
|||||||
set_autolock_delay(device_handler, 10_000)
|
set_autolock_delay(device_handler, 10_000)
|
||||||
debug = device_handler.debuglink()
|
debug = device_handler.debuglink()
|
||||||
|
|
||||||
# get address
|
# get address (derive_seed)
|
||||||
device_handler.run(common.get_test_address) # type: ignore
|
session = Session(SessionV1.new(client=device_handler.client))
|
||||||
|
device_handler.run_with_provided_session(
|
||||||
|
session, derive_seed, passphrase=PASSPHRASE_ON_DEVICE
|
||||||
|
) # type: ignore
|
||||||
assert "PassphraseKeyboard" in debug.read_layout().all_components()
|
assert "PassphraseKeyboard" in debug.read_layout().all_components()
|
||||||
|
|
||||||
if debug.layout_type is LayoutType.Caesar:
|
if debug.layout_type is LayoutType.Caesar:
|
||||||
@ -293,7 +305,7 @@ def test_dryrun_locks_at_number_of_words(device_handler: "BackgroundDeviceHandle
|
|||||||
set_autolock_delay(device_handler, 10_000)
|
set_autolock_delay(device_handler, 10_000)
|
||||||
debug = device_handler.debuglink()
|
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)
|
layout = unlock_dry_run(debug)
|
||||||
assert TR.recovery__num_of_words in debug.read_layout().text_content()
|
assert TR.recovery__num_of_words in debug.read_layout().text_content()
|
||||||
@ -326,7 +338,7 @@ def test_dryrun_locks_at_word_entry(device_handler: "BackgroundDeviceHandler"):
|
|||||||
set_autolock_delay(device_handler, 10_000)
|
set_autolock_delay(device_handler, 10_000)
|
||||||
debug = device_handler.debuglink()
|
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)
|
unlock_dry_run(debug)
|
||||||
|
|
||||||
@ -353,7 +365,7 @@ def test_dryrun_enter_word_slowly(device_handler: "BackgroundDeviceHandler"):
|
|||||||
set_autolock_delay(device_handler, 10_000)
|
set_autolock_delay(device_handler, 10_000)
|
||||||
debug = device_handler.debuglink()
|
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)
|
unlock_dry_run(debug)
|
||||||
|
|
||||||
@ -418,7 +430,11 @@ def test_autolock_does_not_interrupt_preauthorized(
|
|||||||
|
|
||||||
debug = device_handler.debuglink()
|
debug = device_handler.debuglink()
|
||||||
|
|
||||||
device_handler.run(
|
# Prepare session to use later
|
||||||
|
session = device_handler.client.get_session()
|
||||||
|
|
||||||
|
device_handler.run_with_provided_session(
|
||||||
|
session,
|
||||||
btc.authorize_coinjoin,
|
btc.authorize_coinjoin,
|
||||||
coordinator="www.example.com",
|
coordinator="www.example.com",
|
||||||
max_rounds=2,
|
max_rounds=2,
|
||||||
@ -532,14 +548,15 @@ def test_autolock_does_not_interrupt_preauthorized(
|
|||||||
|
|
||||||
def sleepy_filter(msg: MessageType) -> MessageType:
|
def sleepy_filter(msg: MessageType) -> MessageType:
|
||||||
time.sleep(10.1)
|
time.sleep(10.1)
|
||||||
device_handler.client.set_filter(messages.SignTx, None)
|
session.set_filter(messages.SignTx, None)
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
with device_handler.client:
|
with session:
|
||||||
# Start DoPreauthorized flow when device is unlocked. Wait 10s before
|
# Start DoPreauthorized flow when device is unlocked. Wait 10s before
|
||||||
# delivering SignTx, by that time autolock timer should have fired.
|
# delivering SignTx, by that time autolock timer should have fired.
|
||||||
device_handler.client.set_filter(messages.SignTx, sleepy_filter)
|
session.set_filter(messages.SignTx, sleepy_filter)
|
||||||
device_handler.run(
|
device_handler.run_with_provided_session(
|
||||||
|
session,
|
||||||
btc.sign_tx,
|
btc.sign_tx,
|
||||||
"Testnet",
|
"Testnet",
|
||||||
inputs,
|
inputs,
|
||||||
|
@ -52,7 +52,9 @@ def test_backup_slip39_custom(
|
|||||||
|
|
||||||
assert features.initialized is False
|
assert features.initialized is False
|
||||||
|
|
||||||
device_handler.run(
|
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,
|
||||||
@ -71,7 +73,7 @@ def test_backup_slip39_custom(
|
|||||||
# retrieve the result to check that it's not a TrezorFailure exception
|
# retrieve the result to check that it's not a TrezorFailure exception
|
||||||
device_handler.result()
|
device_handler.result()
|
||||||
|
|
||||||
device_handler.run(
|
device_handler.run_with_session(
|
||||||
device.backup,
|
device.backup,
|
||||||
group_threshold=group_threshold,
|
group_threshold=group_threshold,
|
||||||
groups=[(share_threshold, share_count)],
|
groups=[(share_threshold, share_count)],
|
||||||
|
@ -19,7 +19,7 @@ from typing import TYPE_CHECKING
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from trezorlib import models
|
from trezorlib import messages, models
|
||||||
from trezorlib.debuglink import LayoutType
|
from trezorlib.debuglink import LayoutType
|
||||||
|
|
||||||
from .. import common
|
from .. import common
|
||||||
@ -34,6 +34,9 @@ PIN4 = "1234"
|
|||||||
@pytest.mark.setup_client(pin=PIN4)
|
@pytest.mark.setup_client(pin=PIN4)
|
||||||
def test_hold_to_lock(device_handler: "BackgroundDeviceHandler"):
|
def test_hold_to_lock(device_handler: "BackgroundDeviceHandler"):
|
||||||
debug = device_handler.debuglink()
|
debug = device_handler.debuglink()
|
||||||
|
session = device_handler.client.get_seedless_session()
|
||||||
|
session.call(messages.LockDevice())
|
||||||
|
session.refresh_features()
|
||||||
|
|
||||||
short_duration = {
|
short_duration = {
|
||||||
models.T1B1: 500,
|
models.T1B1: 500,
|
||||||
@ -59,22 +62,25 @@ def test_hold_to_lock(device_handler: "BackgroundDeviceHandler"):
|
|||||||
assert device_handler.features().unlocked is False
|
assert device_handler.features().unlocked is False
|
||||||
|
|
||||||
# unlock with message
|
# 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()
|
assert "PinKeyboard" in debug.read_layout().all_components()
|
||||||
debug.input("1234")
|
debug.input(PIN4)
|
||||||
assert device_handler.result()
|
assert device_handler.result()
|
||||||
|
|
||||||
|
session.refresh_features()
|
||||||
assert device_handler.features().unlocked is True
|
assert device_handler.features().unlocked is True
|
||||||
|
|
||||||
# short touch
|
# short touch
|
||||||
hold(short_duration)
|
hold(short_duration)
|
||||||
|
|
||||||
time.sleep(0.5) # so that the homescreen appears again (hacky)
|
time.sleep(0.5) # so that the homescreen appears again (hacky)
|
||||||
|
session.refresh_features()
|
||||||
assert device_handler.features().unlocked is True
|
assert device_handler.features().unlocked is True
|
||||||
|
|
||||||
# lock
|
# lock
|
||||||
hold(lock_duration)
|
hold(lock_duration)
|
||||||
|
session.refresh_features()
|
||||||
assert device_handler.features().unlocked is False
|
assert device_handler.features().unlocked is False
|
||||||
|
|
||||||
# unlock by touching
|
# unlock by touching
|
||||||
@ -86,8 +92,10 @@ def test_hold_to_lock(device_handler: "BackgroundDeviceHandler"):
|
|||||||
assert "PinKeyboard" in layout.all_components()
|
assert "PinKeyboard" in layout.all_components()
|
||||||
debug.input("1234")
|
debug.input("1234")
|
||||||
|
|
||||||
|
session.refresh_features()
|
||||||
assert device_handler.features().unlocked is True
|
assert device_handler.features().unlocked is True
|
||||||
|
|
||||||
# lock
|
# lock
|
||||||
hold(lock_duration)
|
hold(lock_duration)
|
||||||
|
session.refresh_features()
|
||||||
assert device_handler.features().unlocked is False
|
assert device_handler.features().unlocked is False
|
||||||
|
@ -20,9 +20,12 @@ from typing import TYPE_CHECKING, Generator, Optional
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from trezorlib import messages
|
||||||
from trezorlib.debuglink import LayoutType
|
from trezorlib.debuglink import LayoutType
|
||||||
|
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, get_char_category
|
from .common import CommonPass, PassphraseCategory, get_char_category
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
@ -68,12 +71,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(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,
|
||||||
@ -86,12 +89,29 @@ CATEGORY_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
|
||||||
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(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() == ""
|
||||||
|
@ -90,17 +90,19 @@ def prepare(
|
|||||||
|
|
||||||
tap = False
|
tap = False
|
||||||
|
|
||||||
|
device_handler.client.get_seedless_session().lock()
|
||||||
|
|
||||||
# Setup according to the wanted situation
|
# Setup according to the wanted situation
|
||||||
if situation == Situation.PIN_INPUT:
|
if situation == Situation.PIN_INPUT:
|
||||||
# Any action triggering the PIN dialogue
|
# 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
|
tap = True
|
||||||
if situation == Situation.PIN_INPUT_CANCEL:
|
if situation == Situation.PIN_INPUT_CANCEL:
|
||||||
# Any action triggering the PIN dialogue
|
# 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:
|
elif situation == Situation.PIN_SETUP:
|
||||||
# Set new PIN
|
# Set new PIN
|
||||||
device_handler.run(device.change_pin) # type: ignore
|
device_handler.run_with_session(device.change_pin) # type: ignore
|
||||||
assert (
|
assert (
|
||||||
TR.pin__turn_on in debug.read_layout().text_content()
|
TR.pin__turn_on in debug.read_layout().text_content()
|
||||||
or TR.pin__info in debug.read_layout().text_content()
|
or TR.pin__info in debug.read_layout().text_content()
|
||||||
@ -114,14 +116,14 @@ def prepare(
|
|||||||
go_next(debug)
|
go_next(debug)
|
||||||
elif situation == Situation.PIN_CHANGE:
|
elif situation == Situation.PIN_CHANGE:
|
||||||
# Change PIN
|
# 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)
|
_input_see_confirm(debug, old_pin)
|
||||||
assert TR.pin__change in debug.read_layout().text_content()
|
assert TR.pin__change in debug.read_layout().text_content()
|
||||||
go_next(debug)
|
go_next(debug)
|
||||||
_input_see_confirm(debug, old_pin)
|
_input_see_confirm(debug, old_pin)
|
||||||
elif situation == Situation.WIPE_CODE_SETUP:
|
elif situation == Situation.WIPE_CODE_SETUP:
|
||||||
# Set wipe code
|
# 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:
|
if old_pin:
|
||||||
_input_see_confirm(debug, old_pin)
|
_input_see_confirm(debug, old_pin)
|
||||||
assert TR.wipe_code__turn_on in debug.read_layout().text_content()
|
assert TR.wipe_code__turn_on in debug.read_layout().text_content()
|
||||||
|
@ -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(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(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(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)
|
||||||
@ -129,7 +139,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.call(messages.Initialize())
|
session = SessionV1(device_handler.client, id=b"")
|
||||||
|
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(
|
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,
|
||||||
@ -93,7 +95,7 @@ def test_repeated_backup(
|
|||||||
assert features.recovery_status == messages.RecoveryStatus.Nothing
|
assert features.recovery_status == messages.RecoveryStatus.Nothing
|
||||||
|
|
||||||
# run recovery to unlock backup
|
# run recovery to unlock backup
|
||||||
device_handler.run(
|
device_handler.run_with_session(
|
||||||
device.recover,
|
device.recover,
|
||||||
type=messages.RecoveryType.UnlockRepeatedBackup,
|
type=messages.RecoveryType.UnlockRepeatedBackup,
|
||||||
)
|
)
|
||||||
@ -160,7 +162,7 @@ def test_repeated_backup(
|
|||||||
assert features.recovery_status == messages.RecoveryStatus.Nothing
|
assert features.recovery_status == messages.RecoveryStatus.Nothing
|
||||||
|
|
||||||
# try to unlock backup again...
|
# try to unlock backup again...
|
||||||
device_handler.run(
|
device_handler.run_with_session(
|
||||||
device.recover,
|
device.recover,
|
||||||
type=messages.RecoveryType.UnlockRepeatedBackup,
|
type=messages.RecoveryType.UnlockRepeatedBackup,
|
||||||
)
|
)
|
||||||
|
@ -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(
|
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(
|
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(
|
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(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(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(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(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(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(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