mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-07-05 06:12:34 +00:00
WIP - device tests for TT
This commit is contained in:
parent
002976e16d
commit
fcf7ac5133
@ -197,7 +197,8 @@ where
|
|||||||
.set_page_count(complete_page_count);
|
.set_page_count(complete_page_count);
|
||||||
|
|
||||||
// Placing a title and scrollbar in case the title is there
|
// Placing a title and scrollbar in case the title is there
|
||||||
// (scrollbar will be active - counting pages - even when not placed and painted)
|
// (scrollbar will be active - counting pages - even when not placed and
|
||||||
|
// painted)
|
||||||
if self.title.is_some() {
|
if self.title.is_some() {
|
||||||
let (title_area, scrollbar_area) =
|
let (title_area, scrollbar_area) =
|
||||||
title_area.split_right(self.scrollbar.inner().overall_width() + SCROLLBAR_SPACE);
|
title_area.split_right(self.scrollbar.inner().overall_width() + SCROLLBAR_SPACE);
|
||||||
|
@ -92,7 +92,7 @@ where
|
|||||||
{
|
{
|
||||||
fn trace(&self, t: &mut dyn crate::trace::Tracer) {
|
fn trace(&self, t: &mut dyn crate::trace::Tracer) {
|
||||||
t.open("Frame");
|
t.open("Frame");
|
||||||
t.field("title", &self.title);
|
t.title(&self.title.inner().text().as_ref());
|
||||||
t.field("content", &self.content);
|
t.field("content", &self.content);
|
||||||
t.close();
|
t.close();
|
||||||
}
|
}
|
||||||
@ -186,7 +186,7 @@ where
|
|||||||
{
|
{
|
||||||
fn trace(&self, t: &mut dyn crate::trace::Tracer) {
|
fn trace(&self, t: &mut dyn crate::trace::Tracer) {
|
||||||
t.open("NotificationFrame");
|
t.open("NotificationFrame");
|
||||||
t.field("title", &self.title);
|
t.title(&self.title.as_ref());
|
||||||
t.field("content", &self.content);
|
t.field("content", &self.content);
|
||||||
t.close();
|
t.close();
|
||||||
}
|
}
|
||||||
|
@ -32,14 +32,10 @@ if __debug__:
|
|||||||
|
|
||||||
class RustLayout(ui.Layout):
|
class RustLayout(ui.Layout):
|
||||||
# pylint: disable=super-init-not-called
|
# pylint: disable=super-init-not-called
|
||||||
def __init__(self, layout: Any, is_backup: bool = False):
|
def __init__(self, layout: Any):
|
||||||
self.layout = layout
|
self.layout = layout
|
||||||
self.timer = loop.Timer()
|
self.timer = loop.Timer()
|
||||||
self.layout.attach_timer_fn(self.set_timer)
|
self.layout.attach_timer_fn(self.set_timer)
|
||||||
self.is_backup = is_backup
|
|
||||||
|
|
||||||
if __debug__ and self.is_backup:
|
|
||||||
self.notify_backup()
|
|
||||||
|
|
||||||
def set_timer(self, token: int, deadline: int) -> None:
|
def set_timer(self, token: int, deadline: int) -> None:
|
||||||
self.timer.schedule(deadline, token)
|
self.timer.schedule(deadline, token)
|
||||||
@ -110,28 +106,8 @@ class RustLayout(ui.Layout):
|
|||||||
if msg is not None:
|
if msg is not None:
|
||||||
raise ui.Result(msg)
|
raise ui.Result(msg)
|
||||||
|
|
||||||
if self.is_backup:
|
|
||||||
self.notify_backup()
|
|
||||||
notify_layout_change(self)
|
notify_layout_change(self)
|
||||||
|
|
||||||
def notify_backup(self):
|
|
||||||
# TODO: delete this in favor of debuglink::LayoutContent::seed_words
|
|
||||||
from apps.debug import reset_current_words
|
|
||||||
|
|
||||||
content = "\n".join(self.read_content())
|
|
||||||
start = "< Paragraphs "
|
|
||||||
end = ">"
|
|
||||||
start_pos = content.index(start)
|
|
||||||
end_pos = content.index(end, start_pos)
|
|
||||||
words: list[str] = []
|
|
||||||
for line in content[start_pos + len(start) : end_pos].split("\n"):
|
|
||||||
line = line.strip()
|
|
||||||
if not line:
|
|
||||||
continue
|
|
||||||
space_pos = line.index(" ")
|
|
||||||
words.append(line[space_pos + 1 :])
|
|
||||||
reset_current_words.publish(words)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
def create_tasks(self) -> tuple[loop.AwaitableTask, ...]:
|
def create_tasks(self) -> tuple[loop.AwaitableTask, ...]:
|
||||||
|
@ -54,7 +54,6 @@ async def show_share_words(
|
|||||||
title=title,
|
title=title,
|
||||||
pages=pages,
|
pages=pages,
|
||||||
),
|
),
|
||||||
is_backup=True,
|
|
||||||
),
|
),
|
||||||
"backup_words",
|
"backup_words",
|
||||||
ButtonRequestType.ResetDevice,
|
ButtonRequestType.ResetDevice,
|
||||||
|
@ -199,6 +199,7 @@ class LayoutContent(LayoutBase):
|
|||||||
********************
|
********************
|
||||||
Icon:cancel [Cancel], --- [None], CONFIRM [Confirm]
|
Icon:cancel [Cancel], --- [None], CONFIRM [Confirm]
|
||||||
"""
|
"""
|
||||||
|
print(self.str_content)
|
||||||
title_separator = f"\n{20*'-'}\n"
|
title_separator = f"\n{20*'-'}\n"
|
||||||
btn_separator = f"\n{20*'*'}\n"
|
btn_separator = f"\n{20*'*'}\n"
|
||||||
|
|
||||||
@ -222,6 +223,10 @@ class LayoutContent(LayoutBase):
|
|||||||
def text_content(self) -> str:
|
def text_content(self) -> str:
|
||||||
"""Getting text that is displayed in the main part of the screen."""
|
"""Getting text that is displayed in the main part of the screen."""
|
||||||
raw = self.raw_content()
|
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", " ")
|
return raw.replace("\n", " ")
|
||||||
|
|
||||||
def raw_content(self) -> str:
|
def raw_content(self) -> str:
|
||||||
|
@ -80,7 +80,7 @@ def enter_shares(debug: "DebugLink", shares: list[str]) -> None:
|
|||||||
remaining -= 1
|
remaining -= 1
|
||||||
expected_text = f"{remaining} more share"
|
expected_text = f"{remaining} more share"
|
||||||
|
|
||||||
assert "You have successfully recovered your wallet" in layout.text_content()
|
assert "You have finished recovering your wallet" in layout.text_content()
|
||||||
|
|
||||||
|
|
||||||
def finalize(debug: "DebugLink") -> None:
|
def finalize(debug: "DebugLink") -> None:
|
||||||
|
@ -276,6 +276,7 @@ def click_through(
|
|||||||
def read_and_confirm_mnemonic(
|
def read_and_confirm_mnemonic(
|
||||||
debug: "DebugLink", choose_wrong: bool = False
|
debug: "DebugLink", choose_wrong: bool = False
|
||||||
) -> Generator[None, "ButtonRequest", Optional[str]]:
|
) -> Generator[None, "ButtonRequest", Optional[str]]:
|
||||||
|
# TODO: these are very similar, reuse some code
|
||||||
if debug.model == "T":
|
if debug.model == "T":
|
||||||
mnemonic = yield from read_and_confirm_mnemonic_tt(debug, choose_wrong)
|
mnemonic = yield from read_and_confirm_mnemonic_tt(debug, choose_wrong)
|
||||||
elif debug.model == "R":
|
elif debug.model == "R":
|
||||||
@ -303,16 +304,26 @@ def read_and_confirm_mnemonic_tt(
|
|||||||
mnemonic: list[str] = []
|
mnemonic: list[str] = []
|
||||||
br = yield
|
br = yield
|
||||||
assert br.pages is not None
|
assert br.pages is not None
|
||||||
for _ in range(br.pages - 1):
|
|
||||||
mnemonic.extend(debug.read_reset_word().split())
|
# TODO: make the below better
|
||||||
|
for i in range(br.pages - 1):
|
||||||
|
if i == 0:
|
||||||
|
layout = debug.wait_layout()
|
||||||
|
else:
|
||||||
|
layout = debug.read_layout()
|
||||||
|
words = layout.seed_words()
|
||||||
|
mnemonic.extend(words)
|
||||||
debug.swipe_up(wait=True)
|
debug.swipe_up(wait=True)
|
||||||
|
|
||||||
# last page is confirmation
|
# Last confirmation page is special
|
||||||
mnemonic.extend(debug.read_reset_word().split())
|
layout = debug.read_layout()
|
||||||
|
words = layout.seed_words()
|
||||||
|
mnemonic.extend(words)
|
||||||
|
|
||||||
debug.press_yes()
|
debug.press_yes()
|
||||||
|
|
||||||
# check share
|
# check share
|
||||||
for _ in range(3):
|
for i in range(3):
|
||||||
index = debug.read_reset_word_pos()
|
index = debug.read_reset_word_pos()
|
||||||
if choose_wrong:
|
if choose_wrong:
|
||||||
debug.input(mnemonic[(index + 1) % len(mnemonic)])
|
debug.input(mnemonic[(index + 1) % len(mnemonic)])
|
||||||
|
@ -53,7 +53,7 @@ def test_sd_protect_unlock(client: Client):
|
|||||||
|
|
||||||
def input_flow_enable_sd_protect():
|
def input_flow_enable_sd_protect():
|
||||||
yield # Enter PIN to unlock device
|
yield # Enter PIN to unlock device
|
||||||
assert "< PinKeyboard >" == layout().str_content
|
assert "PinKeyboard" in layout().str_content
|
||||||
client.debug.input("1234")
|
client.debug.input("1234")
|
||||||
|
|
||||||
yield # do you really want to enable SD protection
|
yield # do you really want to enable SD protection
|
||||||
@ -61,7 +61,7 @@ def test_sd_protect_unlock(client: Client):
|
|||||||
client.debug.press_yes()
|
client.debug.press_yes()
|
||||||
|
|
||||||
yield # enter current PIN
|
yield # enter current PIN
|
||||||
assert "< PinKeyboard >" == layout().str_content
|
assert "PinKeyboard" in layout().str_content
|
||||||
client.debug.input("1234")
|
client.debug.input("1234")
|
||||||
|
|
||||||
yield # you have successfully enabled SD protection
|
yield # you have successfully enabled SD protection
|
||||||
@ -75,23 +75,27 @@ def test_sd_protect_unlock(client: Client):
|
|||||||
|
|
||||||
def input_flow_change_pin():
|
def input_flow_change_pin():
|
||||||
yield # do you really want to change PIN?
|
yield # do you really want to change PIN?
|
||||||
assert "CHANGE PIN" == layout().title()
|
assert "PIN SETTINGS" == layout().title()
|
||||||
client.debug.press_yes()
|
client.debug.press_yes()
|
||||||
|
|
||||||
yield # enter current PIN
|
yield # enter current PIN
|
||||||
assert "< PinKeyboard >" == layout().str_content
|
assert "PinKeyboard" in layout().str_content
|
||||||
client.debug.input("1234")
|
client.debug.input("1234")
|
||||||
|
|
||||||
yield # enter new PIN
|
yield # enter new PIN
|
||||||
assert "< PinKeyboard >" == layout().str_content
|
assert "PinKeyboard" in layout().str_content
|
||||||
client.debug.input("1234")
|
client.debug.input("1234")
|
||||||
|
|
||||||
|
yield # re-enter to confirm
|
||||||
|
assert "re-enter to confirm" in layout().text_content()
|
||||||
|
client.debug.press_yes()
|
||||||
|
|
||||||
yield # enter new PIN again
|
yield # enter new PIN again
|
||||||
assert "< PinKeyboard >" == layout().str_content
|
assert "PinKeyboard" in layout().str_content
|
||||||
client.debug.input("1234")
|
client.debug.input("1234")
|
||||||
|
|
||||||
yield # Pin change successful
|
yield # Pin change successful
|
||||||
assert "You have successfully changed your PIN." in layout().text_content()
|
assert "PIN changed" in layout().text_content()
|
||||||
client.debug.press_yes()
|
client.debug.press_yes()
|
||||||
|
|
||||||
with client:
|
with client:
|
||||||
@ -103,11 +107,11 @@ def test_sd_protect_unlock(client: Client):
|
|||||||
|
|
||||||
def input_flow_change_pin_format():
|
def input_flow_change_pin_format():
|
||||||
yield # do you really want to change PIN?
|
yield # do you really want to change PIN?
|
||||||
assert "CHANGE PIN" == layout().title()
|
assert "PIN SETTINGS" == layout().title()
|
||||||
client.debug.press_yes()
|
client.debug.press_yes()
|
||||||
|
|
||||||
yield # enter current PIN
|
yield # enter current PIN
|
||||||
assert "< PinKeyboard >" == layout().str_content
|
assert "PinKeyboard" in layout().str_content
|
||||||
client.debug.input("1234")
|
client.debug.input("1234")
|
||||||
|
|
||||||
yield # SD card problem
|
yield # SD card problem
|
||||||
|
@ -993,7 +993,7 @@ def enter_recovery_seed_dry_run(debug: DebugLink, mnemonic: list[str]) -> Genera
|
|||||||
debug.click(buttons.OK)
|
debug.click(buttons.OK)
|
||||||
|
|
||||||
yield
|
yield
|
||||||
assert "Select number of words" in debug.wait_layout().text_content()
|
assert "select the number of words" in debug.wait_layout().text_content()
|
||||||
debug.click(buttons.OK)
|
debug.click(buttons.OK)
|
||||||
|
|
||||||
yield
|
yield
|
||||||
@ -1005,12 +1005,12 @@ def enter_recovery_seed_dry_run(debug: DebugLink, mnemonic: list[str]) -> Genera
|
|||||||
debug.click(buttons.grid34(index % 3, index // 3))
|
debug.click(buttons.grid34(index % 3, index // 3))
|
||||||
|
|
||||||
yield
|
yield
|
||||||
assert "Enter recovery seed" in debug.wait_layout().text_content()
|
assert "enter your recovery seed" in debug.wait_layout().text_content()
|
||||||
debug.click(buttons.OK)
|
debug.click(buttons.OK)
|
||||||
|
|
||||||
yield
|
yield
|
||||||
for word in mnemonic:
|
for word in mnemonic:
|
||||||
assert debug.wait_layout().str_content == "< MnemonicKeyboard >"
|
assert "MnemonicKeyboard" in debug.wait_layout().str_content
|
||||||
debug.input(word)
|
debug.input(word)
|
||||||
|
|
||||||
|
|
||||||
@ -1076,7 +1076,7 @@ class InputFlowBip39RecoveryDryRunInvalid(InputFlowBase):
|
|||||||
self.debug.click(buttons.OK)
|
self.debug.click(buttons.OK)
|
||||||
|
|
||||||
yield # retry screen
|
yield # retry screen
|
||||||
assert "Select number of words" in self.layout().text_content()
|
assert "select the number of words" in self.layout().text_content()
|
||||||
self.debug.click(buttons.CANCEL)
|
self.debug.click(buttons.CANCEL)
|
||||||
|
|
||||||
yield
|
yield
|
||||||
@ -1137,15 +1137,19 @@ def bip39_recovery_possible_pin(
|
|||||||
# PIN when requested
|
# PIN when requested
|
||||||
if pin is not None:
|
if pin is not None:
|
||||||
yield
|
yield
|
||||||
assert debug.wait_layout().str_content == "< PinKeyboard >"
|
assert "PinKeyboard" in debug.wait_layout().str_content
|
||||||
debug.input(pin)
|
debug.input(pin)
|
||||||
|
|
||||||
yield
|
yield
|
||||||
assert debug.wait_layout().str_content == "< PinKeyboard >"
|
assert "re-enter to confirm" in debug.wait_layout().text_content()
|
||||||
|
debug.press_yes()
|
||||||
|
|
||||||
|
yield
|
||||||
|
assert "PinKeyboard" in debug.wait_layout().str_content
|
||||||
debug.input(pin)
|
debug.input(pin)
|
||||||
|
|
||||||
yield
|
yield
|
||||||
assert "Select number of words" in debug.wait_layout().text_content()
|
assert "select the number of words" in debug.wait_layout().text_content()
|
||||||
debug.press_yes()
|
debug.press_yes()
|
||||||
|
|
||||||
yield
|
yield
|
||||||
@ -1153,17 +1157,17 @@ def bip39_recovery_possible_pin(
|
|||||||
debug.input(str(len(mnemonic)))
|
debug.input(str(len(mnemonic)))
|
||||||
|
|
||||||
yield
|
yield
|
||||||
assert "Enter recovery seed" in debug.wait_layout().text_content()
|
assert "enter your recovery seed" in debug.wait_layout().text_content()
|
||||||
debug.press_yes()
|
debug.press_yes()
|
||||||
|
|
||||||
yield
|
yield
|
||||||
for word in mnemonic:
|
for word in mnemonic:
|
||||||
assert debug.wait_layout().str_content == "< MnemonicKeyboard >"
|
assert "MnemonicKeyboard" in debug.wait_layout().str_content
|
||||||
debug.input(word)
|
debug.input(word)
|
||||||
|
|
||||||
yield
|
yield
|
||||||
assert (
|
assert (
|
||||||
"You have successfully recovered your wallet."
|
"You have finished recovering your wallet."
|
||||||
in debug.wait_layout().text_content()
|
in debug.wait_layout().text_content()
|
||||||
)
|
)
|
||||||
debug.press_yes()
|
debug.press_yes()
|
||||||
|
@ -184,7 +184,7 @@ def test_recovery_multiple_resets(emulator: Emulator):
|
|||||||
expected_text = "You have entered"
|
expected_text = "You have entered"
|
||||||
debug = _restart(device_handler, emulator)
|
debug = _restart(device_handler, emulator)
|
||||||
|
|
||||||
assert "You have successfully recovered your wallet" in layout.text_content()
|
assert "You have finished recovering your wallet" in layout.text_content()
|
||||||
|
|
||||||
device_handler = BackgroundDeviceHandler(emulator.client)
|
device_handler = BackgroundDeviceHandler(emulator.client)
|
||||||
debug = device_handler.debuglink()
|
debug = device_handler.debuglink()
|
||||||
|
Loading…
Reference in New Issue
Block a user