Skip to content

Commit

Permalink
fixup! test(core): don't fetch DebugLinkState by default
Browse files Browse the repository at this point in the history
  • Loading branch information
romanz committed Feb 5, 2025
1 parent 1c18a26 commit abb1d59
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 46 deletions.
2 changes: 2 additions & 0 deletions common/protob/messages-debug.proto
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ message DebugLinkGetState {
// trezor-core only - wait until current layout changes
// changed in 2.6.4: multiple wait types instead of true/false.
optional DebugWaitType wait_layout = 3 [default=IMMEDIATE];
// Responds immediately with an empty `DebugLinkState` (used for client-side synchronization).
optional bool return_empty_state = 4 [default=false];
}

/**
Expand Down
5 changes: 5 additions & 0 deletions core/src/apps/debug/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,11 @@ def callback(*args: str) -> None:
async def dispatch_DebugLinkGetState(
msg: DebugLinkGetState,
) -> DebugLinkState | None:
if msg.return_empty_state:
from trezor.messages import DebugLinkState

return DebugLinkState()

if msg.wait_layout == DebugWaitType.IMMEDIATE:
return _state()

Expand Down
2 changes: 2 additions & 0 deletions core/src/trezor/messages.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion python/src/trezorlib/debuglink.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,8 @@ def _decision(self, decision: messages.DebugLinkDecision) -> None:
decision.hold_ms += 200

self._write(decision)
# "Flush" the DebugLink queue, to be sure that `decision` has been processed.
self._call(messages.DebugLinkGetState(return_empty_state=True))

press_yes = _make_input_func(button=messages.DebugButton.YES)
"""Confirm current layout. See `_decision` for more details."""
Expand Down Expand Up @@ -804,7 +806,6 @@ def _default_input_flow(self, br: messages.ButtonRequest) -> None:
if br.pages is not None:
for _ in range(br.pages - 1):
self.debuglink.swipe_up()
self.debuglink.state(DebugWaitType.CURRENT_LAYOUT)

if self.debuglink.model is models.T3T1:
layout = self.debuglink.read_layout()
Expand Down
3 changes: 3 additions & 0 deletions python/src/trezorlib/messages.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

98 changes: 68 additions & 30 deletions rust/trezor-client/src/protos/generated/messages_debug.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion tests/click_tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ def navigate_to_action_and_press(

# Press or hold
debug.press_middle(hold_ms=hold_ms)
debug.read_layout() # TODO: make sure the press above takes action


def _carousel_steps(current_index: int, wanted_index: int, length: int) -> int:
Expand Down
2 changes: 0 additions & 2 deletions tests/click_tests/reset.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def confirm_read(debug: "DebugLink", middle_r: bool = False) -> None:
debug.press_middle()
else:
debug.press_right()
debug.read_layout() # TODO: what is being confirmed here?


def cancel_backup(
Expand All @@ -62,7 +61,6 @@ def cancel_backup(
elif debug.layout_type is LayoutType.Caesar:
debug.press_left()
debug.press_left()
debug.read_layout() # TODO: make sure cancellation took place


def set_selection(debug: "DebugLink", button: tuple[int, int], diff: int) -> None:
Expand Down
7 changes: 0 additions & 7 deletions tests/click_tests/test_autolock.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,6 @@ def sleepy_filter(msg: MessageType) -> MessageType:
elif debug.layout_type is LayoutType.Caesar:
debug.press_middle()

# In all cases we set wait=False to avoid waiting for the screen and triggering
# the layout deadlock detection. In reality there is no deadlock but the
# `sleepy_filter` delays the response by 10 secs while the layout deadlock
# timeout is 3. In this test we don't need the result of the input event so
# waiting for it is not necessary.
debug.read_layout(wait=False)

signatures, tx = device_handler.result()
assert len(signatures) == 1
assert tx
Expand Down
2 changes: 0 additions & 2 deletions tests/click_tests/test_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def hold(duration: int) -> None:
debug.press_right(hold_ms=duration)
else:
debug.click((13, 37), hold_ms=duration)
debug.read_layout() # TODO: is it needed?

assert device_handler.features().unlocked is False

Expand Down Expand Up @@ -86,7 +85,6 @@ def hold(duration: int) -> None:
layout = debug.read_layout()
assert "PinKeyboard" in layout.all_components()
debug.input("1234")
debug.read_layout() # TODO: is it needed?

assert device_handler.features().unlocked is True

Expand Down
1 change: 0 additions & 1 deletion tests/click_tests/test_passphrase_bolt.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ def press_char(debug: "DebugLink", char: str) -> None:
TT_COORDS_PREV = coords # type: ignore
for _ in range(amount):
debug.click(coords)
debug.read_layout() # TODO: seems to be needed


def input_passphrase(debug: "DebugLink", passphrase: str, check: bool = True) -> None:
Expand Down
1 change: 0 additions & 1 deletion tests/click_tests/test_passphrase_delizia.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ def press_char(debug: "DebugLink", char: str) -> None:
COORDS_PREV = coords # type: ignore
for _ in range(amount):
debug.click(coords)
debug.read_layout() # TODO: seems to be needed


def input_passphrase(debug: "DebugLink", passphrase: str, check: bool = True) -> None:
Expand Down
1 change: 0 additions & 1 deletion tests/click_tests/test_pin.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ def _delete_pin(debug: "DebugLink", digits_to_delete: int, check: bool = True) -
for _ in range(digits_to_delete):
if debug.layout_type in (LayoutType.Bolt, LayoutType.Delizia):
debug.click(buttons.pin_passphrase_grid(9))
debug.read_layout() # TODO: make sure the press above takes action
elif debug.layout_type is LayoutType.Caesar:
navigate_to_action_and_press(debug, DELETE, TR_PIN_ACTIONS)

Expand Down

0 comments on commit abb1d59

Please sign in to comment.