1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-18 04:18:10 +00:00

chore(tests): adapt click tests for the new recovery flow

[no changelog]
This commit is contained in:
grdddj 2023-07-27 15:55:01 +02:00 committed by Jiří Musil
parent d48bae4598
commit e8ee3f7ee1
3 changed files with 22 additions and 45 deletions

View File

@ -39,19 +39,13 @@ def enter_word(
def confirm_recovery(debug: "DebugLink") -> None: def confirm_recovery(debug: "DebugLink") -> None:
layout = debug.wait_layout()
if debug.model == "T": if debug.model == "T":
if not debug.legacy_ui and not debug.legacy_debug: assert layout.title().startswith(("RECOVER WALLET", "BACKUP CHECK"))
layout = debug.wait_layout()
assert layout.title().startswith(
("WALLET RECOVERY", "RECOVER WALLET", "BACKUP CHECK")
)
debug.click(buttons.OK, wait=True) debug.click(buttons.OK, wait=True)
elif debug.model == "R": elif debug.model == "R":
layout = debug.wait_layout()
assert layout.title() == "RECOVER WALLET" assert layout.title() == "RECOVER WALLET"
debug.press_right(wait=True) debug.press_right(wait=True)
layout = debug.press_right(wait=True)
assert "safe to eject" in layout.text_content()
debug.press_right() debug.press_right()
@ -61,20 +55,11 @@ def select_number_of_words(
if wait: if wait:
debug.wait_layout() debug.wait_layout()
if debug.model == "T": if debug.model == "T":
# select number of words assert "number of words" in debug.read_layout().text_content()
if not debug.legacy_ui and not debug.legacy_debug: assert debug.read_layout().title() in (
assert "number of words" in debug.read_layout().text_content() "BACKUP CHECK",
layout = debug.click(buttons.OK, wait=True) "RECOVER WALLET",
if debug.legacy_ui: )
assert layout.json_str == "WordSelector"
elif debug.legacy_debug:
assert "SelectWordCount" in layout.json_str
else:
assert layout.title() in (
"WALLET RECOVERY",
"BACKUP CHECK",
"RECOVER WALLET",
)
# click the number # click the number
word_option_offset = 6 word_option_offset = 6
@ -99,11 +84,10 @@ def select_number_of_words(
else: else:
raise ValueError("Unknown model") raise ValueError("Unknown model")
if not debug.legacy_ui and not debug.legacy_debug: if num_of_words in (20, 33):
if num_of_words in (20, 33): assert "Enter any share" in layout.text_content()
assert "Enter any share" in layout.text_content() else:
else: assert "Enter your backup" in layout.text_content()
assert "Enter your backup" in layout.text_content()
def enter_share( def enter_share(
@ -112,13 +96,7 @@ def enter_share(
if debug.model == "T": if debug.model == "T":
layout = debug.click(buttons.OK, wait=True) layout = debug.click(buttons.OK, wait=True)
if debug.legacy_ui: assert layout.main_component() == "MnemonicKeyboard"
assert layout.json_str == "Slip39Keyboard"
elif debug.legacy_debug:
assert "MnemonicKeyboard" in layout.json_str
else:
assert layout.main_component() == "MnemonicKeyboard"
for word in share.split(" "): for word in share.split(" "):
layout = enter_word(debug, word, is_slip39=True) layout = enter_word(debug, word, is_slip39=True)
@ -130,7 +108,7 @@ def enter_share(
# Word entering info # Word entering info
debug.press_right() debug.press_right()
layout = debug.press_right(wait=True) layout = debug.press_right(wait=True)
assert "Slip39Entry" in layout.all_components() assert "MnemonicKeyboard" in layout.all_components()
for word in share.split(" "): for word in share.split(" "):
layout = enter_word(debug, word, is_slip39=True) layout = enter_word(debug, word, is_slip39=True)
@ -162,7 +140,7 @@ def enter_seed(debug: "DebugLink", seed_words: list[str]) -> None:
debug.press_right() debug.press_right()
layout = debug.press_right(wait=True) layout = debug.press_right(wait=True)
assert "Bip39Entry" in layout.all_components() assert "MnemonicKeyboard" in layout.all_components()
for word in seed_words: for word in seed_words:
layout = enter_word(debug, word, is_slip39=False) layout = enter_word(debug, word, is_slip39=False)

View File

@ -301,10 +301,7 @@ def test_dryrun_locks_at_word_entry(device_handler: "BackgroundDeviceHandler"):
assert layout.main_component() == "MnemonicKeyboard" assert layout.main_component() == "MnemonicKeyboard"
elif debug.model == "R": elif debug.model == "R":
layout = debug.press_right(wait=True) layout = debug.press_right(wait=True)
assert layout.title() in ("RECOVER WALLET", "BACKUP CHECK") assert "MnemonicKeyboard" in layout.all_components()
debug.press_right()
layout = debug.press_right(wait=True)
assert "Slip39Entry" in layout.all_components()
# make sure keyboard locks # make sure keyboard locks
time.sleep(10.1) time.sleep(10.1)
@ -338,10 +335,7 @@ def test_dryrun_enter_word_slowly(device_handler: "BackgroundDeviceHandler"):
assert layout.main_component() == "MnemonicKeyboard" assert layout.main_component() == "MnemonicKeyboard"
elif debug.model == "R": elif debug.model == "R":
layout = debug.press_right(wait=True) layout = debug.press_right(wait=True)
assert layout.title() in ("RECOVER WALLET", "BACKUP CHECK") assert "MnemonicKeyboard" in layout.all_components()
debug.press_right()
layout = debug.press_right(wait=True)
assert "Slip39Entry" in layout.all_components()
# pressing middle button three times # pressing middle button three times
for _ in range(3): for _ in range(3):
@ -349,7 +343,7 @@ def test_dryrun_enter_word_slowly(device_handler: "BackgroundDeviceHandler"):
debug.press_middle() debug.press_middle()
layout = debug.wait_layout() layout = debug.wait_layout()
# should not have locked, even though we took 9 seconds to type each letter # should not have locked, even though we took 9 seconds to type each letter
assert "Slip39Entry" in layout.all_components() assert "MnemonicKeyboard" in layout.all_components()
with pytest.raises(exceptions.Cancelled): with pytest.raises(exceptions.Cancelled):
device_handler.result() device_handler.result()

View File

@ -54,6 +54,11 @@ def test_abort(core_emulator: Emulator):
# no waiting for layout because layout doesn't change # no waiting for layout because layout doesn't change
assert "number of words" in debug.read_layout().text_content() assert "number of words" in debug.read_layout().text_content()
# clicking at 24 in word choice (the same coords as CANCEL)
layout = debug.click(buttons.CANCEL, wait=True)
# Cancelling the backup
assert "Enter your backup" in debug.read_layout().text_content()
layout = debug.click(buttons.CANCEL, wait=True) layout = debug.click(buttons.CANCEL, wait=True)
assert layout.title() == "ABORT RECOVERY" assert layout.title() == "ABORT RECOVERY"