mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-07-14 18:48:10 +00:00
tests: common improvements
This commit is contained in:
parent
d652ffecfd
commit
cea6cd6cc4
@ -15,8 +15,10 @@
|
|||||||
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
|
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import time
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import TYPE_CHECKING, Generator, List, Optional
|
from typing import TYPE_CHECKING, Generator, Optional
|
||||||
|
from unittest import mock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@ -59,6 +61,10 @@ COMMON_FIXTURES_DIR = (
|
|||||||
Path(__file__).resolve().parent.parent / "common" / "tests" / "fixtures"
|
Path(__file__).resolve().parent.parent / "common" / "tests" / "fixtures"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# So that all the random things are consistent
|
||||||
|
MOCK_OS_URANDOM = mock.Mock(return_value=EXTERNAL_ENTROPY)
|
||||||
|
WITH_MOCK_URANDOM = mock.patch("os.urandom", MOCK_OS_URANDOM)
|
||||||
|
|
||||||
|
|
||||||
def parametrize_using_common_fixtures(*paths: str) -> "MarkDecorator":
|
def parametrize_using_common_fixtures(*paths: str) -> "MarkDecorator":
|
||||||
fixtures = []
|
fixtures = []
|
||||||
@ -124,7 +130,7 @@ def generate_entropy(
|
|||||||
|
|
||||||
def recovery_enter_shares(
|
def recovery_enter_shares(
|
||||||
debug: "DebugLink",
|
debug: "DebugLink",
|
||||||
shares: List[str],
|
shares: list[str],
|
||||||
groups: bool = False,
|
groups: bool = False,
|
||||||
click_info: bool = False,
|
click_info: bool = False,
|
||||||
) -> Generator[None, "ButtonRequest", None]:
|
) -> Generator[None, "ButtonRequest", None]:
|
||||||
@ -179,7 +185,7 @@ def recovery_enter_shares(
|
|||||||
|
|
||||||
|
|
||||||
def click_through(
|
def click_through(
|
||||||
debug: "DebugLink", screens: int, code: ButtonRequestType = None
|
debug: "DebugLink", screens: int, code: Optional[ButtonRequestType] = None
|
||||||
) -> Generator[None, "ButtonRequest", None]:
|
) -> Generator[None, "ButtonRequest", None]:
|
||||||
"""Click through N dialog screens.
|
"""Click through N dialog screens.
|
||||||
|
|
||||||
@ -214,19 +220,25 @@ def read_and_confirm_mnemonic(
|
|||||||
|
|
||||||
mnemonic = yield from read_and_confirm_mnemonic(client.debug)
|
mnemonic = yield from read_and_confirm_mnemonic(client.debug)
|
||||||
"""
|
"""
|
||||||
mnemonic = []
|
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())
|
|
||||||
debug.swipe_up(wait=True)
|
|
||||||
|
|
||||||
# last page is confirmation
|
for i in range(br.pages):
|
||||||
mnemonic.extend(debug.read_reset_word().split())
|
if i == 0:
|
||||||
|
layout = debug.wait_layout()
|
||||||
|
else:
|
||||||
|
layout = debug.read_layout()
|
||||||
|
words = layout.seed_words()
|
||||||
|
mnemonic.extend(words)
|
||||||
|
# Not swiping on the last page
|
||||||
|
if i < br.pages - 1:
|
||||||
|
debug.swipe_up(wait=True)
|
||||||
|
|
||||||
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)])
|
||||||
@ -237,6 +249,20 @@ def read_and_confirm_mnemonic(
|
|||||||
return " ".join(mnemonic)
|
return " ".join(mnemonic)
|
||||||
|
|
||||||
|
|
||||||
|
def click_info_button(debug: "DebugLink"):
|
||||||
|
"""Click Shamir backup info button and return back."""
|
||||||
|
debug.press_info()
|
||||||
|
yield # Info screen with text
|
||||||
|
debug.press_yes()
|
||||||
|
|
||||||
|
|
||||||
|
def check_PIN_backoff_time(attempts: int, start: float) -> None:
|
||||||
|
"""Helper to assert the exponentially growing delay after incorrect PIN attempts"""
|
||||||
|
expected = (2**attempts) - 1
|
||||||
|
got = round(time.time() - start, 2)
|
||||||
|
assert got >= expected
|
||||||
|
|
||||||
|
|
||||||
def get_test_address(client: "Client") -> str:
|
def get_test_address(client: "Client") -> str:
|
||||||
"""Fetch a testnet address on a fixed path. Useful to make a pin/passphrase
|
"""Fetch a testnet address on a fixed path. Useful to make a pin/passphrase
|
||||||
protected call, or to identify the root secret (seed+passphrase)"""
|
protected call, or to identify the root secret (seed+passphrase)"""
|
||||||
|
Loading…
Reference in New Issue
Block a user