Skip to content

Commit

Permalink
Merge pull request #85 from trilitech/palmer@fix-screen-update
Browse files Browse the repository at this point in the history
Fix home screens update
  • Loading branch information
ajinkyaraj-23 authored Mar 28, 2024
2 parents 98efca8 + f8f830e commit fe96e7a
Show file tree
Hide file tree
Showing 220 changed files with 178 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/ui_bagl.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void ui_initial_screen(void) {
void update_baking_idle_screens(void) {
if (calculate_baking_idle_screens_data()) {
/// refresh
ux_stack_display(0);
ux_stack_redisplay();
}
}

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.
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.
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.
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.
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.
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.
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.
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.
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.
150 changes: 107 additions & 43 deletions test/test_instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import hashlib
import hmac
import time

import pytest
from pytezos import pytezos
Expand Down Expand Up @@ -187,7 +188,6 @@ def test_ledger_screensaver(client: TezosClient, tezos_navigator: TezosNavigator
assert True
return

import time
lvl = 0
main_chain_id = DEFAULT_CHAIN_ID
main_hwm = Hwm(lvl)
Expand Down Expand Up @@ -217,7 +217,6 @@ def test_benchmark_attestation_time(account: Account, client: TezosClient, tezos
assert True
return

import time
lvl = 0
main_chain_id = DEFAULT_CHAIN_ID
main_hwm = Hwm(lvl)
Expand Down Expand Up @@ -262,23 +261,35 @@ def test_authorize_baking(account: Account, tezos_navigator: TezosNavigator) ->
)


def test_deauthorize(client: TezosClient, tezos_navigator: TezosNavigator) -> None:
def test_deauthorize(firmware: Firmware,
backend: BackendInterface,
client: TezosClient,
tezos_navigator: TezosNavigator) -> None:
"""Test the DEAUTHORIZE instruction."""

account = DEFAULT_ACCOUNT

tezos_navigator.authorize_baking(account)

client.deauthorize()
with tezos_navigator.goto_home_public_key():
tezos_navigator.assert_screen("authorized_key_before_authorize")

# TODO : re-check app context after nanos black screen fixed
client.deauthorize()

# tezos_navigator.check_app_context(
# None,
# chain_id=DEFAULT_CHAIN_ID,
# main_hwm=Hwm(0),
# test_hwm=Hwm(0)
# )
if firmware.is_nano:
# No update for Stax
backend.wait_for_screen_change()
if firmware.device == "nanos":
# Wait blink
time.sleep(0.5)
tezos_navigator.assert_screen("authorized_key_after_authorize")

tezos_navigator.check_app_context(
None,
chain_id=DEFAULT_CHAIN_ID,
main_hwm=Hwm(0),
test_hwm=Hwm(0)
)

@pytest.mark.parametrize("account", ACCOUNTS)
def test_get_auth_key(
Expand Down Expand Up @@ -473,6 +484,8 @@ def build_block(level, current_round, chain_id):
def test_sign_preattestation(
account: Account,
with_hash: bool,
firmware: Firmware,
backend: BackendInterface,
client: TezosClient,
tezos_navigator: TezosNavigator) -> None:
"""Test the SIGN(_WITH_HASH) instruction on preattestation."""
Expand All @@ -495,14 +508,26 @@ def test_sign_preattestation(
chain_id=main_chain_id
)

if not with_hash:
signature = client.sign_message(account, preattestation)
account.check_signature(signature, bytes(preattestation))
else:
preattestation_hash, signature = client.sign_message_with_hash(account, preattestation)
assert preattestation_hash == preattestation.hash, \
f"Expected hash {preattestation.hash.hex()} but got {preattestation_hash.hex()}"
account.check_signature(signature, bytes(preattestation))
with tezos_navigator.goto_home_hwm():
tezos_navigator.assert_screen("hwm_before_sign", snap_path=snap_path)

if not with_hash:
signature = client.sign_message(account, preattestation)
account.check_signature(signature, bytes(preattestation))
else:
preattestation_hash, signature = client.sign_message_with_hash(account, preattestation)
assert preattestation_hash == preattestation.hash, \
f"Expected hash {preattestation.hash.hex()} but got {preattestation_hash.hex()}"
account.check_signature(signature, bytes(preattestation))

if firmware.is_nano:
# No update for Stax
backend.wait_for_screen_change()
if firmware.device == "nanos":
# Wait blink
time.sleep(0.5)
tezos_navigator.assert_screen("hwm_after_sign", snap_path=snap_path)


tezos_navigator.check_app_context(
account,
Expand All @@ -517,6 +542,8 @@ def test_sign_preattestation(
def test_sign_attestation(
account: Account,
with_hash: bool,
firmware: Firmware,
backend: BackendInterface,
client: TezosClient,
tezos_navigator: TezosNavigator) -> None:
"""Test the SIGN(_WITH_HASH) instruction on attestation."""
Expand All @@ -539,14 +566,25 @@ def test_sign_attestation(
chain_id=main_chain_id
)

if not with_hash:
signature = client.sign_message(account, attestation)
account.check_signature(signature, bytes(attestation))
else:
attestation_hash, signature = client.sign_message_with_hash(account, attestation)
assert attestation_hash == attestation.hash, \
f"Expected hash {attestation.hash.hex()} but got {attestation_hash.hex()}"
account.check_signature(signature, bytes(attestation))
with tezos_navigator.goto_home_hwm():
tezos_navigator.assert_screen("hwm_before_sign", snap_path=snap_path)

if not with_hash:
signature = client.sign_message(account, attestation)
account.check_signature(signature, bytes(attestation))
else:
attestation_hash, signature = client.sign_message_with_hash(account, attestation)
assert attestation_hash == attestation.hash, \
f"Expected hash {attestation.hash.hex()} but got {attestation_hash.hex()}"
account.check_signature(signature, bytes(attestation))

if firmware.is_nano:
# No update for Stax
backend.wait_for_screen_change()
if firmware.device == "nanos":
# Wait blink
time.sleep(0.5)
tezos_navigator.assert_screen("hwm_after_sign", snap_path=snap_path)

tezos_navigator.check_app_context(
account,
Expand All @@ -561,6 +599,8 @@ def test_sign_attestation(
def test_sign_attestation_dal(
account: Account,
with_hash: bool,
firmware: Firmware,
backend: BackendInterface,
client: TezosClient,
tezos_navigator: TezosNavigator) -> None:
"""Test the SIGN(_WITH_HASH) instruction on attestation."""
Expand All @@ -583,14 +623,25 @@ def test_sign_attestation_dal(
chain_id=main_chain_id
)

if not with_hash:
signature = client.sign_message(account, attestation)
account.check_signature(signature, bytes(attestation))
else:
attestation_hash, signature = client.sign_message_with_hash(account, attestation)
assert attestation_hash == attestation.hash, \
f"Expected hash {attestation.hash.hex()} but got {attestation_hash.hex()}"
account.check_signature(signature, bytes(attestation))
with tezos_navigator.goto_home_hwm():
tezos_navigator.assert_screen("hwm_before_sign", snap_path=snap_path)

if not with_hash:
signature = client.sign_message(account, attestation)
account.check_signature(signature, bytes(attestation))
else:
attestation_hash, signature = client.sign_message_with_hash(account, attestation)
assert attestation_hash == attestation.hash, \
f"Expected hash {attestation.hash.hex()} but got {attestation_hash.hex()}"
account.check_signature(signature, bytes(attestation))

if firmware.is_nano:
# No update for Stax
backend.wait_for_screen_change()
if firmware.device == "nanos":
# Wait blink
time.sleep(0.5)
tezos_navigator.assert_screen("hwm_after_sign", snap_path=snap_path)

tezos_navigator.check_app_context(
account,
Expand All @@ -605,6 +656,8 @@ def test_sign_attestation_dal(
def test_sign_block(
account: Account,
with_hash: bool,
firmware: Firmware,
backend: BackendInterface,
client: TezosClient,
tezos_navigator: TezosNavigator) -> None:
"""Test the SIGN(_WITH_HASH) instruction on block."""
Expand All @@ -627,14 +680,25 @@ def test_sign_block(
chain_id=main_chain_id
)

if not with_hash:
signature = client.sign_message(account, block)
account.check_signature(signature, bytes(block))
else:
block_hash, signature = client.sign_message_with_hash(account, block)
assert block_hash == block.hash, \
f"Expected hash {block.hash.hex()} but got {block_hash.hex()}"
account.check_signature(signature, bytes(block))
with tezos_navigator.goto_home_hwm():
tezos_navigator.assert_screen("hwm_before_sign", snap_path=snap_path)

if not with_hash:
signature = client.sign_message(account, block)
account.check_signature(signature, bytes(block))
else:
block_hash, signature = client.sign_message_with_hash(account, block)
assert block_hash == block.hash, \
f"Expected hash {block.hash.hex()} but got {block_hash.hex()}"
account.check_signature(signature, bytes(block))

if firmware.is_nano:
# No update for Stax
backend.wait_for_screen_change()
if firmware.device == "nanos":
# Wait blink
time.sleep(0.5)
tezos_navigator.assert_screen("hwm_after_sign", snap_path=snap_path)

tezos_navigator.check_app_context(
account,
Expand Down
72 changes: 70 additions & 2 deletions test/utils/navigator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
"""Module providing a tezos navigator."""

from pathlib import Path
from typing import TypeVar, Callable, Optional, Tuple, Union
from typing import TypeVar, Callable, Optional, Tuple, Union, Generator
import time

from contextlib import contextmanager
from multiprocessing.pool import ThreadPool

from ragger.backend import BackendInterface
Expand Down Expand Up @@ -74,6 +75,7 @@ def show_qr(self):
"""Tap to show qr code."""
self.client.finger_touch(*TezosUseCaseAddressConfirmation.SHOW_QR)

APP_CONTEXT = Path("app_context")
class TezosNavigator(metaclass=MetaScreen):
"""Class representing the tezos app navigator."""

Expand Down Expand Up @@ -196,7 +198,7 @@ def check_app_context(self,
f"Expected signature scheme {account.sig_scheme.name} "\
f"but got {received_sig_scheme.name}"

snap_path = snap_path / "app_context"
snap_path = snap_path / APP_CONTEXT
if self.firmware.is_nano:
self.backend.wait_for_home_screen()
self.backend.right_click()
Expand Down Expand Up @@ -235,6 +237,72 @@ def check_app_context(self,
self.backend.wait_for_screen_change()
self.assert_screen("home_screen", snap_path=snap_path)

@contextmanager
def goto_home_public_key(self, snap_path: Path = Path("")) -> Generator[None, None, None]:
snap_path = snap_path / APP_CONTEXT

if self.firmware.is_nano:
self.backend.wait_for_home_screen()
self.backend.right_click()
self.backend.wait_for_screen_change()
self.assert_screen("version", snap_path=snap_path)
self.backend.right_click()
self.backend.wait_for_screen_change()
self.assert_screen("chain_id", snap_path=snap_path)
self.backend.right_click()
self.backend.wait_for_screen_change()
else:
self.assert_screen("home_screen", snap_path=snap_path)
self.home.settings()
self.backend.wait_for_screen_change()

yield

if self.firmware.is_nano:
self.backend.left_click()
self.backend.wait_for_screen_change()
self.assert_screen("chain_id", snap_path=snap_path)
self.backend.left_click()
self.backend.wait_for_screen_change()
self.assert_screen("version", snap_path=snap_path)
self.backend.left_click()
self.backend.wait_for_screen_change()
self.assert_screen("home_screen", snap_path=snap_path)
else:
self.settings.multi_page_exit()
self.backend.wait_for_screen_change()
self.assert_screen("home_screen", snap_path=snap_path)

@contextmanager
def goto_home_hwm(self, snap_path: Path = Path("")) -> Generator[None, None, None]:
snap_path = snap_path / APP_CONTEXT

if self.firmware.is_nano:
self.backend.wait_for_home_screen()
self.backend.left_click()
self.backend.wait_for_screen_change()
self.assert_screen("exit", snap_path=snap_path)
self.backend.left_click()
self.backend.wait_for_screen_change()
else:
self.assert_screen("home_screen", snap_path=snap_path)
self.home.settings()
self.backend.wait_for_screen_change()

yield

if self.firmware.is_nano:
self.backend.right_click()
self.backend.wait_for_screen_change()
self.assert_screen("exit", snap_path=snap_path)
self.backend.right_click()
self.backend.wait_for_screen_change()
self.assert_screen("home_screen", snap_path=snap_path)
else:
self.settings.multi_page_exit()
self.backend.wait_for_screen_change()
self.assert_screen("home_screen", snap_path=snap_path)

def accept_key_navigate(self, **kwargs):
"""Navigate until accept key"""
if self.firmware.is_nano:
Expand Down

0 comments on commit fe96e7a

Please sign in to comment.