diff --git a/test/python/apps/tezos_new.py b/test/python/apps/tezos_new.py index 71ad35aa..a4592547 100644 --- a/test/python/apps/tezos_new.py +++ b/test/python/apps/tezos_new.py @@ -8,6 +8,10 @@ from pathlib import Path from .exchange_navigation_helper import ExchangeNavigationHelper, ROOT_SCREENSHOT_PATH +from typing import Callable, Dict, List, Optional, Union +from ragger.backend import BackendInterface, SpeculosBackend +from time import time + from ragger.navigator import Navigator, NavIns, NavInsID from ragger.backend.interface import BackendInterface, RAPDU from ragger.bip import pack_derivation_path @@ -181,6 +185,63 @@ def _exchange_async(self, ins: INS, index: INDEX, payload: bytes = b"") -> Gener def get_public_key(self) -> RAPDU: return self._exchange(INS.GET_PUBLIC_KEY, P1.FIRST, payload=NTZ_PACKED_DERIVATION_PATH) + + def navigate_until_text_and_compare(self, + navigate_instruction: Union[NavIns, NavInsID], + validation_instructions: List[Union[NavIns, NavInsID]], + text: str, + path: Optional[Path] = None, + test_case_name: Optional[Path] = None, + timeout: int = 300, + screen_change_before_first_instruction: bool = True, + screen_change_after_last_instruction: bool = True) -> None: + navigator = self._exchange_navigation_helper._navigator + idx = 0 + start = time() + if not isinstance(navigator._backend, SpeculosBackend): + if timeout == 30: + timeout = 200 + + navigator._backend.pause_ticker() + + navigator._run_instruction(NavIns(NavInsID.WAIT, (0, )), + timeout, + wait_for_screen_change=screen_change_before_first_instruction, + path=path, + test_case_name=test_case_name, + snap_idx=idx) + + while True: + print("/->", navigator._backend.get_current_screen_content()) + if navigator._backend.compare_screen_with_text(text): + print("YEAH: ", text) + break + else: + remaining = timeout - (time() - start) + if (remaining < 0): + raise TimeoutError(f"Timeout waiting for text {text}") + + idx += 1 + navigator._run_instruction(navigate_instruction, + remaining, + wait_for_screen_change=True, + path=path, + test_case_name=test_case_name, + snap_idx=idx) + + if validation_instructions: + remaining = timeout - (time() - start) + navigator.navigate_and_compare( + path, + test_case_name, + validation_instructions, + timeout=remaining, + screen_change_before_first_instruction=False, + screen_change_after_last_instruction=screen_change_after_last_instruction, + snap_start_idx=idx) + + navigator._backend.resume_ticker() + def sign_message(self, ins: INS = INS.SIGN_WITH_HASH, message: bytes = b"") -> RAPDU: # todo: send the message by chunk instead of fail @@ -199,10 +260,8 @@ def sign_message(self, ins: INS = INS.SIGN_WITH_HASH, message: bytes = b"") -> R else: navigate_instruction = NavInsID.USE_CASE_REVIEW_TAP validation_instructions = [NavInsID.USE_CASE_REVIEW_CONFIRM] - text="Accept" - self._exchange_navigation_helper.\ - _navigator.\ - navigate_until_text_and_compare(navigate_instruction, + text="ccept" + self.navigate_until_text_and_compare(navigate_instruction, validation_instructions, text, path=ROOT_SCREENSHOT_PATH,