From c100358ce2bb79761621d3760ec3b983417afdd0 Mon Sep 17 00:00:00 2001 From: Martin Milata Date: Wed, 29 Mar 2023 17:42:40 +0200 Subject: [PATCH] fix(core/ui): don't send ButtonRequest when displaying GetAddress QR code [no changelog] --- core/src/trezor/ui/layouts/tt_v2/__init__.py | 43 +++++++++---------- python/src/trezorlib/debuglink.py | 12 +++--- .../bitcoin/test_getaddress_show.py | 34 ++++++--------- 3 files changed, 39 insertions(+), 50 deletions(-) diff --git a/core/src/trezor/ui/layouts/tt_v2/__init__.py b/core/src/trezor/ui/layouts/tt_v2/__init__.py index b4246544e..7ea96e3cd 100644 --- a/core/src/trezor/ui/layouts/tt_v2/__init__.py +++ b/core/src/trezor/ui/layouts/tt_v2/__init__.py @@ -384,25 +384,30 @@ async def show_address( multisig_index: int | None = None, xpubs: Sequence[str] = (), ) -> None: + send_button_request = True while True: title = ( "RECEIVE ADDRESS\n(MULTISIG)" if multisig_index is not None else "RECEIVE ADDRESS" ) - result = await interact( - ctx, - RustLayout( - trezorui2.confirm_address( - title=title, - data=address, - description=network or "", - extra=None, - ) - ), - "show_address", - ButtonRequestType.Address, + layout = RustLayout( + trezorui2.confirm_address( + title=title, + data=address, + description=network or "", + extra=None, + ) ) + if send_button_request: + send_button_request = False + await button_request( + ctx, + "show_address", + ButtonRequestType.Address, + pages=layout.page_count(), + ) + result = await ctx.wait(layout) # User pressed right button. if result is CONFIRMED: @@ -416,8 +421,7 @@ async def show_address( result += "(YOURS)" if i == multisig_index else "(COSIGNER)" return result - result = await interact( - ctx, + result = await ctx.wait( RustLayout( trezorui2.show_address_details( address=address if address_qr is None else address_qr, @@ -426,19 +430,12 @@ async def show_address( path=path, xpubs=[(xpub_title(i), xpub) for i, xpub in enumerate(xpubs)], ) - ), - "show_address_details", - ButtonRequestType.Address, + ) ) assert result is CANCELLED else: - result = await interact( - ctx, - RustLayout(trezorui2.show_mismatch()), - "warning_address_mismatch", - ButtonRequestType.Warning, - ) + result = await ctx.wait(RustLayout(trezorui2.show_mismatch())) assert result in (CONFIRMED, CANCELLED) # Right button aborts action, left goes back to showing address. if result is CONFIRMED: diff --git a/python/src/trezorlib/debuglink.py b/python/src/trezorlib/debuglink.py index ca98bcf3c..c40ca2100 100644 --- a/python/src/trezorlib/debuglink.py +++ b/python/src/trezorlib/debuglink.py @@ -368,14 +368,14 @@ class DebugLink: x, y = click return self.input(x=x, y=y, wait=wait) - def press_yes(self) -> None: - self.input(button=messages.DebugButton.YES) + def press_yes(self, wait: bool = False) -> None: + self.input(button=messages.DebugButton.YES, wait=wait) - def press_no(self) -> None: - self.input(button=messages.DebugButton.NO) + def press_no(self, wait: bool = False) -> None: + self.input(button=messages.DebugButton.NO, wait=wait) - def press_info(self) -> None: - self.input(button=messages.DebugButton.INFO) + def press_info(self, wait: bool = False) -> None: + self.input(button=messages.DebugButton.INFO, wait=wait) def swipe_up(self, wait: bool = False) -> None: self.input(swipe=messages.DebugSwipeDirection.UP, wait=wait) diff --git a/tests/device_tests/bitcoin/test_getaddress_show.py b/tests/device_tests/bitcoin/test_getaddress_show.py index 856bd4759..e5b65a0ee 100644 --- a/tests/device_tests/bitcoin/test_getaddress_show.py +++ b/tests/device_tests/bitcoin/test_getaddress_show.py @@ -78,20 +78,16 @@ def test_show_tt( ): def input_flow(): yield - client.debug.click(CORNER_BUTTON) - yield + client.debug.click(CORNER_BUTTON, wait=True) # synchronize; TODO get rid of this once we have single-global-layout client.debug.synchronize_at("HorizontalPage") client.debug.swipe_left(wait=True) client.debug.swipe_right(wait=True) client.debug.swipe_left(wait=True) - client.debug.click(CORNER_BUTTON) - yield - client.debug.press_no() - yield - client.debug.press_no() - yield + client.debug.click(CORNER_BUTTON, wait=True) + client.debug.press_no(wait=True) + client.debug.press_no(wait=True) client.debug.press_yes() with client: @@ -115,16 +111,13 @@ def test_show_cancel( ): def input_flow(): yield - client.debug.click(CORNER_BUTTON) - yield + client.debug.click(CORNER_BUTTON, wait=True) # synchronize; TODO get rid of this once we have single-global-layout client.debug.synchronize_at("HorizontalPage") client.debug.swipe_left(wait=True) - client.debug.click(CORNER_BUTTON) - yield - client.debug.press_no() - yield + client.debug.click(CORNER_BUTTON, wait=True) + client.debug.press_no(wait=True) client.debug.press_yes() with client, pytest.raises(Cancelled): @@ -285,7 +278,6 @@ def test_show_multisig_xpubs( assert layout.get_content().replace(" ", "") == address client.debug.click(CORNER_BUTTON) - yield # show QR code assert "Qr" in client.debug.wait_layout().text layout = client.debug.swipe_left(wait=True) @@ -302,12 +294,12 @@ def test_show_multisig_xpubs( content = layout.get_content().replace(" ", "") assert xpubs[xpub_num] in content - client.debug.click(CORNER_BUTTON) - yield # show address - client.debug.press_no() - yield # address mismatch - client.debug.press_no() - yield # show address + client.debug.click(CORNER_BUTTON, wait=True) + # show address + client.debug.press_no(wait=True) + # address mismatch + client.debug.press_no(wait=True) + # show address client.debug.press_yes() with client: