1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-07-07 07:12:34 +00:00

WIP - click and persistence tests for TT

This commit is contained in:
grdddj 2023-01-19 19:06:49 +01:00
parent fcf7ac5133
commit a37cb1c49b
10 changed files with 39 additions and 24 deletions

View File

@ -198,8 +198,8 @@ where
{
fn trace(&self, t: &mut dyn crate::trace::Tracer) {
t.open("SwipePage");
t.field("active_page", &self.scrollbar.active_page);
t.field("page_count", &self.scrollbar.page_count);
t.kw_pair("active_page", &self.scrollbar.active_page);
t.kw_pair("page_count", &self.scrollbar.page_count);
t.field("content", &self.content);
t.field("buttons", &self.buttons);
t.close();

View File

@ -1169,10 +1169,15 @@ async def confirm_set_new_pin(
br_code=br_code,
)
if "wipe_code" in br_type:
title = "WIPE CODE INFO"
else:
title = "PIN INFORMATION"
return await confirm_action(
ctx,
br_type,
title="PIN INFO",
title=title,
description="\n\n".join(information),
br_code=br_code,
)

View File

@ -174,6 +174,17 @@ class LayoutButtons(LayoutBase):
return None
def select_word_button_texts(self) -> List[str]:
"""Get text of all buttons in the layout.
Example button: "< Button text : LADYBUG >"
-> ["LADYBUG"]
Only for TT.
"""
print("self.str_content", self.str_content)
return re.findall(r"< Button +text : +(.*?) +>", self.str_content)
class LayoutContent(LayoutBase):
"""Stores content of a layout as returned from Trezor.
@ -223,10 +234,6 @@ class LayoutContent(LayoutBase):
def text_content(self) -> str:
"""Getting text that is displayed in the main part of the screen."""
raw = self.raw_content()
# print("self.str_content", self.str_content)
# print("raw", raw)
# replaved = raw.replace("\n", " ")
# print("replaved", replaved)
return raw.replace("\n", " ")
def raw_content(self) -> str:

View File

@ -62,7 +62,7 @@ def enter_share(
if legacy_ui:
assert layout.str_content == "Slip39Keyboard"
else:
assert layout.str_content == "< MnemonicKeyboard >"
assert "MnemonicKeyboard" in layout.str_content
for word in share.split(" "):
layout = enter_word(debug, word, is_slip39=True)

View File

@ -58,13 +58,13 @@ def read_words(debug: "DebugLink", is_advanced: bool = False) -> list[str]:
def confirm_words(debug: "DebugLink", words: list[str]) -> None:
layout = debug.wait_layout()
assert "Select word" in layout.str_content
assert "Select word" in layout.text_content()
for _ in range(3):
# "Select word 3 of 20"
# ^
word_pos = int(layout.text_content().split()[2])
# Unifying both the buttons and words to lowercase
btn_texts = [text.lower() for text in layout.buttons()]
btn_texts = [text.lower() for text in layout.buttons.select_word_button_texts()]
wanted_word = words[word_pos - 1].lower()
button_pos = btn_texts.index(wanted_word)
layout = debug.click(buttons.RESET_WORD_CHECK[button_pos], wait=True)

View File

@ -46,7 +46,7 @@ def set_autolock_delay(device_handler: "BackgroundDeviceHandler", delay_ms: int)
device_handler.run(device.apply_settings, auto_lock_delay_ms=delay_ms)
layout = debug.wait_layout()
assert layout.str_content == "< PinKeyboard >"
assert "PinKeyboard" in layout.str_content
debug.input("1234")
layout = debug.wait_layout()
@ -131,7 +131,7 @@ def test_dryrun_locks_at_number_of_words(device_handler: "BackgroundDeviceHandle
layout = debug.wait_layout()
assert "Do you really want to check the recovery seed?" in layout.text_content()
layout = debug.click(buttons.OK, wait=True)
assert layout.str_content == "< PinKeyboard >"
assert "PinKeyboard" in layout.str_content
layout = debug.input(PIN4, wait=True)
assert "select the number of words " in layout.text_content()
@ -144,7 +144,7 @@ def test_dryrun_locks_at_number_of_words(device_handler: "BackgroundDeviceHandle
# unlock
layout = debug.click(buttons.OK, wait=True)
assert layout.str_content == "< PinKeyboard >"
assert "PinKeyboard" in layout.str_content
layout = debug.input(PIN4, wait=True)
# we are back at homescreen
@ -162,7 +162,7 @@ def test_dryrun_locks_at_word_entry(device_handler: "BackgroundDeviceHandler"):
layout = debug.wait_layout()
assert "Do you really want to check the recovery seed?" in layout.text_content()
layout = debug.click(buttons.OK, wait=True)
assert layout.str_content == "< PinKeyboard >"
assert "PinKeyboard" in layout.str_content
layout = debug.input(PIN4, wait=True)
# select 20 words
@ -170,7 +170,7 @@ def test_dryrun_locks_at_word_entry(device_handler: "BackgroundDeviceHandler"):
layout = debug.click(buttons.OK, wait=True)
# make sure keyboard locks
assert layout.str_content == "< MnemonicKeyboard >"
assert "MnemonicKeyboard" in layout.str_content
time.sleep(10.1)
layout = debug.wait_layout()
assert layout.str_content.startswith("< Lockscreen")
@ -189,7 +189,7 @@ def test_dryrun_enter_word_slowly(device_handler: "BackgroundDeviceHandler"):
layout = debug.wait_layout()
assert "Do you really want to check the recovery seed?" in layout.text_content()
layout = debug.click(buttons.OK, wait=True)
assert layout.str_content == "< PinKeyboard >"
assert "PinKeyboard" in layout.str_content
layout = debug.input(PIN4, wait=True)
# select 20 words
@ -197,11 +197,11 @@ def test_dryrun_enter_word_slowly(device_handler: "BackgroundDeviceHandler"):
layout = debug.click(buttons.OK, wait=True)
# type the word OCEAN slowly
assert layout.str_content == "< MnemonicKeyboard >"
assert "MnemonicKeyboard" in layout.str_content
for coords in buttons.type_word("ocea", is_slip39=True):
time.sleep(9)
debug.click(coords)
layout = debug.click(buttons.CONFIRM_WORD, wait=True)
# should not have locked, even though we took 9 seconds to type each letter
assert layout.str_content == "< MnemonicKeyboard >"
assert "MnemonicKeyboard" in layout.str_content
device_handler.kill_task()

View File

@ -41,7 +41,7 @@ def test_hold_to_lock(device_handler: "BackgroundDeviceHandler"):
# unlock with message
device_handler.run(common.get_test_address)
layout = debug.wait_layout()
assert layout.str_content == "< PinKeyboard >"
assert "PinKeyboard" in layout.str_content
debug.input("1234", wait=True)
assert device_handler.result()
@ -57,7 +57,7 @@ def test_hold_to_lock(device_handler: "BackgroundDeviceHandler"):
# unlock by touching
layout = debug.click(buttons.INFO, wait=True)
assert layout.str_content == "< PinKeyboard >"
assert "PinKeyboard" in layout.str_content
debug.input("1234", wait=True)
assert device_handler.features().unlocked is True

View File

@ -78,6 +78,7 @@ def test_reset_slip39_basic_1of1(device_handler: "BackgroundDeviceHandler"):
# read words
words = reset.read_words(debug)
print("words", words)
# confirm words
reset.confirm_words(debug, words)

View File

@ -74,6 +74,8 @@ class InputFlowSetupDevicePINWIpeCode(InputFlowBase):
def input_flow_common(self) -> GeneratorType:
yield # do you want to set/change the wipe_code?
self.debug.press_yes()
yield # wipe code info
self.debug.press_yes()
yield # enter current pin
self.debug.input(self.pin)
yield # enter new wipe code

View File

@ -53,7 +53,7 @@ def test_abort(emulator: Emulator):
assert layout.title() == "RECOVERY MODE"
layout = debug.click(buttons.OK, wait=True)
assert "select the number of words" in layout.str_content
assert "select the number of words" in layout.text_content()
device_handler.restart(emulator)
debug = device_handler.debuglink()
@ -63,7 +63,7 @@ def test_abort(emulator: Emulator):
# no waiting for layout because layout doesn't change
layout = debug.read_layout()
assert "select the number of words" in layout.str_content
assert "select the number of words" in layout.text_content()
layout = debug.click(buttons.CANCEL, wait=True)
assert layout.title() == "ABORT RECOVERY"
@ -139,7 +139,7 @@ def test_recovery_on_old_wallet(emulator: Emulator):
assert "Enter any share" in layout.str_content
debug.press_yes()
layout = debug.wait_layout()
assert layout.str_content == "< MnemonicKeyboard >"
assert "MnemonicKeyboard" in layout.str_content
# enter first word
debug.input(words[0])
@ -151,7 +151,7 @@ def test_recovery_on_old_wallet(emulator: Emulator):
# try entering remaining 19 words
for word in words[1:]:
assert layout.str_content == "< MnemonicKeyboard >"
assert "MnemonicKeyboard" in layout.str_content
debug.input(word)
layout = debug.wait_layout()