From 8f1126b34b76f8912dd8b9ca0eda0e5e8bc21dd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Palmer?= Date: Wed, 11 Dec 2024 13:22:36 +0100 Subject: [PATCH] [test] check screen back home after review --- .../nano/test_sign/test_blindsign.py | 83 +++++++++++++++---- tests/integration/nano/utils/navigator.py | 36 +++++--- 2 files changed, 92 insertions(+), 27 deletions(-) diff --git a/tests/integration/nano/test_sign/test_blindsign.py b/tests/integration/nano/test_sign/test_blindsign.py index 0a6223b95..675cb3bdf 100644 --- a/tests/integration/nano/test_sign/test_blindsign.py +++ b/tests/integration/nano/test_sign/test_blindsign.py @@ -65,8 +65,13 @@ def _sign_decodable_too_long(tezos_navigator: TezosNavigator, """Sign a decodable too long message""" def navigate() -> None: - tezos_navigator.navigate_review(text=ScreenText.ACCEPT_RISK, snap_path=path / "clear_n_too_long_warning") - tezos_navigator.navigate_review(text=ScreenText.SIGN_ACCEPT, snap_path=path / "summary") + tezos_navigator.navigate_forward_and_press( + text=ScreenText.ACCEPT_RISK, + screen_change_before_first_instruction=True, + screen_change_after_last_instruction=False, + snap_path=path / "clear_n_too_long_warning" + ) + tezos_navigator.navigate_sign_accept(snap_path=path / "summary") _sign_too_long(tezos_navigator, account, message, navigate) @@ -167,7 +172,9 @@ def test_reject_basic_too_long_operation_at_warning(tezos_navigator: TezosNaviga """Check reject too long operation at warning""" def navigate() -> None: - tezos_navigator.navigate_review(text=ScreenText.SIGN_REJECT, snap_path=snapshot_dir / "clear_n_too_long_warning") + tezos_navigator.navigate_sign_reject( + snap_path=snapshot_dir / "clear_n_too_long_warning" + ) _reject_too_long(tezos_navigator, account, BASIC_OPERATION, StatusCode.REJECT, navigate) @@ -175,8 +182,15 @@ def test_reject_basic_too_long_operation_at_summary(tezos_navigator: TezosNaviga """Check reject too long operation at summary""" def navigate() -> None: - tezos_navigator.navigate_review(text=ScreenText.ACCEPT_RISK, snap_path=snapshot_dir / "clear_n_too_long_warning") - tezos_navigator.navigate_review(text=ScreenText.SIGN_REJECT, snap_path=snapshot_dir / "summary") + tezos_navigator.navigate_forward_and_press( + text=ScreenText.ACCEPT_RISK, + screen_change_before_first_instruction=True, + screen_change_after_last_instruction=False, + snap_path=snapshot_dir / "clear_n_too_long_warning" + ) + tezos_navigator.navigate_sign_reject( + snap_path=snapshot_dir / "summary" + ) _reject_too_long(tezos_navigator, account, BASIC_OPERATION, StatusCode.REJECT, navigate) @@ -330,8 +344,15 @@ def test_sign_too_long_operation_with_too_large(tezos_navigator: TezosNavigator, """Check sign too long operation that will also fail the parsing""" def navigate() -> None: - tezos_navigator.navigate_review(text=ScreenText.ACCEPT_RISK, snap_path=snapshot_dir / "clear_n_too_large_warning") - tezos_navigator.navigate_review(text=ScreenText.SIGN_ACCEPT, snap_path=snapshot_dir / "blindsigning") + tezos_navigator.navigate_forward_and_press( + text=ScreenText.ACCEPT_RISK, + screen_change_before_first_instruction=True, + screen_change_after_last_instruction=False, + snap_path=snapshot_dir / "clear_n_too_large_warning" + ) + tezos_navigator.navigate_sign_accept( + snap_path=snapshot_dir / "blindsigning" + ) _sign_too_long(tezos_navigator, account, OPERATION_WITH_TOO_LARGE, navigate) @@ -339,7 +360,9 @@ def test_reject_too_long_operation_with_too_large_at_too_large_warning(tezos_nav """Check reject too long operation that will also fail the parsing at too large warning""" def navigate() -> None: - tezos_navigator.navigate_review(text=ScreenText.SIGN_REJECT, snap_path=snapshot_dir / "clear_n_too_large_warning") + tezos_navigator.navigate_sign_reject( + snap_path=snapshot_dir / "clear_n_too_large_warning" + ) _reject_too_long(tezos_navigator, account, OPERATION_WITH_TOO_LARGE, StatusCode.PARSE_ERROR, navigate) @@ -347,8 +370,15 @@ def test_reject_too_long_operation_with_too_large_at_blindsigning(tezos_navigato """Check reject too long operation that will also fail the parsing at blindsigning""" def navigate() -> None: - tezos_navigator.navigate_review(text=ScreenText.ACCEPT_RISK, snap_path=snapshot_dir / "clear_n_too_large_warning") - tezos_navigator.navigate_review(text=ScreenText.SIGN_REJECT, snap_path=snapshot_dir / "blindsigning") + tezos_navigator.navigate_forward_and_press( + text=ScreenText.ACCEPT_RISK, + screen_change_before_first_instruction=True, + screen_change_after_last_instruction=False, + snap_path=snapshot_dir / "clear_n_too_large_warning" + ) + tezos_navigator.navigate_sign_reject( + snap_path=snapshot_dir / "blindsigning" + ) _reject_too_long(tezos_navigator, account, OPERATION_WITH_TOO_LARGE, StatusCode.REJECT, navigate) @@ -384,9 +414,16 @@ def navigate() -> None: snap_path=snapshot_dir / "clear", ) else: - tezos_navigator.navigate_review(text=ScreenText.ACCEPT_RISK, snap_path=snapshot_dir / "clear") + tezos_navigator.navigate_forward_and_press( + text=ScreenText.ACCEPT_RISK, + screen_change_before_first_instruction=True, + screen_change_after_last_instruction=False, + snap_path=snapshot_dir / "clear" + ) - tezos_navigator.navigate_review(text=ScreenText.SIGN_ACCEPT, snap_path=snapshot_dir / "blind") + tezos_navigator.navigate_sign_accept( + snap_path=snapshot_dir / "blind" + ) data = tezos_navigator.sign( account, @@ -406,8 +443,15 @@ def test_blindsign_too_large(tezos_navigator: TezosNavigator, account: Account, message = MichelineExpr({'int':12345678901234567890123456789012345678901234567890123456789012345678901234567890}) def navigate() -> None: - tezos_navigator.navigate_review(text=ScreenText.ACCEPT_RISK, snap_path=snapshot_dir / "clear") - tezos_navigator.navigate_review(text=ScreenText.SIGN_ACCEPT, snap_path=snapshot_dir / "blind") + tezos_navigator.navigate_forward_and_press( + text=ScreenText.ACCEPT_RISK, + screen_change_before_first_instruction=True, + screen_change_after_last_instruction=False, + snap_path=snapshot_dir / "clear" + ) + tezos_navigator.navigate_sign_accept( + snap_path=snapshot_dir / "blind" + ) data = tezos_navigator.sign( account, @@ -440,8 +484,15 @@ def test_blindsign_reject_from_blind(tezos_navigator: TezosNavigator, account: A expression = MichelineExpr({'int':12345678901234567890123456789012345678901234567890123456789012345678901234567890}) def navigate() -> None: - tezos_navigator.navigate_review(text=ScreenText.ACCEPT_RISK, snap_path=snapshot_dir / "clear") - tezos_navigator.navigate_review(text=ScreenText.SIGN_REJECT, snap_path=snapshot_dir / "blind") + tezos_navigator.navigate_forward_and_press( + text=ScreenText.ACCEPT_RISK, + screen_change_before_first_instruction=True, + screen_change_after_last_instruction=False, + snap_path=snapshot_dir / "clear" + ) + tezos_navigator.navigate_sign_reject( + snap_path=snapshot_dir / "blind" + ) with StatusCode.REJECT.expected(): tezos_navigator.sign( diff --git a/tests/integration/nano/utils/navigator.py b/tests/integration/nano/utils/navigator.py index b67f228c4..09e6f7877 100644 --- a/tests/integration/nano/utils/navigator.py +++ b/tests/integration/nano/utils/navigator.py @@ -112,12 +112,14 @@ def navigate(self, def navigate_until_text(self, snap_path: Optional[Path] = None, screen_change_before_first_instruction: bool = False, + validation_instructions: List[Union[NavIns, NavInsID]] = [], **kwargs) -> None: """Wrapper of `navigator.navigate_until_text_and_compare`""" self._navigator.navigate_until_text_and_compare( path=self._root_dir, test_case_name=snap_path, screen_change_before_first_instruction=screen_change_before_first_instruction, + validation_instructions=validation_instructions, **kwargs ) @@ -216,22 +218,26 @@ def toggle_blindsign(self, **kwargs) -> int: def navigate_forward(self, **kwargs) -> None: """Navigate forward until the text is found. Confirm at the end.""" - self.navigate_until_text( - navigate_instruction=NavInsID.RIGHT_CLICK, - validation_instructions=[NavInsID.BOTH_CLICK], - **kwargs - ) + self.navigate_until_text(navigate_instruction=NavInsID.RIGHT_CLICK, **kwargs) + + def navigate_forward_and_press(self, **kwargs) -> None: + """Navigate forward until the text is found. Confirm at the end.""" + self.navigate_forward(validation_instructions=[NavInsID.BOTH_CLICK], **kwargs) def navigate_review(self, screen_change_before_first_instruction=True, - screen_change_after_last_instruction=False, **kwargs) -> None: - """Navigate forward until the text is found. Confirm at the end.""" - self.navigate_forward( + """Navigate forward until the text is found. + + Confirm at the end and expect to return home. + + """ + self.navigate_forward_and_press( screen_change_before_first_instruction=screen_change_before_first_instruction, - screen_change_after_last_instruction=screen_change_after_last_instruction, + screen_change_after_last_instruction=False, **kwargs ) + self._backend.wait_for_home_screen() def provide_public_key(self, account: Account, @@ -252,6 +258,10 @@ def navigate(): self.navigate_review(text=ScreenText.PUBLIC_KEY_REJECT, **kwargs) return self.provide_public_key(account, navigate) + def navigate_sign_accept(self, **kwargs) -> None: + """Navigate through signing flow and accept to sign""" + self.navigate_review(text=ScreenText.SIGN_ACCEPT, **kwargs) + def sign(self, account: Account, message: Message, @@ -261,12 +271,16 @@ def sign(self, """Send a sign request and navigate""" if navigate is None: def navigate(): - self.navigate_review(text=ScreenText.SIGN_ACCEPT, **kwargs) + self.navigate_sign_accept(**kwargs) return send_and_navigate( send=lambda: self._backend.sign(account, message, with_hash), navigate=navigate ) + def navigate_sign_reject(self, **kwargs) -> None: + """Navigate through signing flow and reject.""" + self.navigate_review(text=ScreenText.SIGN_REJECT, **kwargs) + def reject_signing(self, account: Account, message: Message, @@ -274,5 +288,5 @@ def reject_signing(self, **kwargs) -> None: """Send a sign request and navigate in order to reject it""" def navigate(): - self.navigate_review(text=ScreenText.SIGN_REJECT, **kwargs) + self.navigate_sign_reject(**kwargs) self.sign(account, message, with_hash, navigate)