From e199d2bcaf0391364815de079140ebd8c4fad180 Mon Sep 17 00:00:00 2001 From: matejcik Date: Thu, 10 Oct 2024 15:43:26 +0200 Subject: [PATCH] fix(tests): fix persistence tests, enable T3B1 --- .github/workflows/core.yml | 4 +-- tests/click_tests/recovery.py | 3 +- tests/click_tests/test_recovery.py | 10 ------ tests/input_flows.py | 26 -------------- .../test_shamir_persistence.py | 35 ++++++++++--------- tests/persistence_tests/test_wipe_code.py | 5 ++- tests/ui_tests/fixtures.json | 32 ++++++++--------- 7 files changed, 41 insertions(+), 74 deletions(-) diff --git a/.github/workflows/core.yml b/.github/workflows/core.yml index e70d39e6d5..4c4509c33f 100644 --- a/.github/workflows/core.yml +++ b/.github/workflows/core.yml @@ -21,7 +21,7 @@ env: |core UI changes|device test|click test|persistence test| |---------------|-----------|----------|----------------| |T2T1 Model T | [test](https://data.trezor.io/dev/firmware/ui_report/${{ github.run_id }}/T2T1-en-core_device_test/index.html)([screens](https://data.trezor.io/dev/firmware/ui_report/${{ github.run_id }}/T2T1-en-core_device_test/differing_screens.html)) [main](https://data.trezor.io/dev/firmware/ui_report/${{ github.run_id }}/T2T1-en-core_device_test/master_index.html)([screens](https://data.trezor.io/dev/firmware/ui_report/${{ github.run_id }}/T2T1-en-core_device_test/master_diff.html)) | [test](https://data.trezor.io/dev/firmware/ui_report/${{ github.run_id }}/T2T1-en-core_click_test/index.html)([screens](https://data.trezor.io/dev/firmware/ui_report/${{ github.run_id }}/T2T1-en-core_click_test/differing_screens.html)) [main](https://data.trezor.io/dev/firmware/ui_report/${{ github.run_id }}/T2T1-en-core_click_test/master_index.html)([screens](https://data.trezor.io/dev/firmware/ui_report/${{ github.run_id }}/T2T1-en-core_click_test/master_diff.html)) | [test](https://data.trezor.io/dev/firmware/ui_report/${{ github.run_id }}/T2T1-en-core_persistence_test/index.html)([screens](https://data.trezor.io/dev/firmware/ui_report/${{ github.run_id }}/T2T1-en-core_persistence_test/differing_screens.html)) [main](https://data.trezor.io/dev/firmware/ui_report/${{ github.run_id }}/T2T1-en-core_persistence_test/master_index.html)([screens](https://data.trezor.io/dev/firmware/ui_report/${{ github.run_id }}/T2T1-en-core_persistence_test/master_diff.html))|| - |T3B1 Safe 3 | [test](https://data.trezor.io/dev/firmware/ui_report/${{ github.run_id }}/T3B1-en-core_device_test/index.html)([screens](https://data.trezor.io/dev/firmware/ui_report/${{ github.run_id }}/T3B1-en-core_device_test/differing_screens.html)) [main](https://data.trezor.io/dev/firmware/ui_report/${{ github.run_id }}/T3B1-en-core_device_test/master_index.html)([screens](https://data.trezor.io/dev/firmware/ui_report/${{ github.run_id }}/T3B1-en-core_device_test/master_diff.html)) | [test](https://data.trezor.io/dev/firmware/ui_report/${{ github.run_id }}/T3B1-en-core_click_test/index.html)([screens](https://data.trezor.io/dev/firmware/ui_report/${{ github.run_id }}/T3B1-en-core_click_test/differing_screens.html)) [main](https://data.trezor.io/dev/firmware/ui_report/${{ github.run_id }}/T3B1-en-core_click_test/master_index.html)([screens](https://data.trezor.io/dev/firmware/ui_report/${{ github.run_id }}/T3B1-en-core_click_test/master_diff.html)) |[2724](https://github.com/trezor/trezor-firmware/issues/2724) || + |T3B1 Safe 3 | [test](https://data.trezor.io/dev/firmware/ui_report/${{ github.run_id }}/T3B1-en-core_device_test/index.html)([screens](https://data.trezor.io/dev/firmware/ui_report/${{ github.run_id }}/T3B1-en-core_device_test/differing_screens.html)) [main](https://data.trezor.io/dev/firmware/ui_report/${{ github.run_id }}/T3B1-en-core_device_test/master_index.html)([screens](https://data.trezor.io/dev/firmware/ui_report/${{ github.run_id }}/T3B1-en-core_device_test/master_diff.html)) | [test](https://data.trezor.io/dev/firmware/ui_report/${{ github.run_id }}/T3B1-en-core_click_test/index.html)([screens](https://data.trezor.io/dev/firmware/ui_report/${{ github.run_id }}/T3B1-en-core_click_test/differing_screens.html)) [main](https://data.trezor.io/dev/firmware/ui_report/${{ github.run_id }}/T3B1-en-core_click_test/master_index.html)([screens](https://data.trezor.io/dev/firmware/ui_report/${{ github.run_id }}/T3B1-en-core_click_test/master_diff.html)) | [test](https://data.trezor.io/dev/firmware/ui_report/${{ github.run_id }}/T3B1-en-core_persistence_test/index.html)([screens](https://data.trezor.io/dev/firmware/ui_report/${{ github.run_id }}/T3B1-en-core_persistence_test/differing_screens.html)) [main](https://data.trezor.io/dev/firmware/ui_report/${{ github.run_id }}/T3B1-en-core_persistence_test/master_index.html)([screens](https://data.trezor.io/dev/firmware/ui_report/${{ github.run_id }}/T3B1-en-core_persistence_test/master_diff.html))|| |T3T1 Safe 5 | [test](https://data.trezor.io/dev/firmware/ui_report/${{ github.run_id }}/T3T1-en-core_device_test/index.html)([screens](https://data.trezor.io/dev/firmware/ui_report/${{ github.run_id }}/T3T1-en-core_device_test/differing_screens.html)) [main](https://data.trezor.io/dev/firmware/ui_report/${{ github.run_id }}/T3T1-en-core_device_test/master_index.html)([screens](https://data.trezor.io/dev/firmware/ui_report/${{ github.run_id }}/T3T1-en-core_device_test/master_diff.html)) | [test](https://data.trezor.io/dev/firmware/ui_report/${{ github.run_id }}/T3T1-en-core_click_test/index.html)([screens](https://data.trezor.io/dev/firmware/ui_report/${{ github.run_id }}/T3T1-en-core_click_test/differing_screens.html)) [main](https://data.trezor.io/dev/firmware/ui_report/${{ github.run_id }}/T3T1-en-core_click_test/master_index.html)([screens](https://data.trezor.io/dev/firmware/ui_report/${{ github.run_id }}/T3T1-en-core_click_test/master_diff.html)) | [test](https://data.trezor.io/dev/firmware/ui_report/${{ github.run_id }}/T3T1-en-core_persistence_test/index.html)([screens](https://data.trezor.io/dev/firmware/ui_report/${{ github.run_id }}/T3T1-en-core_persistence_test/differing_screens.html)) [main](https://data.trezor.io/dev/firmware/ui_report/${{ github.run_id }}/T3T1-en-core_persistence_test/master_index.html)([screens](https://data.trezor.io/dev/firmware/ui_report/${{ github.run_id }}/T3T1-en-core_persistence_test/master_diff.html))|| |All | [main](https://data.trezor.io/dev/firmware/master_diff/${{ github.run_id }}/index.html)([screens](https://data.trezor.io/dev/firmware/master_diff/${{ github.run_id }}/master_diff.html)) || @@ -381,7 +381,7 @@ jobs: strategy: fail-fast: false matrix: - model: [T2T1, T3T1] # TODO T3B1 https://github.com/trezor/trezor-firmware/issues/2724 + model: [T2T1, T3B1, T3T1] asan: ${{ fromJSON(needs.param.outputs.asan) }} env: TREZOR_PROFILING: ${{ matrix.asan == 'noasan' && '1' || '0' }} diff --git a/tests/click_tests/recovery.py b/tests/click_tests/recovery.py index c09046b85c..89a6b6bc8b 100644 --- a/tests/click_tests/recovery.py +++ b/tests/click_tests/recovery.py @@ -56,7 +56,8 @@ def confirm_recovery(debug: "DebugLink", title: str = "recovery__title") -> None elif debug.layout_type is LayoutType.Mercury: debug.swipe_up() elif debug.layout_type is LayoutType.TR: - debug.press_right() + for _ in range(layout.page_count()): + debug.press_right() def select_number_of_words( diff --git a/tests/click_tests/test_recovery.py b/tests/click_tests/test_recovery.py index 30cf136815..8770649296 100644 --- a/tests/click_tests/test_recovery.py +++ b/tests/click_tests/test_recovery.py @@ -20,7 +20,6 @@ from typing import TYPE_CHECKING, Generator import pytest from trezorlib import device, messages -from trezorlib.debuglink import LayoutType from ..common import MNEMONIC12, MNEMONIC_SLIP39_BASIC_20_3of6 from . import recovery @@ -55,9 +54,6 @@ def prepare_recovery_and_evaluate( def test_recovery_slip39_basic(device_handler: "BackgroundDeviceHandler"): with prepare_recovery_and_evaluate(device_handler) as debug: recovery.confirm_recovery(debug) - if debug.layout_type is LayoutType.TR: - recovery.confirm_recovery(debug) - recovery.select_number_of_words(debug) recovery.enter_shares(debug, MNEMONIC_SLIP39_BASIC_20_3of6) recovery.finalize(debug) @@ -67,9 +63,6 @@ def test_recovery_slip39_basic(device_handler: "BackgroundDeviceHandler"): def test_recovery_bip39(device_handler: "BackgroundDeviceHandler"): with prepare_recovery_and_evaluate(device_handler) as debug: recovery.confirm_recovery(debug) - if debug.layout_type is LayoutType.TR: - recovery.confirm_recovery(debug) - recovery.select_number_of_words(debug, num_of_words=12) recovery.enter_seed(debug, MNEMONIC12.split()) recovery.finalize(debug) @@ -79,9 +72,6 @@ def test_recovery_bip39(device_handler: "BackgroundDeviceHandler"): def test_recovery_bip39_previous_word(device_handler: "BackgroundDeviceHandler"): with prepare_recovery_and_evaluate(device_handler) as debug: recovery.confirm_recovery(debug) - if debug.layout_type is LayoutType.TR: - recovery.confirm_recovery(debug) - recovery.select_number_of_words(debug, num_of_words=12) seed_words: list[str] = MNEMONIC12.split() bad_indexes = {1: seed_words[-1], 7: seed_words[0]} diff --git a/tests/input_flows.py b/tests/input_flows.py index cd0956ea78..740f00f014 100644 --- a/tests/input_flows.py +++ b/tests/input_flows.py @@ -85,32 +85,6 @@ class InputFlowBase: return self.debug.read_layout().title() -class InputFlowSetupDevicePINWIpeCode(InputFlowBase): - def __init__(self, client: Client, pin: str, wipe_code: str): - super().__init__(client) - self.pin = pin - self.wipe_code = wipe_code - - def input_flow_common(self) -> BRGeneratorType: - yield # do you want to set/change the wipe code? - self.debug.press_yes() - - if self.client.layout_type is LayoutType.TR: - layout = self.debug.read_layout() - if "PinKeyboard" not in layout.all_components(): - yield from swipe_if_necessary(self.debug) # wipe code info - self.debug.press_yes() - - yield # enter current pin - self.debug.input(self.pin) - yield # enter new wipe code - self.debug.input(self.wipe_code) - yield # enter new wipe code again - self.debug.input(self.wipe_code) - yield # success - self.debug.press_yes() - - class InputFlowNewCodeMismatch(InputFlowBase): def __init__( self, diff --git a/tests/persistence_tests/test_shamir_persistence.py b/tests/persistence_tests/test_shamir_persistence.py index d3d13e6708..9d629657c6 100644 --- a/tests/persistence_tests/test_shamir_persistence.py +++ b/tests/persistence_tests/test_shamir_persistence.py @@ -16,12 +16,11 @@ import pytest -from trezorlib import device, models -from trezorlib.debuglink import DebugLink +from trezorlib import device +from trezorlib.debuglink import DebugLink, LayoutType from trezorlib.messages import RecoveryStatus -from .. import buttons -from ..click_tests import recovery +from ..click_tests import common, recovery from ..common import MNEMONIC_SLIP39_ADVANCED_20, MNEMONIC_SLIP39_BASIC_20_3of6 from ..device_handler import BackgroundDeviceHandler from ..emulators import Emulator @@ -41,16 +40,15 @@ def test_abort(core_emulator: Emulator): debug = device_handler.debuglink() features = device_handler.features() - if debug.model is models.T3T1: + if debug.layout_type is LayoutType.Mercury: pytest.skip("abort not supported on T3T1") assert features.recovery_status == RecoveryStatus.Nothing device_handler.run(device.recover, pin_protection=False) - assert debug.read_layout().title().lower() == "recover wallet" - - layout = debug.click(buttons.OK) + recovery.confirm_recovery(debug) + layout = debug.read_layout() assert "number of words" in layout.text_content() debug = _restart(device_handler, core_emulator) @@ -58,19 +56,19 @@ def test_abort(core_emulator: Emulator): assert features.recovery_status == RecoveryStatus.Recovery - # no waiting for layout because layout doesn't change assert "number of words" in debug.read_layout().text_content() - # clicking at 24 in word choice (the same coords as CANCEL) - layout = debug.click(buttons.CANCEL) + # clicking at 24 in word choice + recovery.select_number_of_words(debug, 24) # Cancelling the backup assert "Enter your backup" in debug.read_layout().text_content() - layout = debug.click(buttons.CANCEL) + layout = common.go_back(debug) assert layout.title().lower() in ("abort recovery", "cancel recovery") - layout = debug.click(buttons.OK) + for _ in range(layout.page_count()): + common.go_next(debug) - assert layout.main_component() == "Homescreen" + assert debug.read_layout().main_component() == "Homescreen" features = device_handler.features() assert features.recovery_status == RecoveryStatus.Nothing @@ -138,7 +136,10 @@ def test_recovery_on_old_wallet(core_emulator: Emulator): words = first_share.split(" ") # start entering first share - assert "Enter each word of your wallet backup" in debug.read_layout().text_content() + assert ( + "Enter any share" in debug.read_layout().text_content() + or "Enter each word" in debug.read_layout().text_content() + ) debug.press_yes() assert debug.read_layout().main_component() == "MnemonicKeyboard" @@ -176,7 +177,9 @@ def test_recovery_multiple_resets(core_emulator: Emulator): def enter_shares_with_restarts(debug: DebugLink) -> None: shares = MNEMONIC_SLIP39_ADVANCED_20 layout = debug.read_layout() - expected_text = "Enter each word of your wallet backup" + expected_text = "Enter any share" + if debug.layout_type == LayoutType.Mercury: + expected_text = "Enter each word" remaining = len(shares) for share in shares: assert expected_text in layout.text_content() diff --git a/tests/persistence_tests/test_wipe_code.py b/tests/persistence_tests/test_wipe_code.py index 46dd5a1834..2497a708f6 100644 --- a/tests/persistence_tests/test_wipe_code.py +++ b/tests/persistence_tests/test_wipe_code.py @@ -4,7 +4,6 @@ from trezorlib.debuglink import message_filters from ..common import MNEMONIC12 from ..emulators import Emulator, EmulatorWrapper -from ..input_flows import InputFlowSetupDevicePINWIpeCode from ..upgrade_tests import core_only, legacy_only PIN = "1234" @@ -29,8 +28,7 @@ def setup_device_core(client: Client, pin: str, wipe_code: str) -> None: ) with client: - IF = InputFlowSetupDevicePINWIpeCode(client, pin, wipe_code) - client.set_input_flow(IF.get()) + client.use_pin_sequence([pin, wipe_code, wipe_code]) device.change_wipe_code(client) @@ -45,6 +43,7 @@ def test_wipe_code_activate_core(core_emulator: Emulator): # Initiate Change pin process ret = core_emulator.client.call_raw(messages.ChangePin(remove=False)) assert isinstance(ret, messages.ButtonRequest) + assert ret.name == "change_pin" core_emulator.client.debug.press_yes() ret = core_emulator.client.call_raw(messages.ButtonAck()) diff --git a/tests/ui_tests/fixtures.json b/tests/ui_tests/fixtures.json index da85811f16..db5bdd77f4 100644 --- a/tests/ui_tests/fixtures.json +++ b/tests/ui_tests/fixtures.json @@ -9706,14 +9706,14 @@ "T2T1_pt_zcash-test_sign_tx.py::test_version_group_id_missing": "c8dd180b3a8e7a34d43048add9ede1704df12cf145d1a8803d896a82b864f344" }, "persistence_tests": { -"T2T1_en_test_safety_checks.py::test_safety_checks_level_after_reboot[SafetyCheckLevel.PromptAlways--081810a6": "384e8cfd6a476b25488bc4a2732ae7c4cf98a15826cee8cc9be5dc320883e423", -"T2T1_en_test_safety_checks.py::test_safety_checks_level_after_reboot[SafetyCheckLevel.PromptTempora-b3d21f4a": "4f957dc6cc7a5d73e6c3dfd0f498bf1148e086100de9b727b266bb7209c79af8", -"T2T1_en_test_safety_checks.py::test_safety_checks_level_after_reboot[SafetyCheckLevel.Strict-Safety-f1ff9c26": "3360ec26667b40053e8ae3a1a706f0988c1c338ea98e22e1ff0c04e4c5e042ae", -"T2T1_en_test_shamir_persistence.py::test_abort": "1d97cfb79dcec3dba5405766401f38c2284050db77b7da067dce80e55d43b01d", -"T2T1_en_test_shamir_persistence.py::test_recovery_multiple_resets": "394f6811166fd3739900324b34600028c92f5c112f1f7d2eab7bce54434dc0fa", -"T2T1_en_test_shamir_persistence.py::test_recovery_on_old_wallet": "06ab622055c6fb16c4751a0e17360565459d9530572181c8a807c880137893b1", -"T2T1_en_test_shamir_persistence.py::test_recovery_single_reset": "01748c2717cd2e1225884248f6fc676e825d942f60721bce1a42bb7e960f62ce", -"T2T1_en_test_wipe_code.py::test_wipe_code_activate_core": "36fab76eb0d08d289a3c97cfda4802a6d813f077564671645c665b372531befa" +"T2T1_en_test_safety_checks.py::test_safety_checks_level_after_reboot[SafetyCheckLevel.PromptAlways--081810a6": "d1e7905797c25c34e1be947b2cbcb655b4497068e6e6bdaccf88a1c821339085", +"T2T1_en_test_safety_checks.py::test_safety_checks_level_after_reboot[SafetyCheckLevel.PromptTempora-b3d21f4a": "d69338d8911fc6f4d4a9b4f23297537a9be60975694572d6c8cd1272c55d2af9", +"T2T1_en_test_safety_checks.py::test_safety_checks_level_after_reboot[SafetyCheckLevel.Strict-Safety-f1ff9c26": "458e2c14abebb664a50fef4082d8933d0db7c167439bcd7ffb11b7fca75dfb66", +"T2T1_en_test_shamir_persistence.py::test_abort": "2ff31047e86de855d4142040cb55fc38afffb4f7ac2a6ce623c77470c5255766", +"T2T1_en_test_shamir_persistence.py::test_recovery_multiple_resets": "f353c194c6e7a13b6950b2a6f98056b0f3596170135c34123c696db746b7834d", +"T2T1_en_test_shamir_persistence.py::test_recovery_on_old_wallet": "8405ef6de2513430b62149c70baec92a20def9a8b17206f45870ed4ed85b7c6b", +"T2T1_en_test_shamir_persistence.py::test_recovery_single_reset": "f83817579bb27bf151c0907ae2bd952a94d1939dce26215f5d97ddf5b25a5668", +"T2T1_en_test_wipe_code.py::test_wipe_code_activate_core": "80875ba4bae6dcd0a4a3d1438528bfe99c5bc4567ea6c357e59836271f265282" } }, "T3B1": { @@ -26708,14 +26708,14 @@ "T3T1_pt_zcash-test_sign_tx.py::test_version_group_id_missing": "708b1d45065e8456dc4d87f675b4014305d7e197b88b33485c30c10523577104" }, "persistence_tests": { -"T3T1_en_test_safety_checks.py::test_safety_checks_level_after_reboot[SafetyCheckLevel.PromptAlways--081810a6": "801da41901bb49a7cc2b0212964c060e3488e14af0ab7fdb27f10631111bcc84", -"T3T1_en_test_safety_checks.py::test_safety_checks_level_after_reboot[SafetyCheckLevel.PromptTempora-b3d21f4a": "e997cc958f7d7d262604e7728469f7a6952b60c0b1b3520252e3d58e49b41e66", -"T3T1_en_test_safety_checks.py::test_safety_checks_level_after_reboot[SafetyCheckLevel.Strict-Safety-f1ff9c26": "a0879b23f779049abf46c42608ee7b841a0b8dc4ac83b85ac83a83e992068165", -"T3T1_en_test_shamir_persistence.py::test_abort": "1a5d5ef3d81710c7a0a113514ac287b37d6ab66f284bfe34353dddf634714ea5", -"T3T1_en_test_shamir_persistence.py::test_recovery_multiple_resets": "ace0e626ddf56eeac716327fb92ea7a4bdaa155488f47d462ea371724d36acfc", -"T3T1_en_test_shamir_persistence.py::test_recovery_on_old_wallet": "89a5417c0f4dbdc2932ff705425306707d329bc65f8f9de5652f803c5d18a493", -"T3T1_en_test_shamir_persistence.py::test_recovery_single_reset": "1ee4f62b9967ed9a41575a96b1c115697a741dd3891953e4a96dfff800be203a", -"T3T1_en_test_wipe_code.py::test_wipe_code_activate_core": "aa4da89845a41383de2a091315a54b90996c1f71692adcfaa69886c35c4ad261" +"T3T1_en_test_safety_checks.py::test_safety_checks_level_after_reboot[SafetyCheckLevel.PromptAlways--081810a6": "b05832a6be652be0da7d63e6f29d03ec70c4d13c71d0f0140fb7b76970cbb9c6", +"T3T1_en_test_safety_checks.py::test_safety_checks_level_after_reboot[SafetyCheckLevel.PromptTempora-b3d21f4a": "f3bb5f6e8812aa5bd227209caca1db8b0cf339b3527cce200160cd141765d639", +"T3T1_en_test_safety_checks.py::test_safety_checks_level_after_reboot[SafetyCheckLevel.Strict-Safety-f1ff9c26": "2dd96d140aa4e025fb5accbd3bff3a565792474f9e3241f2a4b12a1fe5b58012", +"T3T1_en_test_shamir_persistence.py::test_abort": "bd699a53a1a7280a9106222c61dffc4a8967afeef8c5141485bd71eb06daf3de", +"T3T1_en_test_shamir_persistence.py::test_recovery_multiple_resets": "dfd6c4bc7168d3dfb1c068dcfe8c4768343d4bd1b3522c54eaf487644a6dc835", +"T3T1_en_test_shamir_persistence.py::test_recovery_on_old_wallet": "4fa6d5b04fe395594fdb1d428120647f127e23b9e6fd72b0bc5c6b12d618e76d", +"T3T1_en_test_shamir_persistence.py::test_recovery_single_reset": "27ad5d19eadfcbd4eae2283e499258790abcdebcb8a7f36b365241dd9a2b237d", +"T3T1_en_test_wipe_code.py::test_wipe_code_activate_core": "581f0fa3207ca2dc938187429b1a993d75b6ffe343a8ac9baddf027542786bac" } } }