Skip to content

Commit

Permalink
[test] check screen back home after review
Browse files Browse the repository at this point in the history
  • Loading branch information
spalmer25 committed Dec 11, 2024
1 parent 463e965 commit 08c07a7
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 29 deletions.
83 changes: 67 additions & 16 deletions tests/integration/nano/test_sign/test_blindsign.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -167,16 +172,25 @@ 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)

def test_reject_basic_too_long_operation_at_summary(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path):
"""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)

Expand Down Expand Up @@ -330,25 +344,41 @@ 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)

def test_reject_too_long_operation_with_too_large_at_too_large_warning(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path):
"""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)

def test_reject_too_long_operation_with_too_large_at_blindsigning(tezos_navigator: TezosNavigator, account: Account, snapshot_dir: Path):
"""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)

Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 0 additions & 2 deletions tests/integration/nano/test_wrong_apdu.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ def test_regression_continue_after_reject(
with StatusCode.REJECT.expected():
tezos_navigator.reject_public_key(account, snap_path=snapshot_dir / "reject_public_key")

backend.wait_for_home_screen()

message = Transaction(
source = 'tz1ixvCiPJYyMjsp2nKBVaq54f6AdbV8hCKa',
fee = 10000,
Expand Down
36 changes: 25 additions & 11 deletions tests/integration/nano/utils/navigator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -261,18 +271,22 @@ 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,
with_hash: bool,
**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)

0 comments on commit 08c07a7

Please sign in to comment.