Skip to content

Commit

Permalink
feat(python/debuglink): detect input flows that continue past end of …
Browse files Browse the repository at this point in the history
…test

should make input flows a tiny bit more robust still
  • Loading branch information
matejcik committed Apr 7, 2024
1 parent b2869a5 commit fd914bd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
8 changes: 8 additions & 0 deletions python/src/trezorlib/debuglink.py
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,14 @@ def __exit__(self, exc_type: Any, value: Any, traceback: Any) -> None:
# If no other exception was raised, evaluate missed responses
# (raises AssertionError on mismatch)
self._verify_responses(expected_responses, actual_responses)
if isinstance(input_flow, Generator):
# Ensure that the input flow is exhausted
try:
input_flow.throw(
AssertionError("input flow continues past end of test")
)
except StopIteration:
pass

elif isinstance(input_flow, Generator):
# Propagate the exception through the input flow, so that we see in
Expand Down
27 changes: 10 additions & 17 deletions tests/input_flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ def input_flow_common(self) -> BRGeneratorType:
self.debug.press_yes()

if self.model() is models.T2B1:
yield from swipe_if_necessary(self.debug) # wipe code info
self.debug.press_yes()
layout = self.debug.read_layout()
if not "PinKeyboard" 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)
Expand Down Expand Up @@ -127,8 +129,10 @@ def input_flow_common(self) -> BRGeneratorType:
self.debug.press_yes()

if self.model() is models.T2B1:
yield from swipe_if_necessary(self.debug) # code info
self.debug.press_yes()
layout = self.debug.read_layout()
if not "PinKeyboard" in layout.all_components():
yield from swipe_if_necessary(self.debug) # code info
self.debug.press_yes()

def input_two_different_pins() -> BRGeneratorType:
yield from self.PIN.setup_new_pin(self.first_code, self.second_code)
Expand Down Expand Up @@ -644,8 +648,6 @@ def input_flow_tt(self) -> BRGeneratorType:

yield # confirm transaction
self.debug.press_yes()
yield # confirm transaction
self.debug.press_yes()

def input_flow_t3t1(self) -> BRGeneratorType:
yield # request to see details
Expand All @@ -668,8 +670,6 @@ def input_flow_t3t1(self) -> BRGeneratorType:

yield # confirm transaction
self.debug.press_yes()
yield # confirm transaction
self.debug.press_yes()


class InputFlowSignTxHighFee(InputFlowBase):
Expand Down Expand Up @@ -899,9 +899,6 @@ def lock_time_input_flow_tt(

yield # confirm transaction
debug.press_yes()
if double_confirm:
yield # confirm transaction
debug.press_yes()


def lock_time_input_flow_tr(
Expand Down Expand Up @@ -934,17 +931,13 @@ def assert_func(self, debug: DebugLink, br: messages.ButtonRequest) -> None:
assert self.block_height in layout_text

def input_flow_tt(self) -> BRGeneratorType:
yield from lock_time_input_flow_tt(
self.debug, self.assert_func, double_confirm=True
)
yield from lock_time_input_flow_tt(self.debug, self.assert_func)

def input_flow_tr(self) -> BRGeneratorType:
yield from lock_time_input_flow_tr(self.debug, self.assert_func)

def input_flow_t3t1(self) -> BRGeneratorType:
yield from lock_time_input_flow_tt(
self.debug, self.assert_func, double_confirm=True
)
yield from lock_time_input_flow_tt(self.debug, self.assert_func)


class InputFlowLockTimeDatetime(InputFlowBase):
Expand Down
9 changes: 4 additions & 5 deletions tests/input_flows_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ def setup_new_pin(
self.debug.input(pin)
if self.client.model is models.T2B1:
yield # Reenter PIN
TR.assert_in(
self.debug.read_layout().text_content(), "pin__reenter_to_confirm"
)
# todo update for wipe code
# TR.assert_in(
# self.debug.read_layout().text_content(), "pin__reenter_to_confirm"
# )
self.debug.press_yes()
yield # Enter PIN again
assert "PinKeyboard" in self.debug.read_layout().all_components()
Expand Down Expand Up @@ -411,7 +412,6 @@ def confirm_tx_staking(
)
self.debug.press_no()
self.debug.press_yes()
yield
else:
# confirm intro
if info:
Expand Down Expand Up @@ -440,4 +440,3 @@ def confirm_tx_staking(
self.debug.press_left()
self.debug.press_left()
self.debug.press_middle()
yield

0 comments on commit fd914bd

Please sign in to comment.