feat(tests): seemingly stable workaround for the wait_layout instability

[no changelog]
pull/2900/head
matejcik 1 year ago committed by matejcik
parent 160addce4b
commit 80af1c552e

@ -17,6 +17,7 @@
import logging import logging
import re import re
import textwrap import textwrap
import time
from copy import deepcopy from copy import deepcopy
from datetime import datetime from datetime import datetime
from enum import IntEnum from enum import IntEnum
@ -252,6 +253,16 @@ class DebugLink:
raise TrezorFailure(obj) raise TrezorFailure(obj)
return LayoutContent(obj.layout_lines) return LayoutContent(obj.layout_lines)
def synchronize_at(self, layout_text: str, timeout: float = 5) -> LayoutContent:
now = time.monotonic()
while True:
layout = self.read_layout()
if layout_text in layout.text:
return layout
if time.monotonic() - now > timeout:
raise RuntimeError("Timeout waiting for layout")
time.sleep(0.1)
def watch_layout(self, watch: bool) -> None: def watch_layout(self, watch: bool) -> None:
"""Enable or disable watching layouts. """Enable or disable watching layouts.
If disabled, wait_layout will not work. If disabled, wait_layout will not work.
@ -372,11 +383,27 @@ class DebugLink:
def swipe_down(self, wait: bool = False) -> None: def swipe_down(self, wait: bool = False) -> None:
self.input(swipe=messages.DebugSwipeDirection.DOWN, wait=wait) self.input(swipe=messages.DebugSwipeDirection.DOWN, wait=wait)
def swipe_right(self, wait: bool = False) -> None: @overload
self.input(swipe=messages.DebugSwipeDirection.RIGHT, wait=wait) def swipe_right(self) -> None:
...
@overload
def swipe_right(self, wait: Literal[True]) -> LayoutContent:
...
def swipe_right(self, wait: bool = False) -> Union[LayoutContent, None]:
return self.input(swipe=messages.DebugSwipeDirection.RIGHT, wait=wait)
@overload
def swipe_left(self) -> None:
...
@overload
def swipe_left(self, wait: Literal[True]) -> LayoutContent:
...
def swipe_left(self, wait: bool = False) -> None: def swipe_left(self, wait: bool = False) -> Union[LayoutContent, None]:
self.input(swipe=messages.DebugSwipeDirection.LEFT, wait=wait) return self.input(swipe=messages.DebugSwipeDirection.LEFT, wait=wait)
def stop(self) -> None: def stop(self) -> None:
self._call(messages.DebugLinkStop(), nowait=True) self._call(messages.DebugLinkStop(), nowait=True)

@ -80,6 +80,9 @@ def test_show_tt(
yield yield
client.debug.click(CORNER_BUTTON) client.debug.click(CORNER_BUTTON)
yield yield
# 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_left(wait=True)
client.debug.swipe_right(wait=True) client.debug.swipe_right(wait=True)
client.debug.swipe_left(wait=True) client.debug.swipe_left(wait=True)
@ -114,6 +117,9 @@ def test_show_cancel(
yield yield
client.debug.click(CORNER_BUTTON) client.debug.click(CORNER_BUTTON)
yield yield
# 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_left(wait=True)
client.debug.click(CORNER_BUTTON) client.debug.click(CORNER_BUTTON)
yield yield
@ -242,8 +248,6 @@ VECTORS_MULTISIG = ( # script_type, bip48_type, address, xpubs, ignore_xpub_mag
) )
# NOTE: contains wait_layout race that manifests on hw sometimes
@pytest.mark.flaky(max_runs=5)
@pytest.mark.skip_t1 @pytest.mark.skip_t1
@pytest.mark.multisig @pytest.mark.multisig
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -276,7 +280,7 @@ def test_show_multisig_xpubs(
def input_flow(): def input_flow():
yield # show address yield # show address
layout = client.debug.wait_layout() # TODO: do not need to *wait* now? layout = client.debug.wait_layout()
assert layout.get_title() == "RECEIVE ADDRESS (MULTISIG)" assert layout.get_title() == "RECEIVE ADDRESS (MULTISIG)"
assert layout.get_content().replace(" ", "") == address assert layout.get_content().replace(" ", "") == address
@ -284,9 +288,8 @@ def test_show_multisig_xpubs(
yield # show QR code yield # show QR code
assert "Qr" in client.debug.wait_layout().text assert "Qr" in client.debug.wait_layout().text
client.debug.swipe_left() layout = client.debug.swipe_left(wait=True)
# address details # address details
layout = client.debug.wait_layout()
assert "Multisig 2 of 3" in layout.text assert "Multisig 2 of 3" in layout.text
# Three xpub pages with the same testing logic # Three xpub pages with the same testing logic
@ -295,8 +298,7 @@ def test_show_multisig_xpubs(
"(YOURS)" if i == xpub_num else "(COSIGNER)" "(YOURS)" if i == xpub_num else "(COSIGNER)"
) )
client.debug.swipe_left() layout = client.debug.swipe_left(wait=True)
layout = client.debug.wait_layout()
assert layout.get_title() == expected_title assert layout.get_title() == expected_title
content = layout.get_content().replace(" ", "") content = layout.get_content().replace(" ", "")
assert xpubs[xpub_num] in content assert xpubs[xpub_num] in content
@ -310,8 +312,9 @@ def test_show_multisig_xpubs(
client.debug.press_yes() client.debug.press_yes()
with client: with client:
client.watch_layout()
client.set_input_flow(input_flow) client.set_input_flow(input_flow)
client.debug.synchronize_at("Homescreen")
client.watch_layout()
btc.get_address( btc.get_address(
client, client,
"Bitcoin", "Bitcoin",

Loading…
Cancel
Save