From 9a4cb1887d2cf777bcd3f57a3d2aa2e81f7db36e Mon Sep 17 00:00:00 2001 From: grdddj Date: Wed, 9 Aug 2023 09:44:33 +0200 Subject: [PATCH] fix(core): raise ActionCancelled when cancelling tutorial flow for TR [no changelog] --- core/src/trezor/ui/layouts/tr/__init__.py | 10 ++++++---- tests/click_tests/test_tutorial.py | 13 +++++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/core/src/trezor/ui/layouts/tr/__init__.py b/core/src/trezor/ui/layouts/tr/__init__.py index 5661535b8..3ccb5391c 100644 --- a/core/src/trezor/ui/layouts/tr/__init__.py +++ b/core/src/trezor/ui/layouts/tr/__init__.py @@ -684,10 +684,12 @@ async def tutorial( br_code: ButtonRequestType = BR_TYPE_OTHER, ) -> None: """Showing users how to interact with the device.""" - await interact( - RustLayout(trezorui2.tutorial()), - "tutorial", - br_code, + await raise_if_not_confirmed( + interact( + RustLayout(trezorui2.tutorial()), + "tutorial", + br_code, + ) ) diff --git a/tests/click_tests/test_tutorial.py b/tests/click_tests/test_tutorial.py index e75ddfcc8..691b559b2 100644 --- a/tests/click_tests/test_tutorial.py +++ b/tests/click_tests/test_tutorial.py @@ -20,6 +20,7 @@ from typing import TYPE_CHECKING, Generator import pytest from trezorlib import device +from trezorlib.exceptions import Cancelled if TYPE_CHECKING: from ..device_handler import BackgroundDeviceHandler @@ -32,14 +33,18 @@ pytestmark = [pytest.mark.skip_t1, pytest.mark.skip_t2] @contextmanager def prepare_tutorial_and_cancel_after_it( - device_handler: "BackgroundDeviceHandler", + device_handler: "BackgroundDeviceHandler", cancelled: bool = False ) -> Generator["DebugLink", None, None]: debug = device_handler.debuglink() device_handler.run(device.show_device_tutorial) yield debug - device_handler.result() + try: + device_handler.result() + except Cancelled: + if not cancelled: + raise def go_through_tutorial(debug: "DebugLink") -> None: @@ -64,7 +69,7 @@ def test_tutorial_finish(device_handler: "BackgroundDeviceHandler"): @pytest.mark.setup_client(uninitialized=True) def test_tutorial_skip(device_handler: "BackgroundDeviceHandler"): - with prepare_tutorial_and_cancel_after_it(device_handler) as debug: + with prepare_tutorial_and_cancel_after_it(device_handler, cancelled=True) as debug: # SKIP debug.press_left(wait=True) debug.press_right(wait=True) @@ -72,7 +77,7 @@ def test_tutorial_skip(device_handler: "BackgroundDeviceHandler"): @pytest.mark.setup_client(uninitialized=True) def test_tutorial_again_and_skip(device_handler: "BackgroundDeviceHandler"): - with prepare_tutorial_and_cancel_after_it(device_handler) as debug: + with prepare_tutorial_and_cancel_after_it(device_handler, cancelled=True) as debug: # CLICK THROUGH go_through_tutorial(debug)