Skip to content

Commit

Permalink
Add tests for hwm disabled option
Browse files Browse the repository at this point in the history
  • Loading branch information
ajinkyaraj-23 committed Apr 9, 2024
1 parent 57a5f92 commit 7b7740f
Show file tree
Hide file tree
Showing 76 changed files with 236 additions and 132 deletions.
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.
254 changes: 169 additions & 85 deletions test/test_instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,39 @@
ZEBRA_ACCOUNTS,
)

def disable_hwm(snap_path: Path, backend: BackendInterface, firmware: Firmware, tezos_navigator: TezosNavigator) -> None:

if firmware.is_nano:
tezos_navigator.assert_screen("home_screen",snap_path)
tezos_navigator.left()
tezos_navigator.assert_screen("quit",snap_path)
tezos_navigator.left()
tezos_navigator.assert_screen("Settings",snap_path)
tezos_navigator.press_both_buttons()
tezos_navigator.assert_screen("hwm_enabled",snap_path)
tezos_navigator.press_both_buttons()
tezos_navigator.assert_screen("hwm_disabled",snap_path)
tezos_navigator.right()
tezos_navigator.assert_screen("back",snap_path)
tezos_navigator.press_both_buttons()
tezos_navigator.assert_screen("home_screen",snap_path)
else:
backend.wait_for_home_screen()
tezos_navigator.home.settings()
backend.wait_for_screen_change()
tezos_navigator.assert_screen("app_context",snap_path)
tezos_navigator.settings.next()
backend.wait_for_screen_change()
tezos_navigator.assert_screen("hwm_status_on",snap_path)
tezos_navigator.layout_choice.choose(1)
backend.wait_for_screen_change()
tezos_navigator.assert_screen("hwm_status_off",snap_path)
tezos_navigator.settings.multi_page_exit()
backend.wait_for_screen_change()
tezos_navigator.assert_screen("home_screen",snap_path)



@pytest.mark.parametrize("account", [None, *ACCOUNTS])
def test_review_home(account: Optional[Account],
backend: BackendInterface,
Expand All @@ -74,131 +107,119 @@ def test_review_home(account: Optional[Account],
test_hwm
)

def screen(name):
tezos_navigator.assert_screen(name, snap_path=snap_path)
def right():
backend.right_click()
backend.wait_for_screen_change()
def left():
backend.left_click()
backend.wait_for_screen_change()
def both():
backend.both_click()
backend.wait_for_screen_change()

if firmware.is_nano:
screen("home_screen")
right()
screen("version")
right()
screen("chain_id")
right()
tezos_navigator.assert_screen("home_screen",snap_path)
tezos_navigator.right()
tezos_navigator.assert_screen("version",snap_path)
tezos_navigator.right()
tezos_navigator.assert_screen("chain_id",snap_path)
tezos_navigator.right()
if account is not None and firmware.device == "nanos":
for i in range(1, account.nanos_screens + 1):
screen("public_key_hash_" + str(i))
right()
tezos_navigator.assert_screen("public_key_hash_" + str(i,snap_path))
tezos_navigator.right()
else:
screen("public_key_hash")
right()
screen("high_watermark")
right()
screen("settings")
right()
screen("exit")
right()
screen("home_screen")
left()
screen("exit")
left()
screen("settings")
left()
screen("high_watermark")
left()
tezos_navigator.assert_screen("public_key_hash",snap_path)
tezos_navigator.right()
tezos_navigator.assert_screen("high_watermark",snap_path)
tezos_navigator.right()
tezos_navigator.assert_screen("settings",snap_path)
tezos_navigator.right()
tezos_navigator.assert_screen("exit",snap_path)
tezos_navigator.right()
tezos_navigator.assert_screen("home_screen",snap_path)
tezos_navigator.left()
tezos_navigator.assert_screen("exit",snap_path)
tezos_navigator.left()
tezos_navigator.assert_screen("settings",snap_path)
tezos_navigator.left()
tezos_navigator.assert_screen("high_watermark",snap_path)
tezos_navigator.left()
if account is not None and firmware.device == "nanos":
for i in reversed(range(1, account.nanos_screens + 1)):
screen("public_key_hash_" + str(i))
left()
tezos_navigator.assert_screen("public_key_hash_" + str(i,snap_path))
tezos_navigator.left()
else:
screen("public_key_hash")
left()
screen("chain_id")
left()
screen("version")
right()
screen("chain_id")
left()
screen("version")
left()
screen("home_screen")
left()
screen("exit")
left()
screen("settings")
left()
screen("high_watermark")
right()
tezos_navigator.assert_screen("public_key_hash",snap_path)
tezos_navigator.left()
tezos_navigator.assert_screen("chain_id",snap_path)
tezos_navigator.left()
tezos_navigator.assert_screen("version",snap_path)
tezos_navigator.right()
tezos_navigator.assert_screen("chain_id",snap_path)
tezos_navigator.left()
tezos_navigator.assert_screen("version",snap_path)
tezos_navigator.left()
tezos_navigator.assert_screen("home_screen",snap_path)
tezos_navigator.left()
tezos_navigator.assert_screen("exit",snap_path)
tezos_navigator.left()
tezos_navigator.assert_screen("settings",snap_path)
tezos_navigator.left()
tezos_navigator.assert_screen("high_watermark",snap_path)
tezos_navigator.right()
# Check settings menu
screen("settings")
both()
screen("hwm_status_enabled")
both()
screen("hwm_status_disabled")
right()
screen("back")
both()
screen("home_screen")
left()
screen("exit")
right()
screen("home_screen")
left()
tezos_navigator.assert_screen("settings",snap_path)
tezos_navigator.press_both_buttons()
tezos_navigator.assert_screen("hwm_status_enabled",snap_path)
tezos_navigator.press_both_buttons()
tezos_navigator.assert_screen("hwm_status_disabled",snap_path)
tezos_navigator.right()
tezos_navigator.assert_screen("back",snap_path)
tezos_navigator.press_both_buttons()
tezos_navigator.assert_screen("home_screen",snap_path)
tezos_navigator.left()
tezos_navigator.assert_screen("exit",snap_path)
tezos_navigator.right()
tezos_navigator.assert_screen("home_screen",snap_path)
tezos_navigator.left()
else:
backend.wait_for_home_screen()
tezos_navigator.home.settings()
backend.wait_for_screen_change()
screen("app_context")
tezos_navigator.assert_screen("app_context",snap_path)
tezos_navigator.settings.next()
backend.wait_for_screen_change()
screen("hwm_status")
tezos_navigator.assert_screen("hwm_status",snap_path)
tezos_navigator.settings.next()
backend.wait_for_screen_change()
screen("description")
tezos_navigator.assert_screen("description",snap_path)
tezos_navigator.settings.previous()
backend.wait_for_screen_change()
screen("hwm_status")
tezos_navigator.assert_screen("hwm_status",snap_path)
tezos_navigator.settings.previous()
backend.wait_for_screen_change()
screen("app_context")
tezos_navigator.assert_screen("app_context",snap_path)
tezos_navigator.settings.multi_page_exit()
backend.wait_for_screen_change()
screen("home_screen")
tezos_navigator.assert_screen("home_screen",snap_path)
tezos_navigator.home.settings()
backend.wait_for_screen_change()
screen("app_context")
tezos_navigator.assert_screen("app_context",snap_path)
tezos_navigator.settings.next()
backend.wait_for_screen_change()
screen("hwm_status_on")
tezos_navigator.assert_screen("hwm_status_on",snap_path)
tezos_navigator.layout_choice.choose(1)
backend.wait_for_screen_change()
screen("hwm_status_off")
tezos_navigator.assert_screen("hwm_status_off",snap_path)
tezos_navigator.layout_choice.choose(1)
backend.wait_for_screen_change()
screen("hwm_status_on")
tezos_navigator.assert_screen("hwm_status_on",snap_path)
tezos_navigator.settings.next()
backend.wait_for_screen_change()
screen("description")
tezos_navigator.assert_screen("description",snap_path)
tezos_navigator.settings.previous()
backend.wait_for_screen_change()
screen("hwm_status_on")
tezos_navigator.assert_screen("hwm_status_on",snap_path)
tezos_navigator.settings.previous()
backend.wait_for_screen_change()
screen("app_context")
tezos_navigator.assert_screen("app_context",snap_path)
tezos_navigator.settings.next()
backend.wait_for_screen_change()
screen("hwm_status_on")
tezos_navigator.assert_screen("hwm_status_on",snap_path)
tezos_navigator.settings.multi_page_exit()
backend.wait_for_screen_change()
screen("home_screen")
tezos_navigator.assert_screen("home_screen",snap_path)

def test_version(client: TezosClient) -> None:
"""Test the VERSION instruction."""
Expand Down Expand Up @@ -1226,6 +1247,69 @@ def test_sign_multiple_operation(
)
account.check_signature(signature, bytes(message))

def test_sign_when_hwm_disabled(
client: TezosClient,
backend: BackendInterface,
firmware: Firmware,
tezos_navigator: TezosNavigator) -> None:
"""Check that signing, when HWM is disabled, changes the main HWM."""

account = DEFAULT_ACCOUNT
snap_path = Path(f"{account}")

disable_hwm(snap_path, backend, firmware, tezos_navigator)

tezos_navigator.setup_app_context(
account,
DEFAULT_CHAIN_ID, # Chain = 0
main_hwm=Hwm(0, 0),
test_hwm=Hwm(0, 0)
)

attestation = build_attestation(
1, 0,
DEFAULT_CHAIN_ID # Chain = 0
)

client.sign_message(account, attestation)

tezos_navigator.check_app_context(
account,
chain_id=DEFAULT_CHAIN_ID,
main_hwm=Hwm(1, 0),
test_hwm=Hwm(0, 0),
snap_path=Path("sign_1_0"))

attestation = build_attestation(
2, 0,
"NetXH12AexHqTQa" # Chain = 1
)

client.sign_message(account, attestation)

tezos_navigator.check_app_context(
account,
chain_id=DEFAULT_CHAIN_ID,
main_hwm=Hwm(2, 0),
test_hwm=Hwm(0, 0),
snap_path=Path("sign_2_0"))

attestation = build_attestation(
2, 0,
"NetXH12Af5mrXhq" # Chain = 2
)

with StatusCode.WRONG_VALUES.expected():
client.sign_message(account, attestation)

tezos_navigator.check_app_context(
account,
chain_id=DEFAULT_CHAIN_ID,
main_hwm=Hwm(2, 0),
test_hwm=Hwm(0, 0),
snap_path=Path("sign_2_0")
)


def test_sign_when_no_chain_setup(
client: TezosClient,
Expand Down
Loading

0 comments on commit 7b7740f

Please sign in to comment.