Skip to content

Commit

Permalink
Use useCaseViewDetails to show tag-value pair which does not fit in s…
Browse files Browse the repository at this point in the history
…ingle page.

- fixes trilitech#260
  • Loading branch information
ajinkyaraj-23 authored Jul 26, 2024
1 parent b4d7a8b commit 953b699
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 15 deletions.
Binary file modified app/icons/flex_tezos.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion app/src/ui_stream_nbgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,10 @@ tz_ui_stream_pushl(tz_ui_cb_type_t cb_type, const char *title,
0, &push_to_next);
PRINTF("[DEBUG] idx=%d fit=%d push_to_next=%d\n", idx, fit,
push_to_next);
push_to_next |= fit <= (uint8_t)idx;
/*
* Dont push to next screen if the number of pairs is one.
*/
push_to_next = (fit <= (uint8_t)idx);

if (push_to_next) {
/* We need to move to the next screen, retry */
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 9 additions & 3 deletions tests/integration/touch/test_sign_execute_outbox_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
send_payload
)


# full input: 0000000000000000000000000000000000000000000000000000000000000000ce00ffdd6102321bc251e4a5190ad5b12b251069d9b4904e02030400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c6396630396632393532643334353238633733336639343631356366633339626335353536313966633535306464346136376261323230386365386538363761613364313361366566393964666265333263363937346161396132313530643231656361323963333334396535396331336239303831663163313162343430616334643334353564656462653465653064653135613861663632306434633836323437643964313332646531626236646132336435666639643864666664613232626139613834
# signer: tz1dyX3B1CFYa2DfdFLyPtiJCfQRUgPVME6E

Expand All @@ -41,9 +42,14 @@
app.review.next()
app.expert_mode_splash()

for i in range(3):
app.review.next()
app.assert_screen(f"operation_proof_396...834_{i}")
app.review.next()
app.assert_screen("operation_proof_396...834_0")
app.review.show_more()
app.assert_screen("operation_prooof_details_396...834_0")
app.review.details.exit()
app.assert_screen("operation_proof_396...834_0")
app.review.next()
app.assert_screen("operation_proof_396...834_1")

app.review.next()
app.assert_screen("operation_sign")
Expand Down
51 changes: 40 additions & 11 deletions tests/integration/touch/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@
UseCaseSettings as OriginalUseCaseSettings,
UseCaseAddressConfirmation as OriginalUseCaseAddressConfirmation,
UseCaseReview as OriginalUseCaseReview,
UseCaseChoice
UseCaseChoice,
UseCaseViewDetails
)
from ragger.firmware.touch.layouts import ChoiceList
from ragger.firmware.touch.positions import (
Position,
STAX_BUTTON_LOWER_LEFT,
STAX_BUTTON_ABOVE_LOWER_MIDDLE,
STAX_BUTTON_LOWER_RIGHT,
STAX_BUTTON_LOWER_MIDDLE,
FLEX_BUTTON_LOWER_LEFT,
FLEX_BUTTON_ABOVE_LOWER_MIDDLE
)

MAX_ATTEMPTS = 50


def with_retry(f, attempts=MAX_ATTEMPTS):
while True:
try:
Expand All @@ -58,26 +58,43 @@ def with_retry(f, attempts=MAX_ATTEMPTS):
# Give plenty of time for speculos to update - can take a long time on CI machines
time.sleep(0.5)


class UseCaseReview(OriginalUseCaseReview):
"""Extension of UseCaseReview for our app."""

reject_tx: UseCaseChoice
enable_expert: UseCaseChoice
enable_blindsign: UseCaseChoice
details: UseCaseViewDetails

_center: Center
MORE_POSITIONS = {
Firmware.STAX: Position(200, 390),
Firmware.FLEX: Position(240, 350)
}

def __init__(self, client: BackendInterface, firmware: Firmware):
super().__init__(client, firmware)
self.reject_tx = UseCaseChoice(client, firmware)
self.enable_expert = UseCaseChoice(client, firmware)
self.enable_blindsign = UseCaseChoice(client, firmware)
self._center = Center(client, firmware)
self.details = UseCaseViewDetails(client, firmware)

@property
def more_position(self) -> Position:
"""Position of the `More` button."""
return UseCaseReview.MORE_POSITIONS[self.firmware]

def next(self) -> None:
"""Pass to the next screen."""
self._center.swipe_left()

def show_more(self) -> None:
"""Tap to show more."""
self.client.finger_touch(*self.more_position)


class UseCaseAddressConfirmation(OriginalUseCaseAddressConfirmation):
"""Extension of UseCaseAddressConfirmation for our app."""

Expand Down Expand Up @@ -105,6 +122,7 @@ def show_qr(self) -> None:
"""Tap to show qr code."""
self.client.finger_touch(*self.qr_position)


class UseCaseSettings(OriginalUseCaseSettings):
"""Extension of UseCaseSettings for our app."""

Expand All @@ -126,6 +144,7 @@ def exit(self) -> None:
"""Exits settings."""
self.multi_page_exit()


class TezosAppScreen(metaclass=MetaScreen):
use_case_welcome = UseCaseHomeExt
use_case_settings = UseCaseSettings
Expand Down Expand Up @@ -171,8 +190,9 @@ def __init__(self,
for filename in os.listdir(path):
os.remove(os.path.join(path, filename))
path = f"{self.__snapshots_path}"
home_path=os.path.join(path, "home.png")
if os.path.exists(home_path): os.remove(home_path)
home_path = os.path.join(path, "home.png")
if os.path.exists(home_path):
os.remove(home_path)

def send_apdu(self, data):
"""Send hex-encoded bytes to the apdu"""
Expand All @@ -182,7 +202,8 @@ def remove_info_page(self):
""" Delete the info page for golden tests"""
if self.__golden:
info_path=os.path.join(self.__snapshots_path, "info.png")
if os.path.exists(info_path): os.remove(info_path)
if os.path.exists(info_path):
os.remove(info_path)

def expect_apdu_return(self, expected):
"""Expect hex-encoded response from the apdu"""
Expand Down Expand Up @@ -210,9 +231,10 @@ def assert_screen(self, screen, fixed: bool = False):
path = f'{self.__snapshots_path}/{screen}.png'
else:
path = f'{self.__prefixed_snapshots_path}/{screen}.png'

def check():
print(f"- Expecting {screen} -")
assert self.__backend.compare_screen_with_snapshot(path, golden_run = golden)
assert self.__backend.compare_screen_with_snapshot(path, golden_run=golden)

with_retry(check)

Expand Down Expand Up @@ -301,46 +323,53 @@ def process_blindsign_warnings(self, landing_screen: str):
self.review.enable_blindsign.confirm()



def tezos_app(prefix) -> TezosAppScreen:
port = os.environ["PORT"]
commit = os.environ["COMMIT_BYTES"]
version = os.environ["VERSION_BYTES"]
golden = os.getenv("GOLDEN") != None
golden = os.getenv("GOLDEN") is not None
target = os.getenv("TARGET")
firmware = Firmware.STAX if target == "stax" else Firmware.FLEX
backend = SpeculosBackend("__unused__", firmware, args=["--api-port", port])
return TezosAppScreen(backend, firmware, commit, version, prefix, golden)


def assert_home_with_code(app, code):
app.assert_home()
app.expect_apdu_failure(code)


def send_initialize_msg(app, apdu):
app.send_apdu(apdu)
app.expect_apdu_return("9000")
app.assert_screen("review_request_sign_operation")


def send_payload(app, apdu):
app.send_apdu(apdu)
app.assert_screen("review_request_sign_operation")


def verify_err_reject_response(app, tag):
verify_reject_response_common(app, tag, "9405")


def verify_reject_response(app, tag):
verify_reject_response_common(app, tag,"6985")
verify_reject_response_common(app, tag, "6985")


def verify_reject_response_common(app, tag, err_code):
app.assert_screen(tag)
app.review.reject()
reject_flow(app, err_code)

def reject_flow(app,err_code):

def reject_flow(app, err_code):
app.assert_screen("reject_review")
with app.fading_screen("rejected"):
app.review.reject_tx.confirm()
assert_home_with_code(app, err_code)


def index_screen(screen: str, index: int) -> str:
return screen + "_" + str(index).zfill(2)

0 comments on commit 953b699

Please sign in to comment.