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 222b3bf commit 5998000
Show file tree
Hide file tree
Showing 75 changed files with 178 additions and 69 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.
247 changes: 178 additions & 69 deletions test/test_instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,62 @@
ZEBRA_ACCOUNTS,
)

class nano_navigation:
backend: BackendInterface
tezos_navigator: TezosNavigator
snap_path: Path
def __init__(self, snap: Path, bknd: BackendInterface, nav :TezosNavigator):
self.backend = bknd
self.tezos_navigator = nav
self.snap_path = snap
def screen(self, name):
self.tezos_navigator.assert_screen(name, snap_path=self.snap_path)
def right(self):
self.backend.right_click()
self.backend.wait_for_screen_change()
def left(self):
self.backend.left_click()
self.backend.wait_for_screen_change()
def both(self):
self.backend.both_click()
self.backend.wait_for_screen_change()



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

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



@pytest.mark.parametrize("account", [None, *ACCOUNTS])
def test_review_home(account: Optional[Account],
backend: BackendInterface,
Expand All @@ -74,84 +130,74 @@ 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()
app = nano_navigation(snap_path, backend, tezos_navigator)

if firmware.is_nano:
screen("home_screen")
right()
screen("version")
right()
screen("chain_id")
right()
app.screen("home_screen")
app.right()
app.screen("version")
app.right()
app.screen("chain_id")
app.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()
app.screen("public_key_hash_" + str(i))
app.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()
app.screen("public_key_hash")
app.right()
app.screen("high_watermark")
app.right()
app.screen("settings")
app.right()
app.screen("exit")
app.right()
app.screen("home_screen")
app.left()
app.screen("exit")
app.left()
app.screen("settings")
app.left()
app.screen("high_watermark")
app.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()
app.screen("public_key_hash_" + str(i))
app.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()
app.screen("public_key_hash")
app.left()
app.screen("chain_id")
app.left()
app.screen("version")
app.right()
app.screen("chain_id")
app.left()
app.screen("version")
app.left()
app.screen("home_screen")
app.left()
app.screen("exit")
app.left()
app.screen("settings")
app.left()
app.screen("high_watermark")
app.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()
app.screen("settings")
app.both()
app.screen("hwm_status_enabled")
app.both()
app.screen("hwm_status_disabled")
app.right()
app.screen("back")
app.both()
app.screen("home_screen")
app.left()
app.screen("exit")
app.right()
app.screen("home_screen")
app.left()
else:
backend.wait_for_home_screen()
tezos_navigator.home.settings()
Expand Down Expand Up @@ -1226,6 +1272,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 no chain has been setup change 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

0 comments on commit 5998000

Please sign in to comment.