From e19a58fb6ea93d56fe836c78d974b3d0bd7c4a55 Mon Sep 17 00:00:00 2001 From: matejcik Date: Tue, 21 Nov 2023 16:55:46 +0100 Subject: [PATCH] tests: fix small irregularities --- tests/click_tests/test_lock.py | 3 +- tests/common.py | 6 +- tests/input_flows.py | 78 +++++++++++++---------- tests/input_flows_helpers.py | 31 +++++---- tests/persistence_tests/test_wipe_code.py | 6 +- 5 files changed, 69 insertions(+), 55 deletions(-) diff --git a/tests/click_tests/test_lock.py b/tests/click_tests/test_lock.py index b4c0e19102..dc9872b513 100644 --- a/tests/click_tests/test_lock.py +++ b/tests/click_tests/test_lock.py @@ -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() diff --git a/tests/common.py b/tests/common.py index 03cb543c26..4e5fff1be9 100644 --- a/tests/common.py +++ b/tests/common.py @@ -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"): diff --git a/tests/input_flows.py b/tests/input_flows.py index b6c0b2a2c6..89a1e4ce63 100644 --- a/tests/input_flows.py +++ b/tests/input_flows.py @@ -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() diff --git a/tests/input_flows_helpers.py b/tests/input_flows_helpers.py index f11685647f..0538af3cf3 100644 --- a/tests/input_flows_helpers.py +++ b/tests/input_flows_helpers.py @@ -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): diff --git a/tests/persistence_tests/test_wipe_code.py b/tests/persistence_tests/test_wipe_code.py index 9ea3822725..46dd5a1834 100644 --- a/tests/persistence_tests/test_wipe_code.py +++ b/tests/persistence_tests/test_wipe_code.py @@ -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)