From 2b3c75c4de364bdcc4a3cfe78f8edc42094d450e Mon Sep 17 00:00:00 2001 From: matejcik Date: Thu, 15 Jul 2021 10:59:43 +0200 Subject: [PATCH] fix(core): properly respond to USB events while on a paginated screen --- core/.changelog.d/1708.fixed | 1 + core/src/trezor/ui/components/tt/scroll.py | 2 +- tests/device_tests/test_cancel.py | 24 ++++++++++++++++++++++ tests/ui_tests/fixtures.json | 1 + 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 core/.changelog.d/1708.fixed diff --git a/core/.changelog.d/1708.fixed b/core/.changelog.d/1708.fixed new file mode 100644 index 000000000..08f129c09 --- /dev/null +++ b/core/.changelog.d/1708.fixed @@ -0,0 +1 @@ +Properly respond to USB events while on a paginated screen. diff --git a/core/src/trezor/ui/components/tt/scroll.py b/core/src/trezor/ui/components/tt/scroll.py index a262a8820..5fe51208f 100644 --- a/core/src/trezor/ui/components/tt/scroll.py +++ b/core/src/trezor/ui/components/tt/scroll.py @@ -114,7 +114,7 @@ class Paginated(ui.Layout): await ctx.call(ButtonRequest(code=code, pages=len(self.pages)), ButtonAck) result = WAS_PAGED while result is WAS_PAGED: - result = await self + result = await ctx.wait(self) return result diff --git a/tests/device_tests/test_cancel.py b/tests/device_tests/test_cancel.py index 2000b349e..8520f4a8c 100644 --- a/tests/device_tests/test_cancel.py +++ b/tests/device_tests/test_cancel.py @@ -67,3 +67,27 @@ def test_cancel_message_via_initialize(client, message): resp = client._raw_read() assert isinstance(resp, m.Features) + + +@pytest.mark.skip_t1 +def test_cancel_on_paginated(client): + """Check that device is responsive on paginated screen. See #1708.""" + # In #1708, the device would ignore USB (or UDP) events while waiting for the user + # to page through the screen. This means that this testcase, instead of failing, + # would get stuck waiting for the _raw_read result. + # I'm not spending the effort to modify the testcase to cause a _failure_ if that + # happens again. Just be advised that this should not get stuck. + message = m.SignMessage( + message=b"hello" * 64, + address_n=TEST_ADDRESS_N, + coin_name="Testnet", + ) + resp = client.call_raw(message) + assert isinstance(resp, m.ButtonRequest) + assert resp.pages is not None + client._raw_write(m.ButtonAck()) + + client._raw_write(m.Cancel()) + resp = client._raw_read() + assert isinstance(resp, m.Failure) + assert resp.code == m.FailureType.ActionCancelled diff --git a/tests/ui_tests/fixtures.json b/tests/ui_tests/fixtures.json index 626a07208..bf2c7dded 100644 --- a/tests/ui_tests/fixtures.json +++ b/tests/ui_tests/fixtures.json @@ -128,6 +128,7 @@ "test_cancel.py::test_cancel_message_via_cancel[message1]": "83a76ca8054759209fc06244ee303f95e20da9e6ccdfe268d16fba5e0065de69", "test_cancel.py::test_cancel_message_via_initialize[message0]": "83a76ca8054759209fc06244ee303f95e20da9e6ccdfe268d16fba5e0065de69", "test_cancel.py::test_cancel_message_via_initialize[message1]": "83a76ca8054759209fc06244ee303f95e20da9e6ccdfe268d16fba5e0065de69", +"test_cancel.py::test_cancel_on_paginated": "83a76ca8054759209fc06244ee303f95e20da9e6ccdfe268d16fba5e0065de69", "test_debuglink.py::test_softlock_instability": "bdc28bcdb709f6ffd74ba89bc34ff87a2516c9277bad701c1c6d9e9926ce6871", "test_descriptors.py::test_descriptors[Bitcoin-0-InputScriptType.SPENDADDRESS-descriptors0]": "2cfe6b7b4d74644c8bdef3f18d8a9be8c20787ab5e9af2588bac2c426a5f1da7", "test_descriptors.py::test_descriptors[Bitcoin-0-InputScriptType.SPENDP2SHWITNESS-descriptors4]": "5b87cbe3b60327d699545bf61101cf633f66d66bc485d692c51505c18519948a",