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 9e15b4e commit ffe5579
Show file tree
Hide file tree
Showing 76 changed files with 253 additions and 91 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.
279 changes: 194 additions & 85 deletions test/test_instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,131 +74,120 @@ 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 @@ -1227,6 +1216,126 @@ 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}")

tezos_navigator.disable_hwm(snap_path)

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")
)


@pytest.mark.parametrize("hwm_disabled", [False, True])
def test_hwm_disabled_manual(client: TezosClient, tezos_navigator: TezosNavigator, backend_name, hwm_disabled: bool) -> None:
"""On device test to verify HWM settings operation.
When HWM is disabled, an abrupt power off will result in HWM reset to 0.
Whwereas when HWM settings is enabled, the abrupt power off will not
reset the HWM."""
# check if backend is speculos, then return .
if backend_name == "speculos":
assert True
return

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

if hwm_disabled:
tezos_navigator.disable_hwm(snap_path)

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

for i in range(1, 11):
attestation = build_attestation(i, 0, DEFAULT_CHAIN_ID)
client.sign_message(account, attestation)

tezos_navigator.check_app_context(
account,
DEFAULT_CHAIN_ID,
main_hwm = Hwm(10,0),
test_hwm = Hwm(0,0),
snap_path = snap_path,
backend_name = backend_name
)
output = "No"
while output.find("Y") == -1:
output = input("1. Now switch off the device abruptly. \n"
"2. Reconnect it to power source. \n"
"3. Open the baking app."
"Done? (Yes/No)")

final_hwm = 10
if hwm_disabled:
final_hwm = 0
tezos_navigator.check_app_context(
account,
DEFAULT_CHAIN_ID,
main_hwm = Hwm(final_hwm,0),
test_hwm = Hwm(0,0),
snap_path = snap_path,
backend_name = backend_name
)


def test_sign_when_no_chain_setup(
client: TezosClient,
tezos_navigator: TezosNavigator) -> None:
Expand Down
Loading

0 comments on commit ffe5579

Please sign in to comment.