1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-13 02:58:57 +00:00

tests: use read_layout everywhere

This commit is contained in:
matejcik 2023-11-21 13:51:59 +01:00 committed by M1nd3r
parent 84c58131f6
commit 9cb9a2e15d
23 changed files with 515 additions and 469 deletions

View File

@ -45,39 +45,36 @@ def get_char_category(char: str) -> PassphraseCategory:
return PassphraseCategory.SPECIAL
def go_next(debug: "DebugLink", wait: bool = False) -> "LayoutContent" | None:
def go_next(debug: "DebugLink") -> LayoutContent:
if debug.model in (models.T2T1,):
return debug.click(buttons.OK, wait=wait) # type: ignore
return debug.click(buttons.OK)
elif debug.model in (models.T2B1,):
return debug.press_right(wait=wait) # type: ignore
return debug.press_right()
elif debug.model in (models.T3T1,):
return debug.swipe_up(wait=wait)
return debug.swipe_up()
else:
raise RuntimeError("Unknown model")
def tap_to_confirm(debug: "DebugLink", wait: bool = False) -> "LayoutContent" | None:
def tap_to_confirm(debug: "DebugLink") -> LayoutContent | None:
if debug.model in (models.T2T1,):
return debug.read_layout() # type: ignore
elif debug.model in (models.T2B1,):
return debug.read_layout() # type: ignore
elif debug.model in (models.T3T1,):
return debug.click(buttons.TAP_TO_CONFIRM, wait=wait)
return debug.click(buttons.TAP_TO_CONFIRM, )
else:
raise RuntimeError("Unknown model")
def go_back(
debug: "DebugLink", wait: bool = False, r_middle: bool = False
) -> "LayoutContent" | None:
def go_back(debug: "DebugLink", r_middle: bool = False) -> LayoutContent:
if debug.model in (models.T2T1, models.T3T1):
return debug.click(buttons.CANCEL, wait=wait) # type: ignore
return debug.click(buttons.CANCEL)
elif debug.model in (models.T2B1,):
if r_middle:
return debug.press_middle(wait=wait) # type: ignore
return debug.press_middle()
else:
return debug.press_left(wait=wait) # type: ignore
return debug.press_left()
else:
raise RuntimeError("Unknown model")
@ -118,19 +115,16 @@ def navigate_to_action_and_press(
)
# Press or hold
if hold_ms:
debug.press_middle_htc(1000)
else:
debug.press_middle(wait=True)
debug.press_middle(hold_ms=hold_ms)
def unlock_gesture(debug: "DebugLink", wait: bool = False) -> "LayoutContent" | None:
def unlock_gesture(debug: "DebugLink") -> LayoutContent | None:
if debug.model in (models.T2T1,):
return debug.click(buttons.OK, wait=wait) # type: ignore
return debug.click(buttons.OK, ) # type: ignore
elif debug.model in (models.T2B1,):
return debug.press_right(wait=wait) # type: ignore
return debug.press_right() # type: ignore
elif debug.model in (models.T3T1,):
return debug.click(buttons.TAP_TO_CONFIRM, wait=wait) # type: ignore
return debug.click(buttons.TAP_TO_CONFIRM, ) # type: ignore
else:
raise RuntimeError("Unknown model")
@ -156,7 +150,7 @@ def _move_one_closer(
current_action: str,
all_actions: list[str],
is_carousel: bool,
) -> "LayoutContent":
) -> LayoutContent:
"""Pressing either left or right regarding to the current situation"""
index_diff = _get_action_index(wanted_action, all_actions) - _get_action_index(
current_action, all_actions
@ -164,17 +158,17 @@ def _move_one_closer(
if not is_carousel:
# Simply move according to the index in a closed list
if index_diff > 0:
return debug.press_right(wait=True)
return debug.press_right()
else:
return debug.press_left(wait=True)
return debug.press_left()
else:
# Carousel can move in a circle - over the edges
# Always move the shortest way
action_half = len(all_actions) // 2
if index_diff > action_half or -action_half < index_diff < 0:
return debug.press_left(wait=True)
return debug.press_left()
else:
return debug.press_right(wait=True)
return debug.press_right()
def get_possible_btn_texts(path: str) -> str:

View File

@ -24,8 +24,8 @@ def enter_word(
debug.click(coords)
if debug.model is models.T3T1 and not is_slip39 and len(word) > 4:
# T3T1 (mercury) BIP39 keyboard allows to "confirm" only if the word is fully written, you need to click the word to auto-complete
debug.click(buttons.CONFIRM_WORD, wait=True)
return debug.click(buttons.CONFIRM_WORD, wait=True)
debug.click(buttons.CONFIRM_WORD)
return debug.click(buttons.CONFIRM_WORD)
elif debug.model in (models.T2B1,):
letter_index = 0
layout = debug.read_layout()
@ -34,39 +34,36 @@ def enter_word(
while layout.find_values_by_key("letter_choices"):
letter = word[letter_index]
while not layout.get_middle_choice() == letter:
layout = debug.press_right(wait=True)
layout = debug.press_right()
layout = debug.press_middle(wait=True)
layout = debug.press_middle()
letter_index += 1
# Word choices
while not layout.get_middle_choice() == word:
layout = debug.press_right(wait=True)
layout = debug.press_right()
return debug.press_middle(wait=True)
return debug.press_middle()
else:
raise ValueError("Unknown model")
def confirm_recovery(debug: "DebugLink", title: str = "recovery__title") -> None:
layout = debug.wait_layout()
layout = debug.read_layout()
TR.assert_equals(layout.title(), title)
if debug.model in (models.T2T1,):
debug.click(buttons.OK, wait=True)
debug.click(buttons.OK)
elif debug.model in (models.T3T1,):
debug.swipe_up(wait=True)
debug.swipe_up()
elif debug.model in (models.T2B1,):
debug.press_right(wait=True)
debug.press_right()
def select_number_of_words(
debug: "DebugLink",
num_of_words: int = 20,
wait: bool = True,
unlock_repeated_backup=False,
) -> None:
if wait:
debug.wait_layout()
if debug.model in (models.T2T1,):
TR.assert_equals(debug.read_layout().text_content(), "recovery__num_of_words")
# click the number
@ -76,17 +73,17 @@ def select_number_of_words(
num_of_words
) # raises if num of words is invalid
coords = buttons.grid34(index % 3, index // 3)
layout = debug.click(coords, wait=True)
layout = debug.click(coords)
elif debug.model in (models.T2B1,):
layout = debug.press_right(wait=True)
layout = debug.press_right()
TR.assert_equals(layout.title(), "word_count__title")
# navigate to the number and confirm it
word_options = (12, 18, 20, 24, 33)
index = word_options.index(num_of_words)
for _ in range(index):
debug.press_right(wait=True)
layout = debug.press_middle(wait=True)
debug.press_right()
layout = debug.press_middle()
elif debug.model in (models.T3T1,):
if num_of_words == 12:
coords = buttons.grid34(0, 1)
@ -100,7 +97,7 @@ def select_number_of_words(
coords = buttons.grid34(1, 3)
else:
raise ValueError("Invalid num_of_words")
layout = debug.click(coords, wait=True)
layout = debug.click(coords)
else:
raise ValueError("Unknown model")
@ -141,14 +138,14 @@ def enter_share(
) -> "LayoutContent":
if debug.model in (models.T2B1,):
TR.assert_in(debug.read_layout().title(), before_title)
layout = debug.wait_layout()
layout = debug.read_layout()
for _ in range(layout.page_count()):
layout = debug.press_right(wait=True)
layout = debug.press_right()
elif debug.model in (models.T3T1,):
layout = debug.swipe_up(wait=True)
layout = debug.swipe_up()
else:
TR.assert_in(debug.read_layout().title(), before_title)
layout = debug.click(buttons.OK, wait=True)
layout = debug.click(buttons.OK)
assert "MnemonicKeyboard" in layout.all_components()
@ -223,20 +220,20 @@ def enter_seed_previous_correct(
if go_back:
go_back = False
if debug.model in (models.T2T1, models.T3T1):
debug.swipe_right(wait=True)
debug.swipe_right()
for _ in range(len(bad_word)):
debug.click(buttons.RECOVERY_DELETE, wait=True)
debug.click(buttons.RECOVERY_DELETE)
elif debug.model in (models.T2B1,):
layout = debug.read_layout()
while layout.get_middle_choice() not in DELETE_BTN_TEXTS:
layout = debug.press_right(wait=True)
layout = debug.press_middle(wait=True)
layout = debug.press_right()
layout = debug.press_middle()
for _ in range(len(bad_word)):
while layout.get_middle_choice() not in DELETE_BTN_TEXTS:
layout = debug.press_left(wait=True)
layout = debug.press_middle(wait=True)
layout = debug.press_left()
layout = debug.press_middle()
continue
if i in bad_indexes:
@ -264,18 +261,18 @@ def prepare_enter_seed(
],
)
if debug.model in (models.T2T1,):
debug.click(buttons.OK, wait=True)
debug.click(buttons.OK)
elif debug.model in (models.T3T1,):
debug.swipe_up(wait=True)
debug.swipe_up(wait=True)
debug.swipe_up()
debug.swipe_up()
elif debug.model in (models.T2B1,):
debug.press_right(wait=True)
debug.press_right()
layout = debug.press_right(wait=True)
debug.press_right()
layout = debug.press_right()
assert "MnemonicKeyboard" in layout.all_components()
def finalize(debug: "DebugLink") -> None:
layout = go_next(debug, wait=True)
layout = go_next(debug)
assert layout is not None
assert layout.main_component() == "Homescreen"

View File

@ -15,103 +15,103 @@ if TYPE_CHECKING:
def confirm_new_wallet(debug: "DebugLink") -> None:
TR.assert_equals(debug.read_layout().title(), "reset__title_create_wallet")
if debug.model in (models.T2T1,):
debug.click(buttons.OK, wait=True)
debug.click(buttons.OK)
elif debug.model in (models.T3T1,):
debug.swipe_up(wait=True)
debug.click(buttons.TAP_TO_CONFIRM, wait=True)
debug.swipe_up(wait=True) # Wallet created
debug.swipe_up()
debug.click(buttons.TAP_TO_CONFIRM)
debug.swipe_up() # Wallet created
elif debug.model in (models.T2B1,):
debug.press_right(wait=True)
debug.press_right(wait=True)
debug.press_right()
debug.press_right()
def confirm_read(debug: "DebugLink", middle_r: bool = False) -> None:
if debug.model in (models.T2T1,):
debug.click(buttons.OK, wait=True)
debug.click(buttons.OK)
elif debug.model in (models.T3T1,):
debug.swipe_up(wait=True)
debug.swipe_up()
elif debug.model in (models.T2B1,):
page_count = debug.read_layout().page_count()
if page_count > 1:
for _ in range(page_count - 1):
debug.press_right(wait=True)
debug.press_right()
if middle_r:
debug.press_middle(wait=True)
debug.press_middle()
else:
debug.press_right(wait=True)
debug.press_right()
def cancel_backup(
debug: "DebugLink", middle_r: bool = False, confirm: bool = False
) -> None:
if debug.model in (models.T2T1,):
debug.click(buttons.CANCEL, wait=True)
debug.click(buttons.CANCEL, wait=True)
debug.click(buttons.CANCEL)
debug.click(buttons.CANCEL)
elif debug.model in (models.T3T1,):
debug.click(buttons.CORNER_BUTTON, wait=True)
debug.click(buttons.VERTICAL_MENU[0], wait=True)
debug.click(buttons.CORNER_BUTTON)
debug.click(buttons.VERTICAL_MENU[0])
if confirm:
debug.swipe_up(wait=True)
debug.swipe_up()
debug.click(buttons.TAP_TO_CONFIRM)
elif debug.model in (models.T2B1,):
debug.press_left(wait=True)
debug.press_left(wait=True)
debug.press_left()
debug.press_left()
def set_selection(debug: "DebugLink", button: tuple[int, int], diff: int) -> None:
if debug.model in (models.T2T1, models.T3T1):
assert "NumberInputDialog" in debug.read_layout().all_components()
for _ in range(diff):
debug.click(button, wait=True)
debug.click(button)
if debug.model in (models.T2T1,):
debug.click(buttons.OK, wait=True)
debug.click(buttons.OK)
else:
debug.swipe_up(wait=True)
debug.swipe_up()
elif debug.model in (models.T2B1,):
layout = debug.read_layout()
if layout.title() in TR.translate(
"reset__title_number_of_shares"
) + TR.translate("words__title_threshold"):
# Special info screens
layout = debug.press_right(wait=True)
layout = debug.press_right()
assert "NumberInput" in layout.all_components()
if button == buttons.reset_minus(debug.model.internal_name):
for _ in range(diff):
debug.press_left(wait=True)
debug.press_left()
else:
for _ in range(diff):
debug.press_right(wait=True)
debug.press_middle(wait=True)
debug.press_right()
debug.press_middle()
def read_words(debug: "DebugLink", do_htc: bool = True) -> list[str]:
words: list[str] = []
if debug.model in (models.T2B1,):
debug.press_right(wait=True)
debug.press_right()
elif debug.model in (models.T3T1,):
debug.swipe_up(wait=True)
debug.swipe_up()
# Swiping through all the pages and loading the words
layout = debug.read_layout()
for _ in range(layout.page_count() - 1):
words.extend(layout.seed_words())
layout = debug.swipe_up(wait=True)
layout = debug.swipe_up()
assert layout is not None
if debug.model in (models.T2T1, models.T3T1):
words.extend(layout.seed_words())
if debug.model in (models.T3T1,):
debug.swipe_up(wait=True)
debug.swipe_up()
# There is hold-to-confirm button
if do_htc:
if debug.model in (models.T2T1,):
debug.click_hold(buttons.OK, hold_ms=1500)
debug.click(buttons.OK, hold_ms=1500)
elif debug.model in (models.T3T1,):
debug.click_hold(buttons.TAP_TO_CONFIRM, hold_ms=1500)
elif debug.model in (models.T2B1,):
debug.press_right_htc(1200)
debug.press_right(hold_ms=1200)
else:
# It would take a very long time to test 16-of-16 with doing 1500 ms HTC after
# each word set
@ -122,15 +122,15 @@ def read_words(debug: "DebugLink", do_htc: bool = True) -> list[str]:
def confirm_words(debug: "DebugLink", words: list[str]) -> None:
if debug.model in (models.T3T1,):
debug.swipe_up(wait=True)
debug.swipe_up()
layout = debug.wait_layout()
layout = debug.read_layout()
if debug.model in (models.T2T1,):
TR.assert_template(layout.text_content(), "reset__select_word_x_of_y_template")
for _ in range(3):
# "Select word 3 of 20"
# ^
word_pos_match = re.search(r"\d+", debug.wait_layout().text_content())
word_pos_match = re.search(r"\d+", debug.read_layout().text_content())
assert word_pos_match is not None
word_pos = int(word_pos_match.group(0))
# Unifying both the buttons and words to lowercase
@ -139,13 +139,13 @@ def confirm_words(debug: "DebugLink", words: list[str]) -> None:
]
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)
layout = debug.click(buttons.RESET_WORD_CHECK[button_pos])
elif debug.model in (models.T3T1,):
TR.assert_template(layout.subtitle(), "reset__select_word_x_of_y_template")
for _ in range(3):
# "Select word 3 of 20"
# ^
word_pos_match = re.search(r"\d+", debug.wait_layout().subtitle())
word_pos_match = re.search(r"\d+", debug.read_layout().subtitle())
assert word_pos_match is not None
word_pos = int(word_pos_match.group(0))
# Unifying both the buttons and words to lowercase
@ -154,10 +154,10 @@ def confirm_words(debug: "DebugLink", words: list[str]) -> None:
]
wanted_word = words[word_pos - 1].lower()
button_pos = btn_texts.index(wanted_word)
layout = debug.click(buttons.VERTICAL_MENU[button_pos], wait=True)
layout = debug.click(buttons.VERTICAL_MENU[button_pos])
elif debug.model in (models.T2B1,):
TR.assert_in(layout.text_content(), "reset__select_correct_word")
layout = debug.press_right(wait=True)
layout = debug.press_right()
for _ in range(3):
# "SELECT 2ND WORD"
# ^
@ -168,9 +168,9 @@ def confirm_words(debug: "DebugLink", words: list[str]) -> None:
wanted_word = words[word_pos - 1].lower()
while not layout.get_middle_choice() == wanted_word:
layout = debug.press_right(wait=True)
layout = debug.press_right()
layout = debug.press_middle(wait=True)
layout = debug.press_middle()
def validate_mnemonics(mnemonics: list[str], expected_ems: bytes) -> None:

View File

@ -60,18 +60,18 @@ def set_autolock_delay(device_handler: "BackgroundDeviceHandler", delay_ms: int)
device_handler.run(device.apply_settings, auto_lock_delay_ms=delay_ms) # type: ignore
assert "PinKeyboard" in debug.wait_layout().all_components()
assert "PinKeyboard" in debug.read_layout().all_components()
debug.input("1234")
TR.assert_template(
debug.wait_layout().text_content(),
debug.read_layout().text_content(),
"auto_lock__change_template",
)
layout = go_next(debug, wait=True)
layout = go_next(debug)
if debug.model in (models.T3T1,):
layout = tap_to_confirm(debug, wait=True)
layout = tap_to_confirm(debug)
assert layout.main_component() == "Homescreen"
assert device_handler.result() == "Settings applied"
@ -101,22 +101,22 @@ def test_autolock_interrupts_signing(device_handler: "BackgroundDeviceHandler"):
assert (
"1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1"
in debug.wait_layout().text_content().replace(" ", "")
in debug.read_layout().text_content().replace(" ", "")
)
if debug.model in (models.T2T1,):
debug.click(buttons.OK, wait=True)
layout = debug.click(buttons.OK, wait=True)
debug.click(buttons.OK)
layout = debug.click(buttons.OK)
TR.assert_in(layout.text_content(), "send__total_amount")
assert "0.0039 BTC" in layout.text_content()
elif debug.model in (models.T3T1,):
debug.swipe_up(wait=True)
layout = debug.swipe_up(wait=True)
debug.swipe_up()
layout = debug.swipe_up()
TR.assert_in(layout.text_content(), "send__total_amount")
assert "0.0039 BTC" in layout.text_content()
elif debug.model in (models.T2B1,):
debug.press_right(wait=True)
layout = debug.press_right(wait=True)
debug.press_right()
layout = debug.press_right()
TR.assert_in(layout.text_content(), "send__total_amount")
assert "0.0039 BTC" in layout.text_content()
@ -153,23 +153,23 @@ def test_autolock_does_not_interrupt_signing(device_handler: "BackgroundDeviceHa
assert (
"1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1"
in debug.wait_layout().text_content().replace(" ", "")
in debug.read_layout().text_content().replace(" ", "")
)
if debug.model in (models.T2T1,):
debug.click(buttons.OK, wait=True)
layout = debug.click(buttons.OK, wait=True)
debug.click(buttons.OK)
layout = debug.click(buttons.OK)
TR.assert_in(layout.text_content(), "send__total_amount")
assert "0.0039 BTC" in layout.text_content()
elif debug.model in (models.T3T1,):
debug.swipe_up(wait=True)
layout = debug.swipe_up(wait=True)
debug.swipe_up()
layout = debug.swipe_up()
TR.assert_in(layout.text_content(), "send__total_amount")
assert "0.0039 BTC" in layout.text_content()
debug.swipe_up(wait=True)
debug.swipe_up()
elif debug.model in (models.T2B1,):
debug.press_right(wait=True)
layout = debug.press_right(wait=True)
debug.press_right()
layout = debug.press_right()
TR.assert_in(layout.text_content(), "send__total_amount")
assert "0.0039 BTC" in layout.text_content()
@ -182,11 +182,11 @@ def test_autolock_does_not_interrupt_signing(device_handler: "BackgroundDeviceHa
device_handler.client.set_filter(messages.TxAck, sleepy_filter)
# confirm transaction
if debug.model in (models.T2T1,):
debug.click(buttons.OK)
debug.click(buttons.OK, wait=False)
elif debug.model in (models.T3T1,):
debug.click(buttons.TAP_TO_CONFIRM)
elif debug.model in (models.T2B1,):
debug.press_middle()
debug.press_middle(wait=False)
signatures, tx = device_handler.result()
assert len(signatures) == 1
@ -203,7 +203,7 @@ def test_autolock_passphrase_keyboard(device_handler: "BackgroundDeviceHandler")
# get address
device_handler.run(common.get_test_address) # type: ignore
assert "PassphraseKeyboard" in debug.wait_layout().all_components()
assert "PassphraseKeyboard" in debug.read_layout().all_components()
if debug.model in (models.T2B1,):
# Going into the selected character category
@ -227,11 +227,11 @@ def test_autolock_passphrase_keyboard(device_handler: "BackgroundDeviceHandler")
# Send the passphrase to the client (TT has it clicked already, TR needs to input it)
if debug.model in (models.T2T1,):
debug.click(buttons.OK, wait=True)
debug.click(buttons.OK)
elif debug.model in (models.T3T1,):
debug.click(buttons.CORNER_BUTTON, wait=True)
debug.click(buttons.CORNER_BUTTON)
elif debug.model in (models.T2B1,):
debug.input("j" * 8, wait=True)
debug.input("j" * 8)
# address corresponding to "jjjjjjjj" passphrase
assert device_handler.result() == "mnF4yRWJXmzRB6EuBzuVigqeqTqirQupxJ"
@ -245,7 +245,7 @@ def test_autolock_interrupts_passphrase(device_handler: "BackgroundDeviceHandler
# get address
device_handler.run(common.get_test_address) # type: ignore
assert "PassphraseKeyboard" in debug.wait_layout().all_components()
assert "PassphraseKeyboard" in debug.read_layout().all_components()
if debug.model in (models.T2B1,):
# Going into the selected character category
@ -262,17 +262,17 @@ def test_autolock_interrupts_passphrase(device_handler: "BackgroundDeviceHandler
# wait for autolock to kick in
time.sleep(10.1)
assert debug.wait_layout().main_component() == "Lockscreen"
assert debug.read_layout().main_component() == "Lockscreen"
with pytest.raises(exceptions.Cancelled):
device_handler.result()
def unlock_dry_run(debug: "DebugLink") -> "LayoutContent":
TR.assert_in(debug.wait_layout().text_content(), "recovery__check_dry_run")
layout = go_next(debug, wait=True)
TR.assert_in(debug.read_layout().text_content(), "recovery__check_dry_run")
layout = go_next(debug)
assert "PinKeyboard" in layout.all_components()
layout = debug.input(PIN4, wait=True)
layout = debug.input(PIN4)
assert layout is not None
return layout
@ -285,28 +285,28 @@ def test_dryrun_locks_at_number_of_words(device_handler: "BackgroundDeviceHandle
device_handler.run(device.recover, dry_run=True) # type: ignore
layout = unlock_dry_run(debug)
TR.assert_in(debug.wait_layout().text_content(), "recovery__num_of_words")
TR.assert_in(debug.read_layout().text_content(), "recovery__num_of_words")
if debug.model in (models.T2B1,):
debug.press_right(wait=True)
debug.press_right()
# wait for autolock to trigger
time.sleep(10.1)
assert debug.wait_layout().main_component() == "Lockscreen"
assert debug.read_layout().main_component() == "Lockscreen"
with pytest.raises(exceptions.Cancelled):
device_handler.result()
# unlock
# lockscreen triggered automatically
debug.wait_layout(wait_for_external_change=True)
layout = unlock_gesture(debug, wait=True)
# debug.wait_layout()
layout = unlock_gesture(debug)
assert "PinKeyboard" in layout.all_components()
layout = debug.input(PIN4, wait=True)
layout = debug.input(PIN4)
assert layout is not None
# we are back at homescreen
TR.assert_in(debug.wait_layout().text_content(), "recovery__num_of_words")
TR.assert_in(debug.read_layout().text_content(), "recovery__num_of_words")
@pytest.mark.setup_client(pin=PIN4)
@ -322,15 +322,15 @@ def test_dryrun_locks_at_word_entry(device_handler: "BackgroundDeviceHandler"):
recovery.select_number_of_words(debug, 20)
if debug.model in (models.T2T1, models.T3T1):
layout = go_next(debug, wait=True)
layout = go_next(debug)
assert layout.main_component() == "MnemonicKeyboard"
elif debug.model in (models.T2B1,):
layout = debug.press_right(wait=True)
layout = debug.press_right()
assert "MnemonicKeyboard" in layout.all_components()
# make sure keyboard locks
time.sleep(10.1)
assert debug.wait_layout().main_component() == "Lockscreen"
assert debug.read_layout().main_component() == "Lockscreen"
with pytest.raises(exceptions.Cancelled):
device_handler.result()
@ -348,36 +348,47 @@ def test_dryrun_enter_word_slowly(device_handler: "BackgroundDeviceHandler"):
recovery.select_number_of_words(debug, 20)
if debug.model in (models.T2T1,):
layout = debug.click(buttons.OK, wait=True)
layout = debug.click(buttons.OK)
assert layout.main_component() == "MnemonicKeyboard"
# type the word OCEAN slowly
for coords in buttons.type_word("ocea", is_slip39=True):
time.sleep(9)
debug.click(coords)
layout = debug.click(buttons.CONFIRM_WORD, wait=True)
layout = debug.click(buttons.CONFIRM_WORD)
# should not have locked, even though we took 9 seconds to type each letter
assert layout.main_component() == "MnemonicKeyboard"
elif debug.model in (models.T3T1,):
layout = debug.swipe_up(wait=True)
layout = debug.swipe_up()
assert layout.main_component() == "MnemonicKeyboard"
# type the word OCEAN slowly
for coords in buttons.type_word("ocea", is_slip39=True):
time.sleep(9)
debug.click(coords)
layout = debug.click(buttons.CONFIRM_WORD, wait=True)
layout = debug.click(buttons.CONFIRM_WORD)
# should not have locked, even though we took 9 seconds to type each letter
assert layout.main_component() == "MnemonicKeyboard"
elif debug.model in (models.T3T1,):
layout = debug.swipe_up()
assert layout.main_component() == "MnemonicKeyboard"
# type the word OCEAN slowly
for coords in buttons.type_word("ocea", is_slip39=True):
time.sleep(9)
debug.click(coords)
layout = debug.click(buttons.CONFIRM_WORD)
# should not have locked, even though we took 9 seconds to type each letter
assert layout.main_component() == "MnemonicKeyboard"
elif debug.model in (models.T2B1,):
layout = debug.press_right(wait=True)
layout = debug.press_right()
assert "MnemonicKeyboard" in layout.all_components()
# pressing middle button three times
for _ in range(3):
time.sleep(9)
debug.press_middle()
layout = debug.wait_layout()
layout = debug.read_layout()
# should not have locked, even though we took 9 seconds to type each letter
assert "MnemonicKeyboard" in layout.all_components()
@ -405,7 +416,7 @@ def test_autolock_does_not_interrupt_preauthorized(
coin_name="Testnet",
script_type=messages.InputScriptType.SPENDTAPROOT,
)
debug.press_yes(wait=True)
debug.press_yes()
device_handler.result()
inputs = [

View File

@ -47,19 +47,19 @@ def test_hold_to_lock(device_handler: "BackgroundDeviceHandler"):
models.T3T1: 3500,
}[debug.model]
def hold(duration: int, wait: bool = True) -> None:
def hold(duration: int) -> None:
if debug.model in (models.T2B1,):
debug.press_right_htc(hold_ms=duration)
debug.press_right(hold_ms=duration)
else:
debug.input(x=13, y=37, hold_ms=duration, wait=wait)
debug.click((13, 37), hold_ms=duration)
assert device_handler.features().unlocked is False
# unlock with message
device_handler.run(common.get_test_address)
assert "PinKeyboard" in debug.wait_layout().all_components()
debug.input("1234", wait=True)
assert "PinKeyboard" in debug.read_layout().all_components()
debug.input("1234")
assert device_handler.result()
assert device_handler.features().unlocked is True
@ -77,12 +77,11 @@ def test_hold_to_lock(device_handler: "BackgroundDeviceHandler"):
# unlock by touching
if debug.model in (models.T2B1,):
# Doing a short HTC to simulate a click
debug.press_right_htc(hold_ms=100)
layout = debug.wait_layout()
layout = debug.press_right(hold_ms=100)
else:
layout = debug.click(buttons.INFO, wait=True)
layout = debug.click(buttons.INFO)
assert "PinKeyboard" in layout.all_components()
debug.input("1234", wait=True)
debug.input("1234")
assert device_handler.features().unlocked is True

View File

@ -98,6 +98,7 @@ def prepare_passphrase_dialogue(
) -> Generator["DebugLink", None, None]:
debug = device_handler.debuglink()
device_handler.run(get_test_address) # type: ignore
# TODO
assert debug.wait_layout().main_component() == "PassphraseKeyboard"
# Resetting the category as it could have been changed by previous tests
@ -212,7 +213,7 @@ def test_passphrase_delete(device_handler: "BackgroundDeviceHandler"):
for _ in range(4):
delete_char(debug)
debug.wait_layout()
debug.read_layout()
input_passphrase(debug, CommonPass.SHORT[8 - 4 :])
enter_passphrase(debug)
@ -242,7 +243,7 @@ def test_passphrase_loop_all_characters(device_handler: "BackgroundDeviceHandler
PassphraseCategory.SPECIAL,
):
go_to_category(debug, category)
debug.wait_layout()
debug.read_layout()
enter_passphrase(debug)
coords = buttons.pin_passphrase_grid(11)

View File

@ -102,7 +102,7 @@ def prepare_passphrase_dialogue(
) -> Generator["DebugLink", None, None]:
debug = device_handler.debuglink()
device_handler.run(get_test_address) # type: ignore
layout = debug.wait_layout()
layout = debug.read_layout()
assert "PassphraseKeyboard" in layout.all_components()
assert layout.passphrase() == ""
assert _current_category(debug) == PassphraseCategory.MENU

View File

@ -70,7 +70,7 @@ def prepare_passphrase_dialogue(
) -> Generator["DebugLink", None, None]:
debug = device_handler.debuglink()
device_handler.run(get_test_address) # type: ignore
assert debug.wait_layout().main_component() == "PassphraseKeyboard"
assert debug.read_layout().main_component() == "PassphraseKeyboard"
# Resetting the category as it could have been changed by previous tests
global TT_CATEGORY
@ -96,10 +96,10 @@ def go_to_category(debug: "DebugLink", category: PassphraseCategory) -> None:
target_index = TT_CATEGORIES.index(category)
if target_index > current_index:
for _ in range(target_index - current_index):
debug.swipe_left(wait=True)
debug.swipe_left()
else:
for _ in range(current_index - target_index):
debug.swipe_right(wait=True)
debug.swipe_right()
TT_CATEGORY = category # type: ignore
# Category changed, reset coordinates
TT_COORDS_PREV = (0, 0) # type: ignore
@ -125,7 +125,7 @@ def press_char(debug: "DebugLink", char: str) -> None:
time.sleep(1.1)
TT_COORDS_PREV = coords # type: ignore
for _ in range(amount):
debug.click(coords, wait=True)
debug.click(coords)
def input_passphrase(debug: "DebugLink", passphrase: str, check: bool = True) -> None:
@ -142,13 +142,13 @@ def input_passphrase(debug: "DebugLink", passphrase: str, check: bool = True) ->
def enter_passphrase(debug: "DebugLink") -> None:
"""Enter a passphrase"""
coords = buttons.pin_passphrase_grid(11)
debug.click(coords, wait=True)
debug.click(coords)
def delete_char(debug: "DebugLink") -> None:
"""Deletes the last char"""
coords = buttons.pin_passphrase_grid(9)
debug.click(coords, wait=True)
debug.click(coords)
VECTORS = ( # passphrase, address
@ -185,7 +185,6 @@ def test_passphrase_delete(device_handler: "BackgroundDeviceHandler"):
for _ in range(4):
delete_char(debug)
debug.wait_layout()
input_passphrase(debug, CommonPass.SHORT[8 - 4 :])
enter_passphrase(debug)
@ -215,7 +214,6 @@ def test_passphrase_loop_all_characters(device_handler: "BackgroundDeviceHandler
PassphraseCategory.SPECIAL,
):
go_to_category(debug, category)
debug.wait_layout()
enter_passphrase(debug)
coords = buttons.pin_passphrase_grid(11)

View File

@ -103,38 +103,36 @@ def prepare(
# Set new PIN
device_handler.run(device.change_pin) # type: ignore
TR.assert_in_multiple(
debug.wait_layout().text_content(), ["pin__turn_on", "pin__info"]
debug.read_layout().text_content(), ["pin__turn_on", "pin__info"]
)
if debug.model in (models.T2T1, models.T3T1):
go_next(debug)
elif debug.model in (models.T2B1,):
go_next(debug, wait=True)
go_next(debug, wait=True)
go_next(debug, wait=True)
go_next(debug, wait=True)
go_next(debug)
go_next(debug)
go_next(debug)
go_next(debug)
elif situation == Situation.PIN_CHANGE:
# Change PIN
device_handler.run(device.change_pin) # type: ignore
_input_see_confirm(debug, old_pin)
TR.assert_in(debug.wait_layout().text_content(), "pin__change")
go_next(debug, wait=True)
TR.assert_in(debug.read_layout().text_content(), "pin__change")
go_next(debug)
_input_see_confirm(debug, old_pin)
elif situation == Situation.WIPE_CODE_SETUP:
# Set wipe code
device_handler.run(device.change_wipe_code) # type: ignore
if old_pin:
_input_see_confirm(debug, old_pin)
TR.assert_in(debug.wait_layout().text_content(), "wipe_code__turn_on")
go_next(debug, wait=True)
TR.assert_in(debug.read_layout().text_content(), "wipe_code__turn_on")
go_next(debug)
if debug.model in (models.T2B1,):
go_next(debug, wait=True)
go_next(debug, wait=True)
go_next(debug, wait=True)
go_next(debug)
go_next(debug)
go_next(debug)
if old_pin:
debug.wait_layout()
_input_see_confirm(debug, old_pin)
debug.wait_layout()
_assert_pin_entry(debug)
yield debug
@ -161,7 +159,7 @@ def _input_pin(debug: "DebugLink", pin: str, check: bool = False) -> None:
for digit in pin:
digit_index = digits_order.index(digit)
coords = buttons.pin_passphrase_index(digit_index)
debug.click(coords, wait=True)
debug.click(coords)
elif debug.model in (models.T2B1,):
for digit in pin:
navigate_to_action_and_press(debug, digit, TR_PIN_ACTIONS)
@ -174,7 +172,7 @@ def _input_pin(debug: "DebugLink", pin: str, check: bool = False) -> None:
def _see_pin(debug: "DebugLink") -> None:
"""Navigate to "SHOW" and press it"""
if debug.model in (models.T2T1, models.T3T1):
debug.click(buttons.TOP_ROW, wait=True)
debug.click(buttons.TOP_ROW)
elif debug.model in (models.T2B1,):
navigate_to_action_and_press(debug, SHOW, TR_PIN_ACTIONS)
@ -186,7 +184,7 @@ def _delete_pin(debug: "DebugLink", digits_to_delete: int, check: bool = True) -
for _ in range(digits_to_delete):
if debug.model in (models.T2T1, models.T3T1):
debug.click(buttons.pin_passphrase_grid(9), wait=True)
debug.click(buttons.pin_passphrase_grid(9))
elif debug.model in (models.T2B1,):
navigate_to_action_and_press(debug, DELETE, TR_PIN_ACTIONS)
@ -198,7 +196,7 @@ def _delete_pin(debug: "DebugLink", digits_to_delete: int, check: bool = True) -
def _delete_all(debug: "DebugLink", check: bool = True) -> None:
"""Navigate to "DELETE" and hold it until all digits are deleted"""
if debug.model in (models.T2T1, models.T3T1):
debug.click_hold(buttons.pin_passphrase_grid(9), hold_ms=1500)
debug.click(buttons.pin_passphrase_grid(9), hold_ms=1500)
elif debug.model in (models.T2B1,):
navigate_to_action_and_press(debug, DELETE, TR_PIN_ACTIONS, hold_ms=1000)
@ -217,7 +215,7 @@ def _cancel_pin(debug: "DebugLink") -> None:
def _confirm_pin(debug: "DebugLink") -> None:
"""Navigate to "ENTER" and press it"""
if debug.model in (models.T2T1, models.T3T1):
debug.click(buttons.pin_passphrase_grid(11), wait=True)
debug.click(buttons.pin_passphrase_grid(11))
elif debug.model in (models.T2B1,):
navigate_to_action_and_press(debug, ENTER, TR_PIN_ACTIONS)
@ -233,7 +231,7 @@ def _enter_two_times(debug: "DebugLink", pin1: str, pin2: str) -> None:
if debug.model in (models.T2B1,):
# Please re-enter
go_next(debug, wait=True)
go_next(debug)
_input_see_confirm(debug, pin2)
@ -360,7 +358,7 @@ def test_wipe_code_same_as_pin(device_handler: "BackgroundDeviceHandler"):
with prepare(device_handler, Situation.WIPE_CODE_SETUP, old_pin="1") as debug:
_input_see_confirm(debug, "1")
# Try again
go_next(debug, wait=True)
go_next(debug)
_enter_two_times(debug, "2", "2")

View File

@ -139,7 +139,7 @@ def test_repeated_backup(
# ... so let's try to do a 2-of-3 backup
debug.wait_layout()
debug.read_layout()
# confirm backup intro
reset.confirm_read(debug)

View File

@ -51,12 +51,12 @@ def prepare_tutorial_and_cancel_after_it(
def go_through_tutorial(debug: "DebugLink") -> None:
debug.press_right(wait=True)
debug.press_right(wait=True)
debug.press_right_htc(hold_ms=1000)
debug.press_right(wait=True)
debug.press_right(wait=True)
layout = debug.press_middle(wait=True)
debug.press_right()
debug.press_right()
debug.press_right(hold_ms=1000)
debug.press_right()
debug.press_right()
layout = debug.press_middle()
TR.assert_equals(layout.title(), "tutorial__title_tutorial_complete")
@ -67,15 +67,15 @@ def test_tutorial_finish(device_handler: "BackgroundDeviceHandler"):
go_through_tutorial(debug)
# FINISH
debug.press_right(wait=True)
debug.press_right()
@pytest.mark.setup_client(uninitialized=True)
def test_tutorial_skip(device_handler: "BackgroundDeviceHandler"):
with prepare_tutorial_and_cancel_after_it(device_handler, cancelled=True) as debug:
# SKIP
debug.press_left(wait=True)
debug.press_right(wait=True)
debug.press_left()
debug.press_right()
@pytest.mark.setup_client(uninitialized=True)
@ -85,8 +85,8 @@ def test_tutorial_again_and_skip(device_handler: "BackgroundDeviceHandler"):
go_through_tutorial(debug)
# AGAIN
debug.press_left(wait=True)
debug.press_left()
# SKIP
debug.press_left(wait=True)
debug.press_right(wait=True)
debug.press_left()
debug.press_right()

View File

@ -14,6 +14,8 @@
# You should have received a copy of the License along with this library.
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
from __future__ import annotations
import json
import re
import time
@ -219,10 +221,8 @@ def read_mnemonic_from_screen_tt(
br = yield
assert br.pages is not None
debug.wait_layout()
for i in range(br.pages):
words = debug.wait_layout().seed_words()
words = debug.read_layout().seed_words()
mnemonic.extend(words)
# Not swiping on the last page
if i < br.pages - 1:
@ -241,7 +241,7 @@ def read_mnemonic_from_screen_tr(
br = yield
assert br.pages is not None
for _ in range(br.pages - 1):
layout = debug.wait_layout()
layout = debug.read_layout()
words = layout.seed_words()
mnemonic.extend(words)
debug.press_right()
@ -259,15 +259,15 @@ def read_mnemonic_from_screen_mercury(
br = yield
assert br.pages is not None
debug.wait_layout()
debug.read_layout()
debug.swipe_up()
for _ in range(br.pages - 2):
words = debug.wait_layout().seed_words()
words = debug.read_layout().seed_words()
mnemonic.extend(words)
debug.swipe_up()
debug.wait_layout()
debug.read_layout()
debug.press_yes()
return mnemonic
@ -285,13 +285,13 @@ def check_share(
if debug.model is models.T2T1:
# T2T1 has position as the first number in the text
word_pos_match = re.search(
re_num_of_word, debug.wait_layout().text_content()
re_num_of_word, debug.read_layout().text_content()
)
elif debug.model is models.T2B1:
# other models have the instruction in the title/subtitle
word_pos_match = re.search(re_num_of_word, debug.wait_layout().title())
word_pos_match = re.search(re_num_of_word, debug.read_layout().title())
elif debug.model is models.T3T1:
word_pos_match = re.search(re_num_of_word, debug.wait_layout().subtitle())
word_pos_match = re.search(re_num_of_word, debug.read_layout().subtitle())
else:
word_pos_match = None
@ -311,8 +311,8 @@ def check_share(
def click_info_button_tt(debug: "DebugLink"):
"""Click Shamir backup info button and return back."""
debug.press_info()
yield # Info screen with text
debug.press_yes()
yield
def click_info_button_mercury(debug: "DebugLink"):
@ -349,12 +349,12 @@ def compact_size(n: int) -> bytes:
def get_text_possible_pagination(debug: "DebugLink", br: messages.ButtonRequest) -> str:
text = debug.wait_layout().text_content()
text = debug.read_layout().text_content()
if br.pages is not None:
for _ in range(br.pages - 1):
debug.swipe_up()
text += " "
text += debug.wait_layout().text_content()
text += debug.read_layout().text_content()
return text

View File

@ -49,6 +49,11 @@ if TYPE_CHECKING:
HERE = Path(__file__).resolve().parent
CORE = HERE.parent / "core"
# So that we see details of failed asserts from this module
pytest.register_assert_rewrite("tests.common")
pytest.register_assert_rewrite("tests.input_flows")
pytest.register_assert_rewrite("tests.input_flows_helpers")
def _emulator_wrapper_main_args() -> list[str]:
"""Look at TREZOR_PROFILING env variable, so that we can generate coverage reports."""

View File

@ -32,7 +32,7 @@ pytestmark = [
def show_details_input_flow(client: Client):
yield
client.debug.wait_layout()
client.debug.read_layout()
# Touch screen click vs pressing right for T2B1
if client.model in (models.T2T1, models.T3T1):
SHOW_ALL_BUTTON_POSITION = (143, 167)

View File

@ -63,17 +63,23 @@ def test_busy_state(client: Client):
@pytest.mark.flaky(max_runs=5)
def test_busy_expiry(client: Client):
WAIT_TIME_MS = 1500
TOLERANCE = 1000
_assert_busy(client, False)
# Start a timer
start = time.monotonic()
# Show the busy dialog.
device.set_busy(client, expiry_ms=1500)
device.set_busy(client, expiry_ms=WAIT_TIME_MS)
_assert_busy(client, True)
# Hasn't expired yet.
time.sleep(0.1)
_assert_busy(client, True)
# Wait until the layout changes
client.debug.wait_layout()
end = time.monotonic()
# Wait for it to expire. Add some tolerance to account for CI/hardware slowness.
time.sleep(4.0)
# Check that the busy dialog was shown for at least WAIT_TIME_MS.
duration = (end - start) * 1000
assert WAIT_TIME_MS <= duration <= WAIT_TIME_MS + TOLERANCE
# Check that the device is no longer busy.
# Also needs to come back to Homescreen (for UI tests).

View File

@ -68,7 +68,7 @@ def client(client: Client) -> Iterator[Client]:
def _check_ping_screen_texts(client: Client, title: str, right_button: str) -> None:
def ping_input_flow(client: Client, title: str, right_button: str):
yield
layout = client.debug.wait_layout()
layout = client.debug.read_layout()
assert layout.title().upper() == title.upper()
assert layout.button_contents()[-1].upper() == right_button.upper()
client.debug.press_yes()

View File

@ -162,7 +162,8 @@ def test_repeated_backup_cancel(client: Client):
)
assert client.features.recovery_status == messages.RecoveryStatus.Backup
client.debug.wait_layout()
layout = client.debug.read_layout()
TR.assert_in(layout.text_content(), "recovery__unlock_repeated_backup")
# send a Cancel message
@ -218,7 +219,8 @@ def test_repeated_backup_send_disallowed_message(client: Client):
)
assert client.features.recovery_status == messages.RecoveryStatus.Backup
client.debug.wait_layout()
layout = client.debug.read_layout()
TR.assert_in(layout.text_content(), "recovery__unlock_repeated_backup")
# send a GetAddress message

View File

@ -51,7 +51,7 @@ def test_sd_no_format(client: Client):
@pytest.mark.sd_card
@pytest.mark.setup_client(pin="1234")
def test_sd_protect_unlock(client: Client):
layout = client.debug.wait_layout
layout = client.debug.read_layout
def input_flow_enable_sd_protect():
yield # Enter PIN to unlock device

View File

@ -398,7 +398,7 @@ def test_hide_passphrase_from_host(client: Client):
def input_flow():
yield
content = client.debug.wait_layout().text_content().lower()
content = client.debug.read_layout().text_content().lower()
assert any(
(s[:50].lower() in content)
for s in TR.translate("passphrase__from_host_not_shown")
@ -437,17 +437,17 @@ def test_hide_passphrase_from_host(client: Client):
def input_flow():
yield
TR.assert_in(
client.debug.wait_layout().text_content(),
client.debug.read_layout().text_content(),
"passphrase__next_screen_will_show_passphrase",
)
client.debug.press_yes()
yield
TR.assert_equals(
client.debug.wait_layout().title(),
client.debug.read_layout().title(),
"passphrase__title_confirm",
)
assert passphrase in client.debug.wait_layout().text_content()
assert passphrase in client.debug.read_layout().text_content()
client.debug.press_yes()
client.watch_layout()

View File

@ -76,16 +76,16 @@ class InputFlowBase:
raise NotImplementedError
def text_content(self) -> str:
return self.debug.wait_layout().text_content()
return self.debug.read_layout().text_content()
def main_component(self) -> str:
return self.debug.wait_layout().main_component()
return self.debug.read_layout().main_component()
def all_components(self) -> list[str]:
return self.debug.wait_layout().all_components()
return self.debug.read_layout().all_components()
def title(self) -> str:
return self.debug.wait_layout().title()
return self.debug.read_layout().title()
class InputFlowSetupDevicePINWIpeCode(InputFlowBase):
@ -216,13 +216,13 @@ class InputFlowSignMessagePagination(InputFlowBase):
layouts: list[LayoutContent] = []
br = yield # confirm address
self.debug.wait_layout()
self.debug.read_layout()
self.debug.press_yes()
br = yield
assert br.pages is not None
for i in range(br.pages):
layout = self.debug.wait_layout()
layout = self.debug.read_layout()
layouts.append(layout)
if i < br.pages - 1:
@ -260,13 +260,13 @@ class InputFlowSignMessagePagination(InputFlowBase):
layouts: list[LayoutContent] = []
br = yield # confirm address
self.debug.wait_layout()
self.debug.read_layout()
self.debug.press_yes()
br = yield
# assert br.pages is not None
for i in range(br.pages or 1):
layout = self.debug.wait_layout()
layout = self.debug.read_layout()
layouts.append(layout)
if br.pages and i < br.pages - 1:
@ -284,9 +284,9 @@ class InputFlowSignMessageInfo(InputFlowBase):
def input_flow_tt(self) -> BRGeneratorType:
yield
# show address/message info
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.press_no(wait=True)
self.debug.click(buttons.CORNER_BUTTON)
self.debug.click(buttons.CORNER_BUTTON)
self.debug.press_no()
self.debug.synchronize_at("IconDialog")
# address mismatch?
self.debug.press_no()
@ -295,15 +295,15 @@ class InputFlowSignMessageInfo(InputFlowBase):
yield
self.debug.press_no()
yield
self.debug.press_no(wait=True)
self.debug.press_yes(wait=True)
self.debug.press_no()
self.debug.press_yes()
def input_flow_t3t1(self) -> BRGeneratorType:
yield
# show address/message info
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.press_no(wait=True)
self.debug.click(buttons.CORNER_BUTTON)
self.debug.click(buttons.CORNER_BUTTON)
self.debug.press_no()
self.debug.synchronize_at("IconDialog")
# address mismatch?
self.debug.press_no()
@ -312,8 +312,8 @@ class InputFlowSignMessageInfo(InputFlowBase):
yield
self.debug.press_no()
yield
self.debug.press_no(wait=True)
self.debug.press_yes(wait=True)
self.debug.press_no()
self.debug.press_yes()
class InputFlowShowAddressQRCode(InputFlowBase):
@ -322,16 +322,16 @@ class InputFlowShowAddressQRCode(InputFlowBase):
def input_flow_tt(self) -> BRGeneratorType:
yield
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.click(buttons.CORNER_BUTTON)
# synchronize; TODO get rid of this once we have single-global-layout
self.debug.synchronize_at("SimplePage")
self.debug.swipe_left(wait=True)
self.debug.swipe_right(wait=True)
self.debug.swipe_left(wait=True)
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.press_no(wait=True)
self.debug.press_no(wait=True)
self.debug.swipe_left()
self.debug.swipe_right()
self.debug.swipe_left()
self.debug.click(buttons.CORNER_BUTTON)
self.debug.press_no()
self.debug.press_no()
self.debug.press_yes()
def input_flow_tr(self) -> BRGeneratorType:
@ -357,29 +357,29 @@ class InputFlowShowAddressQRCode(InputFlowBase):
def input_flow_t3t1(self) -> BRGeneratorType:
yield
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.click(buttons.CORNER_BUTTON)
# synchronize; TODO get rid of this once we have single-global-layout
self.debug.synchronize_at("VerticalMenu")
# menu
self.debug.click(buttons.VERTICAL_MENU[0], wait=True)
self.debug.click(buttons.VERTICAL_MENU[0])
self.debug.synchronize_at("Qr")
# qr code
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.click(buttons.CORNER_BUTTON)
# menu
self.debug.click(buttons.VERTICAL_MENU[1], wait=True)
self.debug.click(buttons.VERTICAL_MENU[1])
# address details
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.click(buttons.CORNER_BUTTON)
# menu
self.debug.click(buttons.VERTICAL_MENU[2], wait=True)
self.debug.click(buttons.VERTICAL_MENU[2])
# cancel
self.debug.swipe_up(wait=True)
self.debug.swipe_up()
# really cancel
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.click(buttons.CORNER_BUTTON)
# menu
layout = self.debug.click(buttons.CORNER_BUTTON, wait=True)
layout = self.debug.click(buttons.CORNER_BUTTON)
while "PromptScreen" not in layout.all_components():
layout = self.debug.swipe_up(wait=True)
layout = self.debug.swipe_up()
self.debug.synchronize_at("PromptScreen")
# tap to confirm
self.debug.click(buttons.TAP_TO_CONFIRM)
@ -391,13 +391,13 @@ class InputFlowShowAddressQRCodeCancel(InputFlowBase):
def input_flow_tt(self) -> BRGeneratorType:
yield
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.click(buttons.CORNER_BUTTON)
# synchronize; TODO get rid of this once we have single-global-layout
self.debug.synchronize_at("SimplePage")
self.debug.swipe_left(wait=True)
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.press_no(wait=True)
self.debug.swipe_left()
self.debug.click(buttons.CORNER_BUTTON)
self.debug.press_no()
self.debug.press_yes()
def input_flow_tr(self) -> BRGeneratorType:
@ -409,7 +409,7 @@ class InputFlowShowAddressQRCodeCancel(InputFlowBase):
self.debug.press_left()
self.debug.press_left()
# Cancel
self.debug.press_left(wait=True)
self.debug.press_left()
# Confirm address mismatch
# Clicking right twice, as some languages can have two pages
self.debug.press_right()
@ -417,25 +417,25 @@ class InputFlowShowAddressQRCodeCancel(InputFlowBase):
def input_flow_t3t1(self) -> BRGeneratorType:
yield
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.click(buttons.CORNER_BUTTON)
# synchronize; TODO get rid of this once we have single-global-layout
self.debug.synchronize_at("VerticalMenu")
# menu
self.debug.click(buttons.VERTICAL_MENU[0], wait=True)
self.debug.click(buttons.VERTICAL_MENU[0])
self.debug.synchronize_at("Qr")
# qr code
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.click(buttons.CORNER_BUTTON)
# menu
self.debug.click(buttons.VERTICAL_MENU[1], wait=True)
self.debug.click(buttons.VERTICAL_MENU[1])
# address details
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.click(buttons.CORNER_BUTTON)
# menu
self.debug.click(buttons.VERTICAL_MENU[2], wait=True)
self.debug.click(buttons.VERTICAL_MENU[2])
# cancel
self.debug.swipe_up(wait=True)
self.debug.swipe_up()
self.debug.synchronize_at("PromptScreen")
# really cancel
self.debug.click(buttons.TAP_TO_CONFIRM, wait=True)
self.debug.click(buttons.TAP_TO_CONFIRM)
class InputFlowShowMultisigXPUBs(InputFlowBase):
@ -450,7 +450,7 @@ class InputFlowShowMultisigXPUBs(InputFlowBase):
self.debug.press_yes()
yield # show address
layout = self.debug.wait_layout()
layout = self.debug.read_layout()
TR.assert_in(layout.title(), "address__title_receive_address")
assert "(MULTISIG)" in layout.title()
assert layout.text_content().replace(" ", "") == self.address
@ -458,24 +458,26 @@ class InputFlowShowMultisigXPUBs(InputFlowBase):
self.debug.click(buttons.CORNER_BUTTON)
assert "Qr" in self.all_components()
layout = self.debug.swipe_left(wait=True)
layout = self.debug.swipe_left()
# address details
assert "Multisig 2 of 3" in layout.screen_content()
TR.assert_in(layout.screen_content(), "address_details__derivation_path_colon")
# Three xpub pages with the same testing logic
for xpub_num in range(3):
expected_title = f"MULTISIG XPUB #{xpub_num + 1}"
layout = self.debug.swipe_left(wait=True)
assert expected_title in layout.title()
expected_title = f"MULTISIG XPUB #{xpub_num + 1}\n" + (
"(YOURS)" if self.index == xpub_num else "(COSIGNER)"
)
layout = self.debug.swipe_left()
assert expected_title == layout.title()
content = layout.text_content().replace(" ", "")
assert self.xpubs[xpub_num] in content
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.click(buttons.CORNER_BUTTON)
# show address
self.debug.press_no(wait=True)
self.debug.press_no()
# address mismatch
self.debug.press_no(wait=True)
self.debug.press_no()
# show address
self.debug.press_yes()
@ -484,7 +486,7 @@ class InputFlowShowMultisigXPUBs(InputFlowBase):
self.debug.press_middle()
yield # show address
layout = self.debug.wait_layout()
layout = self.debug.read_layout()
TR.assert_in(layout.title(), "address__title_receive_address")
assert "(MULTISIG)" in layout.title()
assert layout.text_content().replace(" ", "") == self.address
@ -492,22 +494,24 @@ class InputFlowShowMultisigXPUBs(InputFlowBase):
self.debug.press_right()
assert "Qr" in self.all_components()
layout = self.debug.press_right(wait=True)
layout = self.debug.press_right()
# address details
# TODO: locate it more precisely
assert "Multisig 2 of 3" in layout.json_str
# Three xpub pages with the same testing logic
for xpub_num in range(3):
expected_title = f"MULTISIG XPUB #{xpub_num + 1}"
layout = self.debug.press_right(wait=True)
expected_title = f"MULTISIG XPUB #{xpub_num + 1} " + (
"(YOURS)" if self.index == xpub_num else "(COSIGNER)"
)
layout = self.debug.press_right()
assert expected_title in layout.title()
xpub_part_1 = layout.text_content().replace(" ", "")
# Press "SHOW MORE"
layout = self.debug.press_middle(wait=True)
layout = self.debug.press_middle()
xpub_part_2 = layout.text_content().replace(" ", "")
# Go back
self.debug.press_left(wait=True)
self.debug.press_left()
assert self.xpubs[xpub_num] == xpub_part_1 + xpub_part_2
for _ in range(5):
@ -521,26 +525,26 @@ class InputFlowShowMultisigXPUBs(InputFlowBase):
def input_flow_t3t1(self) -> BRGeneratorType:
yield # multisig address warning
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.click(buttons.CORNER_BUTTON)
self.debug.synchronize_at("VerticalMenu")
self.debug.click(buttons.VERTICAL_MENU[1])
yield # show address
layout = self.debug.wait_layout()
layout = self.debug.read_layout()
TR.assert_in(layout.title(), "address__title_receive_address")
assert layout.text_content().replace(" ", "") == self.address
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.click(buttons.CORNER_BUTTON)
assert "VerticalMenu" in self.all_components()
# menu
self.debug.click(buttons.VERTICAL_MENU[0], wait=True)
self.debug.click(buttons.VERTICAL_MENU[0])
self.debug.synchronize_at("Qr")
# qr code
assert "Qr" in self.all_components()
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.click(buttons.CORNER_BUTTON)
# menu
assert "VerticalMenu" in self.all_components()
self.debug.click(buttons.VERTICAL_MENU[1], wait=True)
self.debug.click(buttons.VERTICAL_MENU[1])
layout = self.debug.synchronize_at("AddressDetails")
# address details
assert "Multisig 2 of 3" in layout.screen_content()
@ -548,24 +552,24 @@ class InputFlowShowMultisigXPUBs(InputFlowBase):
# three xpub pages with the same testing logic
for _xpub_num in range(3):
layout = self.debug.swipe_left(wait=True)
layout = self.debug.swipe_left(wait=True)
layout = self.debug.swipe_left()
layout = self.debug.swipe_left()
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.click(buttons.CORNER_BUTTON)
layout = self.debug.synchronize_at("VerticalMenu")
# menu
self.debug.click(buttons.VERTICAL_MENU[2], wait=True)
self.debug.click(buttons.VERTICAL_MENU[2])
# cancel
self.debug.swipe_up(wait=True)
self.debug.swipe_up()
# really cancel
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.click(buttons.CORNER_BUTTON)
layout = self.debug.synchronize_at("VerticalMenu")
# menu
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.click(buttons.CORNER_BUTTON)
layout = self.debug.synchronize_at("Paragraphs")
# address
while "PromptScreen" not in layout.all_components():
layout = self.debug.swipe_up(wait=True)
layout = self.debug.swipe_up()
self.debug.synchronize_at("PromptScreen")
# tap to confirm
self.debug.press_yes()
@ -584,23 +588,23 @@ class InputFlowShowXpubQRCode(InputFlowBase):
self.debug.press_yes()
br = yield
layout = self.debug.wait_layout()
layout = self.debug.read_layout()
if "coinjoin" in layout.title().lower() or br.code == B.UnknownDerivationPath:
self.debug.press_yes()
br = yield
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.click(buttons.CORNER_BUTTON)
# synchronize; TODO get rid of this once we have single-global-layout
self.debug.synchronize_at("SimplePage")
self.debug.swipe_left(wait=True)
self.debug.swipe_right(wait=True)
self.debug.swipe_left(wait=True)
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.press_no(wait=True)
self.debug.press_no(wait=True)
self.debug.swipe_left()
self.debug.swipe_right()
self.debug.swipe_left()
self.debug.click(buttons.CORNER_BUTTON)
self.debug.press_no()
self.debug.press_no()
for _ in range(br.pages - 1):
self.debug.swipe_up(wait=True)
self.debug.swipe_up()
self.debug.press_yes()
def input_flow_tr(self) -> BRGeneratorType:
@ -611,19 +615,19 @@ class InputFlowShowXpubQRCode(InputFlowBase):
self.debug.press_right()
br = yield
layout = self.debug.wait_layout()
layout = self.debug.read_layout()
if "coinjoin" in layout.title().lower() or br.code == B.UnknownDerivationPath:
self.debug.press_yes()
br = yield
# Go into details
self.debug.press_right(wait=True)
self.debug.press_right()
# Go through details and back
self.debug.press_right(wait=True)
self.debug.press_right(wait=True)
self.debug.press_right(wait=True)
self.debug.press_left(wait=True)
self.debug.press_left(wait=True)
self.debug.press_right()
self.debug.press_right()
self.debug.press_right()
self.debug.press_left()
self.debug.press_left()
assert br.pages is not None
for _ in range(br.pages - 1):
self.debug.press_right()
@ -638,44 +642,44 @@ class InputFlowShowXpubQRCode(InputFlowBase):
self.debug.press_yes()
br = yield
layout = self.debug.wait_layout()
layout = self.debug.read_layout()
if "coinjoin" in layout.title().lower() or br.code == B.UnknownDerivationPath:
self.debug.press_yes()
br = yield
layout = self.debug.wait_layout()
layout = self.debug.read_layout()
assert layout.title() in TR.translate("address__public_key") + ["XPUB"]
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.click(buttons.CORNER_BUTTON)
assert "VerticalMenu" in self.all_components()
# menu
self.debug.click(buttons.VERTICAL_MENU[0], wait=True)
self.debug.click(buttons.VERTICAL_MENU[0])
self.debug.synchronize_at("Qr")
# qr code
assert "Qr" in self.all_components()
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.click(buttons.CORNER_BUTTON)
# menu
assert "VerticalMenu" in self.all_components()
self.debug.click(buttons.VERTICAL_MENU[1], wait=True)
self.debug.click(buttons.VERTICAL_MENU[1])
layout = self.debug.synchronize_at("AddressDetails")
# address details
TR.assert_in(layout.screen_content(), "address_details__derivation_path")
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.click(buttons.CORNER_BUTTON)
layout = self.debug.synchronize_at("VerticalMenu")
# menu
self.debug.click(buttons.VERTICAL_MENU[2], wait=True)
self.debug.click(buttons.VERTICAL_MENU[2])
# cancel
self.debug.swipe_up(wait=True)
self.debug.swipe_up()
# really cancel
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.click(buttons.CORNER_BUTTON)
layout = self.debug.synchronize_at("VerticalMenu")
# menu
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.click(buttons.CORNER_BUTTON)
layout = self.debug.synchronize_at("Paragraphs")
# address
while "PromptScreen" not in layout.all_components():
layout = self.debug.swipe_up(wait=True)
layout = self.debug.swipe_up()
self.debug.synchronize_at("PromptScreen")
# tap to confirm
self.debug.press_yes()
@ -688,21 +692,21 @@ class InputFlowPaymentRequestDetails(InputFlowBase):
def input_flow_tt(self) -> BRGeneratorType:
yield # request to see details
self.debug.wait_layout()
self.debug.read_layout()
self.debug.press_info()
yield # confirm first output
assert self.outputs[0].address[:16] in self.text_content() # type: ignore
self.debug.press_yes()
yield # confirm first output
self.debug.wait_layout()
self.debug.read_layout()
self.debug.press_yes()
yield # confirm second output
assert self.outputs[1].address[:16] in self.text_content() # type: ignore
self.debug.press_yes()
yield # confirm second output
self.debug.wait_layout()
self.debug.read_layout()
self.debug.press_yes()
yield # confirm transaction
@ -712,21 +716,21 @@ class InputFlowPaymentRequestDetails(InputFlowBase):
def input_flow_t3t1(self) -> BRGeneratorType:
yield # request to see details
self.debug.wait_layout()
self.debug.read_layout()
self.debug.press_info()
yield # confirm first output
assert self.outputs[0].address[:16] in self.text_content() # type: ignore
self.debug.swipe_up()
yield # confirm first output
self.debug.wait_layout()
self.debug.read_layout()
self.debug.swipe_up()
yield # confirm second output
assert self.outputs[1].address[:16] in self.text_content() # type: ignore
self.debug.swipe_up()
yield # confirm second output
self.debug.wait_layout()
self.debug.read_layout()
self.debug.swipe_up()
yield # confirm transaction
@ -784,20 +788,20 @@ class InputFlowSignTxHighFee(InputFlowBase):
def sign_tx_go_to_info(client: Client) -> Generator[None, None, str]:
yield # confirm output
client.debug.wait_layout()
client.debug.read_layout()
client.debug.press_yes()
yield # confirm output
client.debug.wait_layout()
client.debug.read_layout()
client.debug.press_yes()
yield # confirm transaction
client.debug.wait_layout()
client.debug.read_layout()
client.debug.press_info()
layout = client.debug.wait_layout()
layout = client.debug.read_layout()
content = layout.text_content()
client.debug.click(buttons.CORNER_BUTTON, wait=True)
client.debug.click(buttons.CORNER_BUTTON)
return content
@ -806,35 +810,72 @@ def sign_tx_go_to_info_t3t1(
client: Client, multi_account: bool = False
) -> Generator[None, None, str]:
yield # confirm output
client.debug.wait_layout()
client.debug.read_layout()
client.debug.swipe_up()
yield # confirm output
client.debug.wait_layout()
client.debug.read_layout()
client.debug.swipe_up()
if multi_account:
yield
client.debug.wait_layout()
client.debug.read_layout()
client.debug.swipe_up()
yield # confirm transaction
client.debug.wait_layout()
client.debug.read_layout()
client.debug.click(buttons.CORNER_BUTTON)
client.debug.synchronize_at("VerticalMenu")
client.debug.click(buttons.VERTICAL_MENU[0])
layout = client.debug.wait_layout()
layout = client.debug.read_layout()
content = layout.text_content()
client.debug.click(buttons.CORNER_BUTTON)
client.debug.synchronize_at("VerticalMenu")
client.debug.click(buttons.VERTICAL_MENU[1])
layout = client.debug.wait_layout()
layout = client.debug.read_layout()
content += " " + layout.text_content()
client.debug.click(buttons.CORNER_BUTTON)
client.debug.click(buttons.CORNER_BUTTON, wait=True)
client.debug.click(buttons.CORNER_BUTTON)
return content
def sign_tx_go_to_info_t3t1(
client: Client, multi_account: bool = False
) -> Generator[None, None, str]:
yield # confirm output
client.debug.read_layout()
client.debug.swipe_up()
yield # confirm output
client.debug.read_layout()
client.debug.swipe_up()
if multi_account:
yield
client.debug.read_layout()
client.debug.swipe_up()
yield # confirm transaction
client.debug.read_layout()
client.debug.click(buttons.CORNER_BUTTON)
client.debug.synchronize_at("VerticalMenu")
client.debug.click(buttons.VERTICAL_MENU[0])
layout = client.debug.read_layout()
content = layout.text_content()
client.debug.click(buttons.CORNER_BUTTON)
client.debug.synchronize_at("VerticalMenu")
client.debug.click(buttons.VERTICAL_MENU[1])
layout = client.debug.read_layout()
content += " " + layout.text_content()
client.debug.click(buttons.CORNER_BUTTON)
client.debug.click(buttons.CORNER_BUTTON)
return content
@ -843,24 +884,24 @@ def sign_tx_go_to_info_tr(
client: Client,
) -> Generator[None, None, str]:
yield # confirm address
client.debug.wait_layout()
client.debug.read_layout()
client.debug.press_yes() # CONTINUE
yield # confirm amount
client.debug.wait_layout()
client.debug.read_layout()
client.debug.press_yes() # CONFIRM
screen_texts: list[str] = []
yield # confirm total
layout = client.debug.wait_layout()
layout = client.debug.read_layout()
if "multiple accounts" in layout.text_content().lower():
client.debug.press_middle()
yield
layout = client.debug.press_right(wait=True)
layout = client.debug.press_right()
screen_texts.append(layout.text_content())
layout = client.debug.press_right(wait=True)
layout = client.debug.press_right()
screen_texts.append(layout.text_content())
client.debug.press_left()
@ -962,15 +1003,16 @@ class InputFlowSignTxInformationReplacement(InputFlowBase):
yield # confirm address
self.debug.press_yes()
# go back to address
yield
self.debug.press_no()
# confirm address
self.debug.press_yes()
yield # confirm amount
# confirm amount
self.debug.press_yes()
yield # transaction summary, press info
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.click(buttons.CORNER_BUTTON)
self.debug.click(buttons.CORNER_BUTTON)
self.debug.press_yes()
def input_flow_tr(self) -> BRGeneratorType:
@ -1000,8 +1042,8 @@ class InputFlowSignTxInformationReplacement(InputFlowBase):
self.debug.press_yes()
yield # transaction summary, press info
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.click(buttons.CORNER_BUTTON)
self.debug.click(buttons.CORNER_BUTTON)
self.debug.press_yes()
@ -1011,10 +1053,10 @@ def lock_time_input_flow_tt(
double_confirm: bool = False,
) -> BRGeneratorType:
yield # confirm output
debug.wait_layout()
debug.read_layout()
debug.press_yes()
yield # confirm output
debug.wait_layout()
debug.read_layout()
debug.press_yes()
br = yield # confirm locktime
@ -1033,10 +1075,10 @@ def lock_time_input_flow_tr(
layout_assert_func: Callable[[DebugLink, messages.ButtonRequest], None],
) -> BRGeneratorType:
yield # confirm address
debug.wait_layout()
debug.read_layout()
debug.press_yes()
yield # confirm amount
debug.wait_layout()
debug.read_layout()
debug.press_yes()
br = yield # confirm locktime
@ -1053,10 +1095,10 @@ def lock_time_input_flow_t3t1(
double_confirm: bool = False,
) -> BRGeneratorType:
yield # confirm output
debug.wait_layout()
debug.read_layout()
debug.swipe_up()
yield # confirm output
debug.wait_layout()
debug.read_layout()
debug.swipe_up()
br = yield # confirm locktime
@ -1135,7 +1177,7 @@ class InputFlowEIP712ShowMore(InputFlowBase):
self.debug.press_yes()
yield # confirm domain
self.debug.wait_layout()
self.debug.read_layout()
self._confirm_show_more()
# confirm domain properties
@ -1144,11 +1186,11 @@ class InputFlowEIP712ShowMore(InputFlowBase):
self.debug.press_yes()
yield # confirm message
self.debug.wait_layout()
self.debug.read_layout()
self._confirm_show_more()
yield # confirm message.from
self.debug.wait_layout()
self.debug.read_layout()
self._confirm_show_more()
# confirm message.from properties
@ -1157,7 +1199,7 @@ class InputFlowEIP712ShowMore(InputFlowBase):
self.debug.press_yes()
yield # confirm message.to
self.debug.wait_layout()
self.debug.read_layout()
self._confirm_show_more()
# confirm message.to properties
@ -1428,21 +1470,16 @@ class InputFlowSlip39BasicBackup(InputFlowBase):
self.repeated = repeated
def input_flow_tt(self) -> BRGeneratorType:
if self.repeated:
# intro confirmation screen
yield
self.debug.press_yes()
yield # 1. Backup intro
self.debug.press_yes()
yield # 2. Checklist
yield # 1. Checklist
self.debug.press_yes()
yield # 2. Number of shares (5)
if self.click_info:
yield from click_info_button_tt(self.debug)
yield # 3. Number of shares (5)
self.debug.press_yes()
yield # 4. Checklist
self.debug.press_yes()
yield # 4. Threshold (3)
if self.click_info:
yield from click_info_button_tt(self.debug)
yield # 5. Threshold (3)
@ -1498,17 +1535,17 @@ class InputFlowSlip39BasicBackup(InputFlowBase):
self.debug.press_yes()
yield # 1. Backup intro
self.debug.wait_layout()
self.debug.read_layout()
self.debug.swipe_up()
yield # 2. Checklist
self.debug.wait_layout()
self.debug.swipe_up(wait=True)
self.debug.read_layout()
self.debug.swipe_up()
if self.click_info:
click_info_button_mercury(self.debug)
yield # 3. Number of shares (5)
self.debug.swipe_up()
yield # 4. Checklist
self.debug.swipe_up(wait=True)
self.debug.swipe_up()
if self.click_info:
click_info_button_mercury(self.debug)
yield # 5. Threshold (3)
@ -1705,12 +1742,14 @@ class InputFlowSlip39AdvancedBackup(InputFlowBase):
self.debug.press_yes()
yield # 2. Checklist
self.debug.press_yes()
yield # 2. Set and confirm group count
if self.click_info:
yield from click_info_button_tt(self.debug)
yield # 3. Set and confirm group count
self.debug.press_yes()
yield # 4. Checklist
self.debug.press_yes()
yield # 4. Set and confirm group threshold
if self.click_info:
yield from click_info_button_tt(self.debug)
yield # 5. Set and confirm group threshold
@ -1718,13 +1757,13 @@ class InputFlowSlip39AdvancedBackup(InputFlowBase):
yield # 6. Checklist
self.debug.press_yes()
for _ in range(5): # for each of 5 groups
if self.click_info:
yield from click_info_button_tt(self.debug)
yield # Set & Confirm number of shares
self.debug.press_yes()
if self.click_info:
yield from click_info_button_tt(self.debug)
self.debug.press_yes()
yield # Set & confirm share threshold value
if self.click_info:
yield from click_info_button_tt(self.debug)
self.debug.press_yes()
yield # Confirm show seeds
self.debug.press_yes()
@ -1770,31 +1809,31 @@ class InputFlowSlip39AdvancedBackup(InputFlowBase):
def input_flow_t3t1(self) -> BRGeneratorType:
yield # 1. Backup intro
self.debug.wait_layout()
self.debug.read_layout()
self.debug.swipe_up()
yield # 2. Checklist
self.debug.swipe_up(wait=True)
self.debug.swipe_up()
if self.click_info:
click_info_button_mercury(self.debug)
yield # 3. Set and confirm group count
self.debug.swipe_up()
yield # 4. Checklist
self.debug.swipe_up(wait=True)
self.debug.swipe_up()
if self.click_info:
click_info_button_mercury(self.debug)
yield # 5. Set and confirm group threshold
self.debug.swipe_up()
yield # 6. Checklist
self.debug.swipe_up(wait=True)
self.debug.swipe_up()
for _i in range(5): # for each of 5 groups
if self.click_info:
click_info_button_mercury(self.debug)
yield # Set & Confirm number of shares
self.debug.swipe_up(wait=True)
self.debug.swipe_up()
if self.click_info:
click_info_button_mercury(self.debug)
yield # Set & confirm share threshold value
self.debug.swipe_up(wait=_i != 4)
self.debug.swipe_up()
yield # Confirm show seeds
self.debug.press_yes()
@ -2272,7 +2311,7 @@ class InputFlowConfirmAllWarnings(InputFlowBase):
br = yield
while True:
# wait for homescreen to go away
self.debug.wait_layout()
self.debug.read_layout()
self.client.ui._default_input_flow(br)
br = yield
@ -2284,11 +2323,11 @@ class InputFlowConfirmAllWarnings(InputFlowBase):
while True:
# wait for homescreen to go away
# probably won't be needed after https://github.com/trezor/trezor-firmware/pull/3686
self.debug.wait_layout()
self.debug.read_layout()
# Paginating (going as further as possible) and pressing Yes
if br.pages is not None:
for _ in range(br.pages - 1):
self.debug.swipe_up(wait=True)
self.debug.swipe_up()
layout = self.debug.read_layout()
text = layout.text_content().lower()
# hi priority warning
@ -2302,7 +2341,7 @@ class InputFlowConfirmAllWarnings(InputFlowBase):
]
)
if any(needle.lower() in text for needle in hi_prio):
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.click(buttons.CORNER_BUTTON)
self.debug.synchronize_at("VerticalMenu")
self.debug.click(buttons.VERTICAL_MENU[1])
elif "PromptScreen" in layout.all_components():

View File

@ -17,16 +17,16 @@ class PinFlow:
self, pin: str, second_different_pin: str | None = None
) -> BRGeneratorType:
yield # Enter PIN
assert "PinKeyboard" in self.debug.wait_layout().all_components()
assert "PinKeyboard" in self.debug.read_layout().all_components()
self.debug.input(pin)
if self.client.model is models.T2B1:
yield # Reenter PIN
TR.assert_in(
self.debug.wait_layout().text_content(), "pin__reenter_to_confirm"
self.debug.read_layout().text_content(), "pin__reenter_to_confirm"
)
self.debug.press_yes()
yield # Enter PIN again
assert "PinKeyboard" in self.debug.wait_layout().all_components()
assert "PinKeyboard" in self.debug.read_layout().all_components()
if second_different_pin is not None:
self.debug.input(second_different_pin)
else:
@ -40,7 +40,7 @@ class BackupFlow:
def confirm_new_wallet(self) -> BRGeneratorType:
yield
TR.assert_in(self.debug.wait_layout().text_content(), "reset__by_continuing")
TR.assert_in(self.debug.read_layout().text_content(), "reset__by_continuing")
if self.client.model is models.T2B1:
self.debug.press_right()
self.debug.press_yes()
@ -52,7 +52,7 @@ class RecoveryFlow:
self.debug = self.client.debug
def _text_content(self) -> str:
layout = self.debug.wait_layout()
layout = self.debug.read_layout()
return layout.title() + " " + layout.text_content()
def confirm_recovery(self) -> BRGeneratorType:
@ -97,13 +97,13 @@ class RecoveryFlow:
else:
TR.assert_in(self._text_content(), "recovery__enter_backup")
is_dry_run = any(
title in self.debug.wait_layout().title().lower()
title in self.debug.read_layout().title().lower()
for title in TR.translate("recovery__title_dry_run", lower=True)
)
if self.client.model is models.T2B1 and not is_dry_run:
# Normal recovery has extra info (not dry run)
self.debug.press_right(wait=True)
self.debug.press_right(wait=True)
self.debug.press_right()
self.debug.press_right()
self.debug.press_yes()
def enter_any_share(self) -> BRGeneratorType:
@ -113,13 +113,13 @@ class RecoveryFlow:
["recovery__enter_any_share", "recovery__enter_each_word"],
)
is_dry_run = any(
title in self.debug.wait_layout().title().lower()
title in self.debug.read_layout().title().lower()
for title in TR.translate("recovery__title_dry_run", lower=True)
)
if self.client.model is models.T2B1 and not is_dry_run:
# Normal recovery has extra info (not dry run)
self.debug.press_right(wait=True)
self.debug.press_right(wait=True)
self.debug.press_right()
self.debug.press_right()
self.debug.press_yes()
def abort_recovery(self, confirm: bool) -> BRGeneratorType:
@ -187,7 +187,7 @@ class RecoveryFlow:
br = yield
assert br.code == B.MnemonicWordCount
if self.client.model is models.T2B1:
TR.assert_in(self.debug.wait_layout().title(), "word_count__title")
TR.assert_in(self.debug.read_layout().title(), "word_count__title")
else:
TR.assert_in(self._text_content(), "recovery__num_of_words")
self.debug.input(str(num_words))
@ -283,7 +283,7 @@ class RecoveryFlow:
def input_mnemonic(self, mnemonic: list[str]) -> BRGeneratorType:
br = yield
assert br.code == B.MnemonicInput
assert "MnemonicKeyboard" in self.debug.wait_layout().all_components()
assert "MnemonicKeyboard" in self.debug.read_layout().all_components()
for _, word in enumerate(mnemonic):
self.debug.input(word)
@ -311,8 +311,8 @@ class RecoveryFlow:
self,
) -> BRGeneratorType:
# Moving through the INFO button
self.debug.press_info()
yield
self.debug.press_info()
self.debug.swipe_up()
self.debug.press_yes()
@ -334,7 +334,7 @@ class EthereumFlow:
def confirm_data(self, info: bool = False, cancel: bool = False) -> BRGeneratorType:
yield
TR.assert_equals(
self.debug.wait_layout().title(), "ethereum__title_confirm_data"
self.debug.read_layout().title(), "ethereum__title_confirm_data"
)
if info:
self.debug.press_info()
@ -346,11 +346,11 @@ class EthereumFlow:
def paginate_data(self) -> BRGeneratorType:
br = yield
TR.assert_equals(
self.debug.wait_layout().title(), "ethereum__title_confirm_data"
self.debug.read_layout().title(), "ethereum__title_confirm_data"
)
assert br.pages is not None
for i in range(br.pages):
self.debug.wait_layout()
self.debug.read_layout()
if i < br.pages - 1:
self.debug.swipe_up()
self.debug.press_yes()
@ -358,13 +358,13 @@ class EthereumFlow:
def paginate_data_go_back(self) -> BRGeneratorType:
br = yield
TR.assert_equals(
self.debug.wait_layout().title(), "ethereum__title_confirm_data"
self.debug.read_layout().title(), "ethereum__title_confirm_data"
)
assert br.pages is not None
assert br.pages > 2
if self.client.model in (models.T2T1, models.T3T1):
self.debug.swipe_up(wait=True)
self.debug.swipe_up(wait=True)
self.debug.swipe_up()
self.debug.swipe_up()
self.debug.click(self.GO_BACK)
else:
self.debug.press_right()
@ -380,7 +380,7 @@ class EthereumFlow:
go_back_from_summary: bool = False,
) -> BRGeneratorType:
yield
TR.assert_equals(self.debug.wait_layout().title(), "words__recipient")
TR.assert_equals(self.debug.read_layout().title(), "words__recipient")
if self.client.model in (models.T2T1, models.T3T1):
if cancel:
@ -389,10 +389,10 @@ class EthereumFlow:
self.debug.press_yes()
yield
TR.assert_equals(
self.debug.wait_layout().title(), "words__title_summary"
self.debug.read_layout().title(), "words__title_summary"
)
TR.assert_in(
self.debug.wait_layout().text_content(), "send__maximum_fee"
self.debug.read_layout().text_content(), "send__maximum_fee"
)
if go_back_from_summary:
self.debug.press_no()
@ -400,14 +400,14 @@ class EthereumFlow:
self.debug.press_yes()
yield
if info:
self.debug.press_info(wait=True)
self.debug.press_info()
TR.assert_in(
self.debug.wait_layout().text_content(), "ethereum__gas_limit"
self.debug.read_layout().text_content(), "ethereum__gas_limit"
)
TR.assert_in(
self.debug.wait_layout().text_content(), "ethereum__gas_price"
self.debug.read_layout().text_content(), "ethereum__gas_price"
)
self.debug.press_no(wait=True)
self.debug.press_no()
self.debug.press_yes()
else:
if cancel:
@ -416,7 +416,7 @@ class EthereumFlow:
self.debug.press_right()
yield
TR.assert_in(
self.debug.wait_layout().text_content(), "send__maximum_fee"
self.debug.read_layout().text_content(), "send__maximum_fee"
)
if go_back_from_summary:
self.debug.press_left()
@ -424,16 +424,16 @@ class EthereumFlow:
self.debug.press_right()
yield
if info:
self.debug.press_right(wait=True)
self.debug.press_right()
TR.assert_in(
self.debug.wait_layout().text_content(), "ethereum__gas_limit"
self.debug.read_layout().text_content(), "ethereum__gas_limit"
)
self.debug.press_right(wait=True)
self.debug.press_right()
TR.assert_in(
self.debug.wait_layout().text_content(), "ethereum__gas_price"
self.debug.read_layout().text_content(), "ethereum__gas_price"
)
self.debug.press_left(wait=True)
self.debug.press_left(wait=True)
self.debug.press_left()
self.debug.press_left()
self.debug.press_middle()
def confirm_tx_staking(
@ -442,7 +442,7 @@ class EthereumFlow:
) -> BRGeneratorType:
yield
TR.assert_equals_multiple(
self.debug.wait_layout().title(),
self.debug.read_layout().title(),
[
"ethereum__staking_stake",
"ethereum__staking_unstake",
@ -450,7 +450,7 @@ class EthereumFlow:
],
)
TR.assert_equals_multiple(
self.debug.wait_layout().text_content(),
self.debug.read_layout().text_content(),
[
"ethereum__staking_stake_intro",
"ethereum__staking_unstake_intro",
@ -460,56 +460,56 @@ class EthereumFlow:
if self.client.model in (models.T2T1, models.T3T1):
# confirm intro
if info:
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.click(buttons.CORNER_BUTTON, )
TR.assert_equals_multiple(
self.debug.wait_layout().title(),
self.debug.read_layout().title(),
[
"ethereum__staking_stake_address",
"ethereum__staking_claim_address",
],
)
self.debug.press_no(wait=True)
self.debug.press_no()
self.debug.press_yes()
yield
# confirm summary
if info and self.client.model != models.T3T1:
self.debug.press_info(wait=True)
self.debug.press_info()
TR.assert_in(
self.debug.wait_layout().text_content(), "ethereum__gas_limit"
self.debug.read_layout().text_content(), "ethereum__gas_limit"
)
TR.assert_in(
self.debug.wait_layout().text_content(), "ethereum__gas_price"
self.debug.read_layout().text_content(), "ethereum__gas_price"
)
self.debug.press_no(wait=True)
self.debug.press_no()
self.debug.press_yes()
yield
else:
# confirm intro
if info:
self.debug.press_right(wait=True)
self.debug.press_right()
TR.assert_equals_multiple(
self.debug.wait_layout().title(),
self.debug.read_layout().title(),
[
"ethereum__staking_stake_address",
"ethereum__staking_claim_address",
],
)
self.debug.press_left(wait=True)
self.debug.press_left()
self.debug.press_middle()
yield
# confirm summary
if info:
self.debug.press_right(wait=True)
self.debug.press_right()
TR.assert_in(
self.debug.wait_layout().text_content(), "ethereum__gas_limit"
self.debug.read_layout().text_content(), "ethereum__gas_limit"
)
self.debug.press_right(wait=True)
self.debug.press_right()
TR.assert_in(
self.debug.wait_layout().text_content(), "ethereum__gas_price"
self.debug.read_layout().text_content(), "ethereum__gas_price"
)
self.debug.press_left(wait=True)
self.debug.press_left(wait=True)
self.debug.press_left()
self.debug.press_left()
self.debug.press_middle()
yield

View File

@ -48,9 +48,9 @@ def test_abort(core_emulator: Emulator):
device_handler.run(device.recover, pin_protection=False)
assert debug.wait_layout().title().lower() == "recover wallet"
assert debug.read_layout().title().lower() == "recover wallet"
layout = debug.click(buttons.OK, wait=True)
layout = debug.click(buttons.OK)
assert "number of words" in layout.text_content()
debug = _restart(device_handler, core_emulator)
@ -61,14 +61,14 @@ def test_abort(core_emulator: Emulator):
# no waiting for layout because layout doesn't change
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)
layout = debug.click(buttons.CANCEL)
# 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)
assert layout.title().lower() in ("abort recovery", "cancel recovery")
layout = debug.click(buttons.OK, wait=True)
layout = debug.click(buttons.OK)
assert layout.main_component() == "Homescreen"
features = device_handler.features()
@ -95,7 +95,7 @@ def test_recovery_single_reset(core_emulator: Emulator):
assert features.recovery_status == RecoveryStatus.Recovery
# we need to enter the number of words again, that's a feature
recovery.select_number_of_words(debug, wait=False)
recovery.select_number_of_words(debug)
recovery.enter_shares(debug, MNEMONIC_SLIP39_BASIC_20_3of6)
recovery.finalize(debug)
@ -132,7 +132,7 @@ def test_recovery_on_old_wallet(core_emulator: Emulator):
assert features.recovery_status == RecoveryStatus.Recovery
# enter number of words
recovery.select_number_of_words(debug, wait=False)
recovery.select_number_of_words(debug)
first_share = MNEMONIC_SLIP39_BASIC_20_3of6[0]
words = first_share.split(" ")
@ -140,11 +140,11 @@ def test_recovery_on_old_wallet(core_emulator: Emulator):
# start entering first share
assert "Enter each word of your wallet backup" in debug.read_layout().text_content()
debug.press_yes()
assert debug.wait_layout().main_component() == "MnemonicKeyboard"
assert debug.read_layout().main_component() == "MnemonicKeyboard"
# enter first word
debug.input(words[0])
layout = debug.wait_layout()
layout = debug.read_layout()
# while keyboard is open, hit the device with Initialize/GetFeatures
device_handler.client.init_device()
@ -154,7 +154,7 @@ def test_recovery_on_old_wallet(core_emulator: Emulator):
for word in words[1:]:
assert layout.main_component() == "MnemonicKeyboard"
debug.input(word)
layout = debug.wait_layout()
layout = debug.read_layout()
# check that we entered the first share successfully
assert "2 more shares needed" in layout.text_content()
@ -208,7 +208,7 @@ def test_recovery_multiple_resets(core_emulator: Emulator):
assert features.recovery_status == RecoveryStatus.Recovery
# enter the number of words again, that's a feature!
recovery.select_number_of_words(debug, wait=False)
recovery.select_number_of_words(debug)
# enter shares and restart after each one
enter_shares_with_restarts(debug)

View File

@ -13,19 +13,15 @@ def _enter_word(
for coords in buttons.type_word(typed_word, is_slip39=is_slip39):
debug.click(coords)
return debug.click(buttons.CONFIRM_WORD, wait=True)
return debug.click(buttons.CONFIRM_WORD)
def confirm_recovery(debug: "DebugLink") -> None:
debug.click(buttons.OK, wait=True)
debug.click(buttons.OK)
def select_number_of_words(
debug: "DebugLink", num_of_words: int = 20, wait: bool = True
) -> None:
if wait:
debug.wait_layout()
debug.click(buttons.OK, wait=True)
def select_number_of_words(debug: "DebugLink", num_of_words: int = 20) -> None:
debug.click(buttons.OK)
# click the number
word_option_offset = 6
@ -34,13 +30,13 @@ def select_number_of_words(
num_of_words
) # raises if num of words is invalid
coords = buttons.grid34(index % 3, index // 3)
debug.click(coords, wait=True)
debug.click(coords)
def enter_share(
debug: "DebugLink", share: str, is_first: bool = True
) -> "LayoutContent":
layout = debug.click(buttons.OK, wait=True)
layout = debug.click(buttons.OK)
for word in share.split(" "):
layout = _enter_word(debug, word, is_slip39=True)
return layout