1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-07-04 13:52:35 +00:00

tests: fix small irregularities

This commit is contained in:
matejcik 2023-11-21 16:55:46 +01:00 committed by M1nd3r
parent ee5443a9ec
commit e19a58fb6e
5 changed files with 69 additions and 55 deletions

View File

@ -76,8 +76,7 @@ def test_hold_to_lock(device_handler: "BackgroundDeviceHandler"):
# unlock by touching
if debug.model in (models.T2B1,):
# Doing a short HTC to simulate a click
layout = debug.press_right(hold_ms=100)
layout = debug.press_right()
else:
layout = debug.click(buttons.INFO)
assert "PinKeyboard" in layout.all_components()

View File

@ -20,7 +20,7 @@ import json
import re
import time
from pathlib import Path
from typing import TYPE_CHECKING, Generator, Optional
from typing import TYPE_CHECKING, Any, Generator, Optional
from unittest import mock
import pytest
@ -308,11 +308,11 @@ def check_share(
return True
def click_info_button_tt(debug: "DebugLink"):
def click_info_button_tt(debug: "DebugLink") -> Generator[Any, Any, ButtonRequest]:
"""Click Shamir backup info button and return back."""
debug.press_info()
debug.press_yes()
yield
return (yield)
def click_info_button_mercury(debug: "DebugLink"):

View File

@ -465,11 +465,11 @@ class InputFlowShowMultisigXPUBs(InputFlowBase):
# Three xpub pages with the same testing logic
for xpub_num in range(3):
expected_title = f"MULTISIG XPUB #{xpub_num + 1}\n" + (
"(YOURS)" if self.index == xpub_num else "(COSIGNER)"
expected_title = f"multisig xpub #{xpub_num + 1}\n" + (
"(yours)" if self.index == xpub_num else "(cosigner)"
)
layout = self.debug.swipe_left()
assert expected_title == layout.title()
assert expected_title == layout.title().lower()
content = layout.text_content().replace(" ", "")
assert self.xpubs[xpub_num] in content
@ -1019,15 +1019,15 @@ class InputFlowSignTxInformationReplacement(InputFlowBase):
yield # confirm txid
self.debug.press_right()
self.debug.press_right()
yield # confirm address
yield # modify amount - address
self.debug.press_right()
self.debug.press_right()
yield # modify amount - amount
self.debug.press_right()
yield # modify fee
self.debug.press_right()
self.debug.press_right()
self.debug.press_right()
yield # confirm amount
self.debug.press_right()
self.debug.press_right()
self.debug.press_right()
yield
def input_flow_t3t1(self) -> BRGeneratorType:
yield # confirm txid
@ -1470,23 +1470,29 @@ class InputFlowSlip39BasicBackup(InputFlowBase):
self.repeated = repeated
def input_flow_tt(self) -> BRGeneratorType:
yield # 1. Checklist
if self.repeated:
assert (yield).name == "confirm_repeated_backup"
self.debug.press_yes()
assert (yield).name == "backup_intro"
self.debug.press_yes()
yield # 2. Number of shares (5)
assert (yield).name == "slip39_checklist"
self.debug.press_yes()
assert (yield).name == "slip39_shares"
if self.click_info:
yield from click_info_button_tt(self.debug)
yield # 3. Number of shares (5)
br = yield from click_info_button_tt(self.debug)
assert br.name == "slip39_shares"
self.debug.press_yes()
yield # 4. Checklist
assert (yield).name == "slip39_checklist"
self.debug.press_yes()
yield # 4. Threshold (3)
assert (yield).name == "slip39_threshold"
if self.click_info:
yield from click_info_button_tt(self.debug)
yield # 5. Threshold (3)
br = yield from click_info_button_tt(self.debug)
assert br.name == "slip39_threshold"
self.debug.press_yes()
yield # 6. Checklist
assert (yield).name == "slip39_checklist"
self.debug.press_yes()
yield # 7. Confirm show seeds
assert (yield).name == "backup_warning"
self.debug.press_yes()
# Mnemonic phrases
@ -1738,34 +1744,36 @@ class InputFlowSlip39AdvancedBackup(InputFlowBase):
self.click_info = click_info
def input_flow_tt(self) -> BRGeneratorType:
yield # 1. Backup intro
assert (yield).name == "backup_intro"
self.debug.press_yes()
yield # 2. Checklist
assert (yield).name == "slip39_checklist"
self.debug.press_yes()
yield # 2. Set and confirm group count
assert (yield).name == "slip39_groups"
if self.click_info:
yield from click_info_button_tt(self.debug)
yield # 3. Set and confirm group count
br = yield from click_info_button_tt(self.debug)
assert br.name == "slip39_groups"
self.debug.press_yes()
yield # 4. Checklist
assert (yield).name == "slip39_checklist"
self.debug.press_yes()
yield # 4. Set and confirm group threshold
assert (yield).name == "slip39_group_threshold"
if self.click_info:
yield from click_info_button_tt(self.debug)
yield # 5. Set and confirm group threshold
br = yield from click_info_button_tt(self.debug)
assert br.name == "slip39_group_threshold"
self.debug.press_yes()
yield # 6. Checklist
assert (yield).name == "slip39_checklist"
self.debug.press_yes()
for _ in range(5): # for each of 5 groups
yield # Set & Confirm number of shares
assert (yield).name == "slip39_shares"
if self.click_info:
yield from click_info_button_tt(self.debug)
br = yield from click_info_button_tt(self.debug)
assert br.name == "slip39_shares"
self.debug.press_yes()
yield # Set & confirm share threshold value
assert (yield).name == "slip39_threshold"
if self.click_info:
yield from click_info_button_tt(self.debug)
br = yield from click_info_button_tt(self.debug)
assert br.name == "slip39_threshold"
self.debug.press_yes()
yield # Confirm show seeds
assert (yield).name == "backup_warning"
self.debug.press_yes()
# Mnemonic phrases - show & confirm shares for all groups
@ -2114,7 +2122,7 @@ class InputFlowSlip39BasicRecoveryDryRun(InputFlowBase):
yield from self.REC.input_all_slip39_shares(self.shares)
if self.mismatch:
yield from self.REC.warning_slip39_dryrun_mismatch()
else:
elif not self.unlock_repeated_backup:
yield from self.REC.success_slip39_dryrun_valid()

View File

@ -1,3 +1,5 @@
import typing as t
from trezorlib import messages, models
from trezorlib.debuglink import TrezorClientDebugLink as Client
@ -56,14 +58,14 @@ class RecoveryFlow:
return layout.title() + " " + layout.text_content()
def confirm_recovery(self) -> BRGeneratorType:
yield
assert (yield).name == "recover_device"
TR.assert_in(self._text_content(), "reset__by_continuing")
if self.client.model is models.T2B1:
self.debug.press_right()
self.debug.press_yes()
def confirm_dry_run(self) -> BRGeneratorType:
yield
assert (yield).name == "confirm_seedcheck"
TR.assert_in(self._text_content(), "recovery__check_dry_run")
self.debug.press_yes()
@ -91,7 +93,7 @@ class RecoveryFlow:
self.debug.press_yes()
def enter_your_backup(self) -> BRGeneratorType:
yield
assert (yield).name == "recovery"
if self.debug.model is models.T3T1:
TR.assert_in(self._text_content(), "recovery__enter_each_word")
else:
@ -107,7 +109,7 @@ class RecoveryFlow:
self.debug.press_yes()
def enter_any_share(self) -> BRGeneratorType:
yield
assert (yield).name == "recovery"
TR.assert_in_multiple(
self._text_content(),
["recovery__enter_any_share", "recovery__enter_each_word"],
@ -186,6 +188,7 @@ class RecoveryFlow:
def input_number_of_words(self, num_words: int) -> BRGeneratorType:
br = yield
assert br.code == B.MnemonicWordCount
assert br.name == "word_count"
if self.client.model is models.T2B1:
TR.assert_in(self.debug.read_layout().title(), "word_count__title")
else:
@ -225,7 +228,7 @@ class RecoveryFlow:
self.debug.press_yes()
def success_share_group_entered(self) -> BRGeneratorType:
yield
assert (yield).name == "share_success"
TR.assert_in(self._text_content(), "recovery__you_have_entered")
self.debug.press_yes()
@ -275,6 +278,7 @@ class RecoveryFlow:
self, count_needed: int | None = None
) -> BRGeneratorType:
br = yield
assert br.name == "recovery"
text = get_text_possible_pagination(self.debug, br)
if count_needed is not None:
assert str(count_needed) in text
@ -283,6 +287,7 @@ class RecoveryFlow:
def input_mnemonic(self, mnemonic: list[str]) -> BRGeneratorType:
br = yield
assert br.code == B.MnemonicInput
assert br.name == "mnemonic"
assert "MnemonicKeyboard" in self.debug.read_layout().all_components()
for _, word in enumerate(mnemonic):
self.debug.input(word)
@ -301,19 +306,21 @@ class RecoveryFlow:
if has_groups:
yield from self.success_share_group_entered()
if click_info:
assert (yield).name == "recovery"
if self.client.model is models.T2T1:
yield from self.tt_click_info()
elif self.client.model is models.T3T1:
self.mercury_click_info()
yield from self.success_more_shares_needed()
self.debug.press_yes()
else:
yield from self.success_more_shares_needed()
def tt_click_info(
self,
) -> BRGeneratorType:
# Moving through the INFO button
yield
def tt_click_info(self) -> t.Generator[t.Any, t.Any, None]:
self.debug.press_info()
self.debug.swipe_up()
br = yield
assert br.name == "show_shares"
for _ in range(br.pages):
self.debug.swipe_up()
self.debug.press_yes()
def mercury_click_info(self):

View File

@ -1,5 +1,6 @@
from trezorlib import debuglink, device, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.debuglink import message_filters
from ..common import MNEMONIC12
from ..emulators import Emulator, EmulatorWrapper
@ -48,9 +49,8 @@ def test_wipe_code_activate_core(core_emulator: Emulator):
ret = core_emulator.client.call_raw(messages.ButtonAck())
# Enter the wipe code instead of the current PIN
assert ret == messages.ButtonRequest(
code=messages.ButtonRequestType.PinEntry, name="pin_device"
)
expected = message_filters.ButtonRequest(code=messages.ButtonRequestType.PinEntry)
assert expected.match(ret)
core_emulator.client._raw_write(messages.ButtonAck())
core_emulator.client.debug.input(WIPE_CODE)