mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-29 16:51:30 +00:00
fix(tests): update tests for newly introduced device.setup()
This commit is contained in:
parent
79cc7a9693
commit
a3fc66f4b6
@ -73,7 +73,7 @@ def set_autolock_delay(device_handler: "BackgroundDeviceHandler", delay_ms: int)
|
||||
if debug.layout_type is LayoutType.Quicksilver:
|
||||
layout = tap_to_confirm(debug)
|
||||
assert layout.main_component() == "Homescreen"
|
||||
assert device_handler.result() == "Settings applied"
|
||||
device_handler.result()
|
||||
|
||||
|
||||
@pytest.mark.setup_client(pin=PIN4)
|
||||
|
@ -22,7 +22,7 @@ from trezorlib import device, messages
|
||||
from trezorlib.debuglink import LayoutType
|
||||
|
||||
from .. import translations as TR
|
||||
from ..common import EXTERNAL_ENTROPY, WITH_MOCK_URANDOM, generate_entropy
|
||||
from ..common import EXTERNAL_ENTROPY, MOCK_GET_ENTROPY, generate_entropy
|
||||
from . import reset
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@ -41,7 +41,6 @@ pytestmark = pytest.mark.models("core")
|
||||
],
|
||||
)
|
||||
@pytest.mark.setup_client(uninitialized=True)
|
||||
@WITH_MOCK_URANDOM
|
||||
def test_backup_slip39_custom(
|
||||
device_handler: "BackgroundDeviceHandler",
|
||||
group_threshold: int,
|
||||
@ -54,10 +53,13 @@ def test_backup_slip39_custom(
|
||||
assert features.initialized is False
|
||||
|
||||
device_handler.run(
|
||||
device.reset,
|
||||
device.setup,
|
||||
strength=128,
|
||||
backup_type=messages.BackupType.Slip39_Basic,
|
||||
pin_protection=False,
|
||||
passphrase_protection=False,
|
||||
entropy_check_count=0,
|
||||
_get_entropy=MOCK_GET_ENTROPY,
|
||||
)
|
||||
|
||||
# confirm new wallet
|
||||
@ -66,7 +68,8 @@ def test_backup_slip39_custom(
|
||||
# cancel back up
|
||||
reset.cancel_backup(debug, confirm=True)
|
||||
|
||||
assert device_handler.result() == "Initialized"
|
||||
# retrieve the result to check that it's not a TrezorFailure exception
|
||||
device_handler.result()
|
||||
|
||||
device_handler.run(
|
||||
device.backup,
|
||||
@ -116,7 +119,9 @@ def test_backup_slip39_custom(
|
||||
# validate that all combinations will result in the correct master secret
|
||||
reset.validate_mnemonics(all_words[:share_threshold], secret)
|
||||
|
||||
assert device_handler.result() == "Seed successfully backed up"
|
||||
# retrieve the result to check that it's not a TrezorFailure exception
|
||||
device_handler.result()
|
||||
|
||||
features = device_handler.features()
|
||||
assert features.initialized is True
|
||||
assert features.backup_availability == messages.BackupAvailability.NotAvailable
|
||||
|
@ -44,7 +44,8 @@ def prepare_recovery_and_evaluate(
|
||||
|
||||
yield debug
|
||||
|
||||
assert isinstance(device_handler.result(), messages.Success)
|
||||
device_handler.result()
|
||||
|
||||
features = device_handler.features()
|
||||
assert features.initialized is True
|
||||
assert features.recovery_status == messages.RecoveryStatus.Nothing
|
||||
|
@ -21,7 +21,7 @@ import pytest
|
||||
from trezorlib import device, messages
|
||||
|
||||
from .. import buttons
|
||||
from ..common import WITH_MOCK_URANDOM
|
||||
from ..common import MOCK_GET_ENTROPY
|
||||
from . import recovery, reset
|
||||
from .common import go_next
|
||||
|
||||
@ -33,7 +33,6 @@ pytestmark = pytest.mark.models("core")
|
||||
|
||||
|
||||
@pytest.mark.setup_client(uninitialized=True)
|
||||
@WITH_MOCK_URANDOM
|
||||
def test_repeated_backup(
|
||||
device_handler: "BackgroundDeviceHandler",
|
||||
):
|
||||
@ -43,10 +42,13 @@ def test_repeated_backup(
|
||||
assert features.initialized is False
|
||||
|
||||
device_handler.run(
|
||||
device.reset,
|
||||
device.setup,
|
||||
strength=128,
|
||||
backup_type=messages.BackupType.Slip39_Basic,
|
||||
pin_protection=False,
|
||||
passphrase_protection=False,
|
||||
entropy_check_count=0,
|
||||
_get_entropy=MOCK_GET_ENTROPY,
|
||||
)
|
||||
|
||||
# confirm new wallet
|
||||
@ -84,8 +86,9 @@ def test_repeated_backup(
|
||||
# Your backup is done
|
||||
go_next(debug)
|
||||
|
||||
# retrieve the result to check that it does not raise a failure
|
||||
device_handler.result()
|
||||
# great ... device is initialized, backup done, and we are not in recovery mode!
|
||||
assert device_handler.result() == "Initialized"
|
||||
features = device_handler.features()
|
||||
assert features.backup_type is messages.BackupType.Slip39_Basic_Extendable
|
||||
assert features.initialized is True
|
||||
@ -109,8 +112,8 @@ def test_repeated_backup(
|
||||
"recovery__unlock_repeated_backup",
|
||||
)
|
||||
|
||||
# backup is enabled
|
||||
assert device_handler.result().message == "Backup unlocked"
|
||||
# check non-exception result
|
||||
device_handler.result()
|
||||
|
||||
# we are now in recovery mode
|
||||
features = device_handler.features()
|
||||
@ -178,7 +181,8 @@ def test_repeated_backup(
|
||||
"recovery__unlock_repeated_backup",
|
||||
)
|
||||
|
||||
assert device_handler.result().message == "Backup unlocked"
|
||||
# check non-exception result
|
||||
device_handler.result()
|
||||
|
||||
# we are now in recovery mode again!
|
||||
features = device_handler.features()
|
||||
|
@ -21,7 +21,7 @@ import pytest
|
||||
from trezorlib import device, messages
|
||||
|
||||
from .. import translations as TR
|
||||
from ..common import WITH_MOCK_URANDOM
|
||||
from ..common import MOCK_GET_ENTROPY
|
||||
from . import reset
|
||||
from .common import go_next
|
||||
|
||||
@ -33,7 +33,6 @@ pytestmark = pytest.mark.models("core")
|
||||
|
||||
|
||||
@pytest.mark.setup_client(uninitialized=True)
|
||||
@WITH_MOCK_URANDOM
|
||||
def test_reset_bip39(device_handler: "BackgroundDeviceHandler"):
|
||||
features = device_handler.features()
|
||||
debug = device_handler.debuglink()
|
||||
@ -41,10 +40,13 @@ def test_reset_bip39(device_handler: "BackgroundDeviceHandler"):
|
||||
assert features.initialized is False
|
||||
|
||||
device_handler.run(
|
||||
device.reset,
|
||||
device.setup,
|
||||
strength=128,
|
||||
backup_type=messages.BackupType.Bip39,
|
||||
pin_protection=False,
|
||||
passphrase_protection=False,
|
||||
entropy_check_count=0,
|
||||
_get_entropy=MOCK_GET_ENTROPY,
|
||||
)
|
||||
|
||||
# confirm new wallet
|
||||
@ -82,7 +84,9 @@ def test_reset_bip39(device_handler: "BackgroundDeviceHandler"):
|
||||
|
||||
# TODO: some validation of the generated secret?
|
||||
|
||||
assert device_handler.result() == "Initialized"
|
||||
# retrieve the result to check that it's not a TrezorFailure exception
|
||||
device_handler.result()
|
||||
|
||||
features = device_handler.features()
|
||||
assert features.initialized is True
|
||||
assert features.backup_availability == messages.BackupAvailability.NotAvailable
|
||||
|
@ -21,7 +21,7 @@ import pytest
|
||||
from trezorlib import device, messages
|
||||
|
||||
from .. import buttons
|
||||
from ..common import EXTERNAL_ENTROPY, WITH_MOCK_URANDOM, generate_entropy
|
||||
from ..common import EXTERNAL_ENTROPY, MOCK_GET_ENTROPY, generate_entropy
|
||||
from . import reset
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@ -39,7 +39,6 @@ pytestmark = pytest.mark.models("core")
|
||||
pytest.param(16, 16, 16, 16, id="16of16", marks=pytest.mark.slow),
|
||||
],
|
||||
)
|
||||
@WITH_MOCK_URANDOM
|
||||
def test_reset_slip39_advanced(
|
||||
device_handler: "BackgroundDeviceHandler",
|
||||
group_count: int,
|
||||
@ -53,9 +52,12 @@ def test_reset_slip39_advanced(
|
||||
assert features.initialized is False
|
||||
|
||||
device_handler.run(
|
||||
device.reset,
|
||||
device.setup,
|
||||
backup_type=messages.BackupType.Slip39_Advanced,
|
||||
pin_protection=False,
|
||||
passphrase_protection=False,
|
||||
entropy_check_count=0,
|
||||
_get_entropy=MOCK_GET_ENTROPY,
|
||||
)
|
||||
|
||||
# confirm new wallet
|
||||
@ -162,7 +164,8 @@ def test_reset_slip39_advanced(
|
||||
# validate that all combinations will result in the correct master secret
|
||||
reset.validate_mnemonics(all_words, secret)
|
||||
|
||||
assert device_handler.result() == "Initialized"
|
||||
# retrieve the result to check that it's not a TrezorFailure exception
|
||||
device_handler.result()
|
||||
|
||||
features = device_handler.features()
|
||||
assert features.initialized is True
|
||||
|
@ -21,7 +21,7 @@ import pytest
|
||||
from trezorlib import device, messages
|
||||
|
||||
from .. import buttons
|
||||
from ..common import EXTERNAL_ENTROPY, WITH_MOCK_URANDOM, generate_entropy
|
||||
from ..common import EXTERNAL_ENTROPY, MOCK_GET_ENTROPY, generate_entropy
|
||||
from . import reset
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@ -39,7 +39,6 @@ pytestmark = pytest.mark.models("core")
|
||||
],
|
||||
)
|
||||
@pytest.mark.setup_client(uninitialized=True)
|
||||
@WITH_MOCK_URANDOM
|
||||
def test_reset_slip39_basic(
|
||||
device_handler: "BackgroundDeviceHandler", num_of_shares: int, threshold: int
|
||||
):
|
||||
@ -49,10 +48,13 @@ def test_reset_slip39_basic(
|
||||
assert features.initialized is False
|
||||
|
||||
device_handler.run(
|
||||
device.reset,
|
||||
device.setup,
|
||||
strength=128,
|
||||
backup_type=messages.BackupType.Slip39_Basic,
|
||||
pin_protection=False,
|
||||
passphrase_protection=False,
|
||||
entropy_check_count=0,
|
||||
_get_entropy=MOCK_GET_ENTROPY,
|
||||
)
|
||||
|
||||
# confirm new wallet
|
||||
@ -137,7 +139,9 @@ def test_reset_slip39_basic(
|
||||
# validate that all combinations will result in the correct master secret
|
||||
reset.validate_mnemonics(all_words, secret)
|
||||
|
||||
assert device_handler.result() == "Initialized"
|
||||
# retrieve the result to check that it's not a TrezorFailure exception
|
||||
device_handler.result()
|
||||
|
||||
features = device_handler.features()
|
||||
assert features.initialized is True
|
||||
assert features.backup_availability == messages.BackupAvailability.NotAvailable
|
||||
|
@ -83,8 +83,7 @@ COMMON_FIXTURES_DIR = (
|
||||
)
|
||||
|
||||
# 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)
|
||||
MOCK_GET_ENTROPY = mock.Mock(return_value=EXTERNAL_ENTROPY)
|
||||
|
||||
|
||||
def parametrize_using_common_fixtures(*paths: str) -> "MarkDecorator":
|
||||
|
@ -1,18 +1,22 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import typing as t
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from typing import TYPE_CHECKING, Any, Callable
|
||||
|
||||
import typing_extensions as tx
|
||||
|
||||
from trezorlib.client import PASSPHRASE_ON_DEVICE
|
||||
from trezorlib.messages import DebugWaitType
|
||||
from trezorlib.transport import udp
|
||||
|
||||
if TYPE_CHECKING:
|
||||
if t.TYPE_CHECKING:
|
||||
from trezorlib._internal.emulator import Emulator
|
||||
from trezorlib.debuglink import DebugLink
|
||||
from trezorlib.debuglink import TrezorClientDebugLink as Client
|
||||
from trezorlib.messages import Features
|
||||
|
||||
P = tx.ParamSpec("P")
|
||||
|
||||
|
||||
udp.SOCKET_TIMEOUT = 0.1
|
||||
|
||||
@ -48,7 +52,12 @@ class BackgroundDeviceHandler:
|
||||
self.client.watch_layout(True)
|
||||
self.client.debug.input_wait_type = DebugWaitType.CURRENT_LAYOUT
|
||||
|
||||
def run(self, function: Callable[..., Any], *args: Any, **kwargs: Any) -> None:
|
||||
def run(
|
||||
self,
|
||||
function: t.Callable[tx.Concatenate["Client", P], t.Any],
|
||||
*args: P.args,
|
||||
**kwargs: P.kwargs,
|
||||
) -> None:
|
||||
"""Runs some function that interacts with a device.
|
||||
|
||||
Makes sure the UI is updated before returning.
|
||||
@ -79,7 +88,7 @@ class BackgroundDeviceHandler:
|
||||
emulator.restart()
|
||||
self._configure_client(emulator.client) # type: ignore [client cannot be None]
|
||||
|
||||
def result(self, timeout: float | None = None) -> Any:
|
||||
def result(self, timeout: float | None = None) -> t.Any:
|
||||
if self.task is None:
|
||||
raise RuntimeError("No task running")
|
||||
try:
|
||||
|
@ -457,7 +457,7 @@ def test_sign_tx_spend(client: Client):
|
||||
client.set_expected_responses(
|
||||
[
|
||||
messages.ButtonRequest(code=B.Other),
|
||||
messages.UnlockedPathRequest(),
|
||||
messages.UnlockedPathRequest,
|
||||
request_input(0),
|
||||
request_output(0),
|
||||
request_output(1),
|
||||
@ -531,7 +531,7 @@ def test_sign_tx_migration(client: Client):
|
||||
client.set_expected_responses(
|
||||
[
|
||||
messages.ButtonRequest(code=B.Other),
|
||||
messages.UnlockedPathRequest(),
|
||||
messages.UnlockedPathRequest,
|
||||
request_input(0),
|
||||
request_input(1),
|
||||
request_output(0),
|
||||
|
@ -51,15 +51,13 @@ def _test_secret(
|
||||
with client:
|
||||
IF = InputFlowSlip39AdvancedRecovery(client, shares, click_info=click_info)
|
||||
client.set_input_flow(IF.get())
|
||||
ret = device.recover(
|
||||
device.recover(
|
||||
client,
|
||||
pin_protection=False,
|
||||
passphrase_protection=False,
|
||||
label="label",
|
||||
)
|
||||
|
||||
# Workflow succesfully ended
|
||||
assert ret == messages.Success(message="Device recovered")
|
||||
assert client.features.initialized is True
|
||||
assert client.features.pin_protection is False
|
||||
assert client.features.passphrase_protection is False
|
||||
|
@ -45,7 +45,7 @@ def test_2of3_dryrun(client: Client):
|
||||
client, EXTRA_GROUP_SHARE + MNEMONIC_SLIP39_ADVANCED_20
|
||||
)
|
||||
client.set_input_flow(IF.get())
|
||||
ret = device.recover(
|
||||
device.recover(
|
||||
client,
|
||||
passphrase_protection=False,
|
||||
pin_protection=False,
|
||||
@ -53,11 +53,6 @@ def test_2of3_dryrun(client: Client):
|
||||
type=messages.RecoveryType.DryRun,
|
||||
)
|
||||
|
||||
# Dry run was successful
|
||||
assert ret == messages.Success(
|
||||
message="The seed is valid and matches the one in the device"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.setup_client(mnemonic=MNEMONIC_SLIP39_ADVANCED_20)
|
||||
def test_2of3_invalid_seed_dryrun(client: Client):
|
||||
|
@ -75,10 +75,9 @@ def test_secret(
|
||||
with client:
|
||||
IF = InputFlowSlip39BasicRecovery(client, shares)
|
||||
client.set_input_flow(IF.get())
|
||||
ret = device.recover(client, pin_protection=False, label="label")
|
||||
device.recover(client, pin_protection=False, label="label")
|
||||
|
||||
# Workflow successfully ended
|
||||
assert ret == messages.Success(message="Device recovered")
|
||||
assert client.features.pin_protection is False
|
||||
assert client.features.passphrase_protection is False
|
||||
assert client.features.backup_type is backup_type
|
||||
@ -94,7 +93,7 @@ def test_recover_with_pin_passphrase(client: Client):
|
||||
client, MNEMONIC_SLIP39_BASIC_20_3of6, pin="654"
|
||||
)
|
||||
client.set_input_flow(IF.get())
|
||||
ret = device.recover(
|
||||
device.recover(
|
||||
client,
|
||||
pin_protection=True,
|
||||
passphrase_protection=True,
|
||||
@ -102,7 +101,6 @@ def test_recover_with_pin_passphrase(client: Client):
|
||||
)
|
||||
|
||||
# Workflow successfully ended
|
||||
assert ret == messages.Success(message="Device recovered")
|
||||
assert client.features.pin_protection is True
|
||||
assert client.features.passphrase_protection is True
|
||||
assert client.features.backup_type is messages.BackupType.Slip39_Basic
|
||||
@ -194,7 +192,7 @@ def test_1of1(client: Client):
|
||||
with client:
|
||||
IF = InputFlowSlip39BasicRecovery(client, MNEMONIC_SLIP39_BASIC_20_1of1)
|
||||
client.set_input_flow(IF.get())
|
||||
ret = device.recover(
|
||||
device.recover(
|
||||
client,
|
||||
pin_protection=False,
|
||||
passphrase_protection=False,
|
||||
@ -202,7 +200,6 @@ def test_1of1(client: Client):
|
||||
)
|
||||
|
||||
# Workflow successfully ended
|
||||
assert ret == messages.Success(message="Device recovered")
|
||||
assert client.features.initialized is True
|
||||
assert client.features.pin_protection is False
|
||||
assert client.features.passphrase_protection is False
|
||||
|
@ -41,7 +41,7 @@ def test_2of3_dryrun(client: Client):
|
||||
with client:
|
||||
IF = InputFlowSlip39BasicRecoveryDryRun(client, SHARES_20_2of3[1:3])
|
||||
client.set_input_flow(IF.get())
|
||||
ret = device.recover(
|
||||
device.recover(
|
||||
client,
|
||||
passphrase_protection=False,
|
||||
pin_protection=False,
|
||||
@ -49,11 +49,6 @@ def test_2of3_dryrun(client: Client):
|
||||
type=messages.RecoveryType.DryRun,
|
||||
)
|
||||
|
||||
# Dry run was successful
|
||||
assert ret == messages.Success(
|
||||
message="The seed is valid and matches the one in the device"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.setup_client(mnemonic=SHARES_20_2of3[0:2])
|
||||
def test_2of3_invalid_seed_dryrun(client: Client):
|
||||
|
@ -22,7 +22,7 @@ from trezorlib import device
|
||||
from trezorlib.debuglink import TrezorClientDebugLink as Client
|
||||
from trezorlib.messages import BackupAvailability, BackupType
|
||||
|
||||
from ...common import WITH_MOCK_URANDOM
|
||||
from ...common import MOCK_GET_ENTROPY
|
||||
from ...input_flows import (
|
||||
InputFlowBip39Backup,
|
||||
InputFlowResetSkipBackup,
|
||||
@ -75,13 +75,15 @@ VECTORS = [
|
||||
@pytest.mark.parametrize("backup_type, backup_flow", VECTORS)
|
||||
@pytest.mark.setup_client(uninitialized=True)
|
||||
def test_skip_backup_msg(client: Client, backup_type, backup_flow):
|
||||
with WITH_MOCK_URANDOM, client:
|
||||
device.reset(
|
||||
with client:
|
||||
device.setup(
|
||||
client,
|
||||
skip_backup=True,
|
||||
passphrase_protection=False,
|
||||
pin_protection=False,
|
||||
backup_type=backup_type,
|
||||
entropy_check_count=0,
|
||||
_get_entropy=MOCK_GET_ENTROPY,
|
||||
)
|
||||
|
||||
assert client.features.initialized is True
|
||||
@ -108,14 +110,16 @@ def test_skip_backup_msg(client: Client, backup_type, backup_flow):
|
||||
@pytest.mark.parametrize("backup_type, backup_flow", VECTORS)
|
||||
@pytest.mark.setup_client(uninitialized=True)
|
||||
def test_skip_backup_manual(client: Client, backup_type: BackupType, backup_flow):
|
||||
with WITH_MOCK_URANDOM, client:
|
||||
with client:
|
||||
IF = InputFlowResetSkipBackup(client)
|
||||
client.set_input_flow(IF.get())
|
||||
device.reset(
|
||||
device.setup(
|
||||
client,
|
||||
pin_protection=False,
|
||||
passphrase_protection=False,
|
||||
backup_type=backup_type,
|
||||
entropy_check_count=0,
|
||||
_get_entropy=MOCK_GET_ENTROPY,
|
||||
)
|
||||
|
||||
assert client.features.initialized is True
|
||||
|
@ -209,7 +209,7 @@ def test_failed_pin(client: Client):
|
||||
|
||||
def test_already_initialized(client: Client):
|
||||
with pytest.raises(Exception):
|
||||
device.reset(
|
||||
device.setup(
|
||||
client,
|
||||
strength=128,
|
||||
passphrase_protection=True,
|
||||
|
@ -23,7 +23,7 @@ from trezorlib.debuglink import LayoutType
|
||||
from trezorlib.debuglink import TrezorClientDebugLink as Client
|
||||
from trezorlib.exceptions import TrezorFailure
|
||||
|
||||
from ...common import EXTERNAL_ENTROPY, MNEMONIC12, WITH_MOCK_URANDOM, generate_entropy
|
||||
from ...common import EXTERNAL_ENTROPY, MNEMONIC12, MOCK_GET_ENTROPY, generate_entropy
|
||||
from ...input_flows import (
|
||||
InputFlowBip39ResetBackup,
|
||||
InputFlowBip39ResetFailedCheck,
|
||||
@ -34,21 +34,25 @@ pytestmark = pytest.mark.models("core")
|
||||
|
||||
|
||||
def reset_device(client: Client, strength: int):
|
||||
with WITH_MOCK_URANDOM, client:
|
||||
with client:
|
||||
IF = InputFlowBip39ResetBackup(client)
|
||||
client.set_input_flow(IF.get())
|
||||
|
||||
# No PIN, no passphrase, don't display random
|
||||
device.reset(
|
||||
device.setup(
|
||||
client,
|
||||
strength=strength,
|
||||
passphrase_protection=False,
|
||||
pin_protection=False,
|
||||
label="test",
|
||||
entropy_check_count=0,
|
||||
backup_type=messages.BackupType.Bip39,
|
||||
_get_entropy=MOCK_GET_ENTROPY,
|
||||
)
|
||||
|
||||
# generate mnemonic locally
|
||||
internal_entropy = client.debug.state().reset_entropy
|
||||
assert internal_entropy is not None
|
||||
entropy = generate_entropy(strength, internal_entropy, EXTERNAL_ENTROPY)
|
||||
expected_mnemonic = Mnemonic("english").to_mnemonic(entropy)
|
||||
|
||||
@ -56,12 +60,13 @@ def reset_device(client: Client, strength: int):
|
||||
assert IF.mnemonic == expected_mnemonic
|
||||
|
||||
# Check if device is properly initialized
|
||||
resp = client.call_raw(messages.Initialize())
|
||||
assert resp.initialized is True
|
||||
assert resp.backup_availability == messages.BackupAvailability.NotAvailable
|
||||
assert resp.pin_protection is False
|
||||
assert resp.passphrase_protection is False
|
||||
assert resp.backup_type is messages.BackupType.Bip39
|
||||
assert client.features.initialized is True
|
||||
assert (
|
||||
client.features.backup_availability == messages.BackupAvailability.NotAvailable
|
||||
)
|
||||
assert client.features.pin_protection is False
|
||||
assert client.features.passphrase_protection is False
|
||||
assert client.features.backup_type is messages.BackupType.Bip39
|
||||
|
||||
# backup attempt fails because backup was done in reset
|
||||
with pytest.raises(TrezorFailure, match="ProcessError: Seed already backed up"):
|
||||
@ -82,21 +87,25 @@ def test_reset_device_192(client: Client):
|
||||
def test_reset_device_pin(client: Client):
|
||||
strength = 256 # 24 words
|
||||
|
||||
with WITH_MOCK_URANDOM, client:
|
||||
with client:
|
||||
IF = InputFlowBip39ResetPIN(client)
|
||||
client.set_input_flow(IF.get())
|
||||
|
||||
# PIN, passphrase, display random
|
||||
device.reset(
|
||||
device.setup(
|
||||
client,
|
||||
strength=strength,
|
||||
passphrase_protection=True,
|
||||
pin_protection=True,
|
||||
label="test",
|
||||
entropy_check_count=0,
|
||||
backup_type=messages.BackupType.Bip39,
|
||||
_get_entropy=MOCK_GET_ENTROPY,
|
||||
)
|
||||
|
||||
# generate mnemonic locally
|
||||
internal_entropy = client.debug.state().reset_entropy
|
||||
assert internal_entropy is not None
|
||||
entropy = generate_entropy(strength, internal_entropy, EXTERNAL_ENTROPY)
|
||||
expected_mnemonic = Mnemonic("english").to_mnemonic(entropy)
|
||||
|
||||
@ -104,33 +113,37 @@ def test_reset_device_pin(client: Client):
|
||||
assert IF.mnemonic == expected_mnemonic
|
||||
|
||||
# Check if device is properly initialized
|
||||
resp = client.call_raw(messages.Initialize())
|
||||
assert resp.initialized is True
|
||||
assert resp.backup_availability == messages.BackupAvailability.NotAvailable
|
||||
assert resp.pin_protection is True
|
||||
assert resp.passphrase_protection is True
|
||||
assert client.features.initialized is True
|
||||
assert (
|
||||
client.features.backup_availability == messages.BackupAvailability.NotAvailable
|
||||
)
|
||||
assert client.features.pin_protection is True
|
||||
assert client.features.passphrase_protection is True
|
||||
|
||||
|
||||
@pytest.mark.setup_client(uninitialized=True)
|
||||
def test_reset_entropy_check(client: Client):
|
||||
strength = 128 # 12 words
|
||||
|
||||
with WITH_MOCK_URANDOM, client:
|
||||
with client:
|
||||
IF = InputFlowBip39ResetBackup(client)
|
||||
client.set_input_flow(IF.get())
|
||||
|
||||
# No PIN, no passphrase
|
||||
_, path_xpubs = device.reset_entropy_check(
|
||||
path_xpubs = device.setup(
|
||||
client,
|
||||
strength=strength,
|
||||
passphrase_protection=False,
|
||||
pin_protection=False,
|
||||
label="test",
|
||||
entropy_check_count=2,
|
||||
backup_type=messages.BackupType.Bip39,
|
||||
_get_entropy=MOCK_GET_ENTROPY,
|
||||
)
|
||||
|
||||
# Generate the mnemonic locally.
|
||||
internal_entropy = client.debug.state().reset_entropy
|
||||
assert internal_entropy is not None
|
||||
entropy = generate_entropy(strength, internal_entropy, EXTERNAL_ENTROPY)
|
||||
expected_mnemonic = Mnemonic("english").to_mnemonic(entropy)
|
||||
|
||||
@ -138,12 +151,13 @@ def test_reset_entropy_check(client: Client):
|
||||
assert IF.mnemonic == expected_mnemonic
|
||||
|
||||
# Check that the device is properly initialized.
|
||||
resp = client.call_raw(messages.Initialize())
|
||||
assert resp.initialized is True
|
||||
assert resp.backup_availability == messages.BackupAvailability.NotAvailable
|
||||
assert resp.pin_protection is False
|
||||
assert resp.passphrase_protection is False
|
||||
assert resp.backup_type is messages.BackupType.Bip39
|
||||
assert client.features.initialized is True
|
||||
assert (
|
||||
client.features.backup_availability == messages.BackupAvailability.NotAvailable
|
||||
)
|
||||
assert client.features.pin_protection is False
|
||||
assert client.features.passphrase_protection is False
|
||||
assert client.features.backup_type is messages.BackupType.Bip39
|
||||
|
||||
# Check that the XPUBs are the same as those from the entropy check.
|
||||
for path, xpub in path_xpubs:
|
||||
@ -155,21 +169,25 @@ def test_reset_entropy_check(client: Client):
|
||||
def test_reset_failed_check(client: Client):
|
||||
strength = 256 # 24 words
|
||||
|
||||
with WITH_MOCK_URANDOM, client:
|
||||
with client:
|
||||
IF = InputFlowBip39ResetFailedCheck(client)
|
||||
client.set_input_flow(IF.get())
|
||||
|
||||
# PIN, passphrase, display random
|
||||
device.reset(
|
||||
device.setup(
|
||||
client,
|
||||
strength=strength,
|
||||
passphrase_protection=False,
|
||||
pin_protection=False,
|
||||
label="test",
|
||||
entropy_check_count=0,
|
||||
backup_type=messages.BackupType.Bip39,
|
||||
_get_entropy=MOCK_GET_ENTROPY,
|
||||
)
|
||||
|
||||
# generate mnemonic locally
|
||||
internal_entropy = client.debug.state().reset_entropy
|
||||
assert internal_entropy is not None
|
||||
entropy = generate_entropy(strength, internal_entropy, EXTERNAL_ENTROPY)
|
||||
expected_mnemonic = Mnemonic("english").to_mnemonic(entropy)
|
||||
|
||||
@ -177,12 +195,13 @@ def test_reset_failed_check(client: Client):
|
||||
assert IF.mnemonic == expected_mnemonic
|
||||
|
||||
# Check if device is properly initialized
|
||||
resp = client.call_raw(messages.Initialize())
|
||||
assert resp.initialized is True
|
||||
assert resp.backup_availability == messages.BackupAvailability.NotAvailable
|
||||
assert resp.pin_protection is False
|
||||
assert resp.passphrase_protection is False
|
||||
assert resp.backup_type is messages.BackupType.Bip39
|
||||
assert client.features.initialized is True
|
||||
assert (
|
||||
client.features.backup_availability == messages.BackupAvailability.NotAvailable
|
||||
)
|
||||
assert client.features.pin_protection is False
|
||||
assert client.features.passphrase_protection is False
|
||||
assert client.features.backup_type is messages.BackupType.Bip39
|
||||
|
||||
|
||||
@pytest.mark.setup_client(uninitialized=True)
|
||||
@ -223,7 +242,7 @@ def test_failed_pin(client: Client):
|
||||
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
|
||||
def test_already_initialized(client: Client):
|
||||
with pytest.raises(Exception):
|
||||
device.reset(
|
||||
device.setup(
|
||||
client,
|
||||
strength=128,
|
||||
passphrase_protection=True,
|
||||
|
@ -21,7 +21,7 @@ from trezorlib.debuglink import TrezorClientDebugLink as Client
|
||||
from trezorlib.messages import BackupType
|
||||
from trezorlib.tools import parse_path
|
||||
|
||||
from ...common import WITH_MOCK_URANDOM
|
||||
from ...common import MOCK_GET_ENTROPY
|
||||
from ...input_flows import InputFlowBip39Recovery, InputFlowBip39ResetBackup
|
||||
from ...translations import set_language
|
||||
|
||||
@ -41,18 +41,20 @@ def test_reset_recovery(client: Client):
|
||||
|
||||
|
||||
def reset(client: Client, strength: int = 128, skip_backup: bool = False) -> str:
|
||||
with WITH_MOCK_URANDOM, client:
|
||||
with client:
|
||||
IF = InputFlowBip39ResetBackup(client)
|
||||
client.set_input_flow(IF.get())
|
||||
|
||||
# No PIN, no passphrase, don't display random
|
||||
device.reset(
|
||||
device.setup(
|
||||
client,
|
||||
strength=strength,
|
||||
passphrase_protection=False,
|
||||
pin_protection=False,
|
||||
label="test",
|
||||
backup_type=BackupType.Bip39,
|
||||
entropy_check_count=0,
|
||||
_get_entropy=MOCK_GET_ENTROPY,
|
||||
)
|
||||
|
||||
# Check if device is properly initialized
|
||||
@ -73,9 +75,7 @@ def recover(client: Client, mnemonic: str):
|
||||
IF = InputFlowBip39Recovery(client, words)
|
||||
client.set_input_flow(IF.get())
|
||||
client.watch_layout()
|
||||
ret = device.recover(client, pin_protection=False, label="label")
|
||||
device.recover(client, pin_protection=False, label="label")
|
||||
|
||||
# Workflow successfully ended
|
||||
assert ret == messages.Success(message="Device recovered")
|
||||
assert client.features.pin_protection is False
|
||||
assert client.features.passphrase_protection is False
|
||||
|
@ -21,7 +21,7 @@ from trezorlib.debuglink import TrezorClientDebugLink as Client
|
||||
from trezorlib.messages import BackupType
|
||||
from trezorlib.tools import parse_path
|
||||
|
||||
from ...common import WITH_MOCK_URANDOM
|
||||
from ...common import MOCK_GET_ENTROPY
|
||||
from ...input_flows import (
|
||||
InputFlowSlip39AdvancedRecovery,
|
||||
InputFlowSlip39AdvancedResetRecovery,
|
||||
@ -62,18 +62,20 @@ def test_reset_recovery(client: Client):
|
||||
|
||||
|
||||
def reset(client: Client, strength: int = 128) -> list[str]:
|
||||
with WITH_MOCK_URANDOM, client:
|
||||
with client:
|
||||
IF = InputFlowSlip39AdvancedResetRecovery(client, False)
|
||||
client.set_input_flow(IF.get())
|
||||
|
||||
# No PIN, no passphrase, don't display random
|
||||
device.reset(
|
||||
device.setup(
|
||||
client,
|
||||
strength=strength,
|
||||
passphrase_protection=False,
|
||||
pin_protection=False,
|
||||
label="test",
|
||||
backup_type=BackupType.Slip39_Advanced,
|
||||
entropy_check_count=0,
|
||||
_get_entropy=MOCK_GET_ENTROPY,
|
||||
)
|
||||
|
||||
# Check if device is properly initialized
|
||||
@ -92,10 +94,8 @@ def recover(client: Client, shares: list[str]):
|
||||
with client:
|
||||
IF = InputFlowSlip39AdvancedRecovery(client, shares, False)
|
||||
client.set_input_flow(IF.get())
|
||||
ret = device.recover(client, pin_protection=False, label="label")
|
||||
device.recover(client, pin_protection=False, label="label")
|
||||
|
||||
# Workflow successfully ended
|
||||
assert ret == messages.Success(message="Device recovered")
|
||||
assert client.features.pin_protection is False
|
||||
assert client.features.passphrase_protection is False
|
||||
assert client.features.backup_type is BackupType.Slip39_Advanced_Extendable
|
||||
|
@ -15,6 +15,7 @@
|
||||
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
|
||||
|
||||
import itertools
|
||||
import typing as t
|
||||
|
||||
import pytest
|
||||
|
||||
@ -23,7 +24,7 @@ from trezorlib.debuglink import TrezorClientDebugLink as Client
|
||||
from trezorlib.messages import BackupType
|
||||
from trezorlib.tools import parse_path
|
||||
|
||||
from ...common import WITH_MOCK_URANDOM
|
||||
from ...common import MOCK_GET_ENTROPY
|
||||
from ...input_flows import (
|
||||
InputFlowSlip39BasicRecovery,
|
||||
InputFlowSlip39BasicResetRecovery,
|
||||
@ -33,7 +34,6 @@ from ...translations import set_language
|
||||
|
||||
@pytest.mark.models("core")
|
||||
@pytest.mark.setup_client(uninitialized=True)
|
||||
@WITH_MOCK_URANDOM
|
||||
def test_reset_recovery(client: Client):
|
||||
mnemonics = reset(client)
|
||||
address_before = btc.get_address(client, "Bitcoin", parse_path("m/44h/0h/0h/0/0"))
|
||||
@ -56,13 +56,15 @@ def reset(client: Client, strength: int = 128) -> list[str]:
|
||||
client.set_input_flow(IF.get())
|
||||
|
||||
# No PIN, no passphrase, don't display random
|
||||
device.reset(
|
||||
device.setup(
|
||||
client,
|
||||
strength=strength,
|
||||
passphrase_protection=False,
|
||||
pin_protection=False,
|
||||
label="test",
|
||||
backup_type=BackupType.Slip39_Basic,
|
||||
entropy_check_count=0,
|
||||
_get_entropy=MOCK_GET_ENTROPY,
|
||||
)
|
||||
|
||||
# Check if device is properly initialized
|
||||
@ -77,14 +79,12 @@ def reset(client: Client, strength: int = 128) -> list[str]:
|
||||
return IF.mnemonics
|
||||
|
||||
|
||||
def recover(client: Client, shares: list[str]):
|
||||
def recover(client: Client, shares: t.Sequence[str]):
|
||||
with client:
|
||||
IF = InputFlowSlip39BasicRecovery(client, shares)
|
||||
client.set_input_flow(IF.get())
|
||||
ret = device.recover(client, pin_protection=False, label="label")
|
||||
device.recover(client, pin_protection=False, label="label")
|
||||
|
||||
# Workflow successfully ended
|
||||
assert ret == messages.Success(message="Device recovered")
|
||||
assert client.features.pin_protection is False
|
||||
assert client.features.passphrase_protection is False
|
||||
assert client.features.backup_type is BackupType.Slip39_Basic_Extendable
|
||||
|
@ -22,7 +22,7 @@ from trezorlib.debuglink import TrezorClientDebugLink as Client
|
||||
from trezorlib.exceptions import TrezorFailure
|
||||
from trezorlib.messages import BackupAvailability, BackupType
|
||||
|
||||
from ...common import EXTERNAL_ENTROPY, WITH_MOCK_URANDOM, generate_entropy
|
||||
from ...common import EXTERNAL_ENTROPY, MOCK_GET_ENTROPY, generate_entropy
|
||||
from ...input_flows import InputFlowSlip39AdvancedResetRecovery
|
||||
|
||||
pytestmark = pytest.mark.models("core")
|
||||
@ -34,22 +34,25 @@ def test_reset_device_slip39_advanced(client: Client):
|
||||
strength = 128
|
||||
member_threshold = 3
|
||||
|
||||
with WITH_MOCK_URANDOM, client:
|
||||
with client:
|
||||
IF = InputFlowSlip39AdvancedResetRecovery(client, False)
|
||||
client.set_input_flow(IF.get())
|
||||
|
||||
# No PIN, no passphrase, don't display random
|
||||
device.reset(
|
||||
device.setup(
|
||||
client,
|
||||
strength=strength,
|
||||
passphrase_protection=False,
|
||||
pin_protection=False,
|
||||
label="test",
|
||||
backup_type=BackupType.Slip39_Advanced,
|
||||
entropy_check_count=0,
|
||||
_get_entropy=MOCK_GET_ENTROPY,
|
||||
)
|
||||
|
||||
# generate secret locally
|
||||
internal_entropy = client.debug.state().reset_entropy
|
||||
assert internal_entropy is not None
|
||||
secret = generate_entropy(strength, internal_entropy, EXTERNAL_ENTROPY)
|
||||
|
||||
# validate that all combinations will result in the correct master secret
|
||||
@ -68,7 +71,7 @@ def test_reset_device_slip39_advanced(client: Client):
|
||||
|
||||
|
||||
def validate_mnemonics(
|
||||
mnemonics: list[list[str]], threshold: int, expected_ems: bytes
|
||||
mnemonics: list[str], threshold: int, expected_ems: bytes
|
||||
) -> None:
|
||||
# 3of5 shares 3of5 groups
|
||||
# TODO: test all possible group+share combinations?
|
||||
|
@ -25,7 +25,7 @@ from trezorlib.debuglink import TrezorClientDebugLink as Client
|
||||
from trezorlib.exceptions import TrezorFailure
|
||||
from trezorlib.messages import BackupAvailability, BackupType
|
||||
|
||||
from ...common import EXTERNAL_ENTROPY, WITH_MOCK_URANDOM, generate_entropy
|
||||
from ...common import EXTERNAL_ENTROPY, MOCK_GET_ENTROPY, generate_entropy
|
||||
from ...input_flows import InputFlowSlip39BasicResetRecovery
|
||||
|
||||
pytestmark = pytest.mark.models("core")
|
||||
@ -34,22 +34,25 @@ pytestmark = pytest.mark.models("core")
|
||||
def reset_device(client: Client, strength: int):
|
||||
member_threshold = 3
|
||||
|
||||
with WITH_MOCK_URANDOM, client:
|
||||
with client:
|
||||
IF = InputFlowSlip39BasicResetRecovery(client)
|
||||
client.set_input_flow(IF.get())
|
||||
|
||||
# No PIN, no passphrase, don't display random
|
||||
device.reset(
|
||||
device.setup(
|
||||
client,
|
||||
strength=strength,
|
||||
passphrase_protection=False,
|
||||
pin_protection=False,
|
||||
label="test",
|
||||
backup_type=BackupType.Slip39_Basic,
|
||||
entropy_check_count=0,
|
||||
_get_entropy=MOCK_GET_ENTROPY,
|
||||
)
|
||||
|
||||
# generate secret locally
|
||||
internal_entropy = client.debug.state().reset_entropy
|
||||
assert internal_entropy is not None
|
||||
secret = generate_entropy(strength, internal_entropy, EXTERNAL_ENTROPY)
|
||||
|
||||
# validate that all combinations will result in the correct master secret
|
||||
@ -83,12 +86,12 @@ def test_reset_entropy_check(client: Client):
|
||||
|
||||
strength = 128 # 20 words
|
||||
|
||||
with WITH_MOCK_URANDOM, client:
|
||||
with client:
|
||||
IF = InputFlowSlip39BasicResetRecovery(client)
|
||||
client.set_input_flow(IF.get())
|
||||
|
||||
# No PIN, no passphrase.
|
||||
_, path_xpubs = device.reset_entropy_check(
|
||||
path_xpubs = device.setup(
|
||||
client,
|
||||
strength=strength,
|
||||
passphrase_protection=False,
|
||||
@ -96,10 +99,12 @@ def test_reset_entropy_check(client: Client):
|
||||
label="test",
|
||||
backup_type=BackupType.Slip39_Basic,
|
||||
entropy_check_count=3,
|
||||
_get_entropy=MOCK_GET_ENTROPY,
|
||||
)
|
||||
|
||||
# Generate the master secret locally.
|
||||
internal_entropy = client.debug.state().reset_entropy
|
||||
assert internal_entropy is not None
|
||||
secret = generate_entropy(strength, internal_entropy, EXTERNAL_ENTROPY)
|
||||
|
||||
# Check that all combinations will result in the correct master secret.
|
||||
|
@ -37,4 +37,4 @@ def test_solana_get_address(client: Client, parameters, result):
|
||||
client, address_n=parse_path(parameters["path"]), show_display=True
|
||||
)
|
||||
|
||||
assert actual_result.address == result["expected_address"]
|
||||
assert actual_result == result["expected_address"]
|
||||
|
@ -37,4 +37,4 @@ def test_solana_get_public_key(client: Client, parameters, result):
|
||||
client, address_n=parse_path(parameters["path"]), show_display=True
|
||||
)
|
||||
|
||||
assert actual_result.public_key.hex() == result["expected_public_key"]
|
||||
assert actual_result.hex() == result["expected_public_key"]
|
||||
|
@ -70,7 +70,7 @@ def test_solana_sign_tx(client: Client, parameters, result):
|
||||
),
|
||||
)
|
||||
|
||||
assert actual_result.signature == bytes.fromhex(result["expected_signature"])
|
||||
assert actual_result == bytes.fromhex(result["expected_signature"])
|
||||
|
||||
|
||||
def _serialize_tx(tx_construct):
|
||||
|
@ -426,11 +426,4 @@ def test_label_too_long(client: Client):
|
||||
@pytest.mark.models(skip=["legacy", "safe3"])
|
||||
@pytest.mark.setup_client(pin=None)
|
||||
def test_set_brightness(client: Client):
|
||||
with client:
|
||||
assert (
|
||||
device.set_brightness(
|
||||
client,
|
||||
None,
|
||||
)
|
||||
== "Settings applied"
|
||||
)
|
||||
device.set_brightness(client, None)
|
||||
|
@ -54,7 +54,14 @@ def test_autolock_not_retained(client: Client):
|
||||
|
||||
with client:
|
||||
client.use_pin_sequence([PIN4, PIN4])
|
||||
device.reset(client, skip_backup=True, pin_protection=True)
|
||||
device.setup(
|
||||
client,
|
||||
skip_backup=True,
|
||||
pin_protection=True,
|
||||
passphrase_protection=False,
|
||||
entropy_check_count=0,
|
||||
backup_type=messages.BackupType.Bip39,
|
||||
)
|
||||
|
||||
time.sleep(10.5)
|
||||
with client:
|
||||
|
@ -22,7 +22,7 @@ from trezorlib.debuglink import TrezorClientDebugLink as Client
|
||||
from trezorlib.exceptions import TrezorFailure
|
||||
from trezorlib.tools import parse_path
|
||||
|
||||
from ..common import MNEMONIC12, WITH_MOCK_URANDOM, get_test_address, is_core
|
||||
from ..common import MNEMONIC12, MOCK_GET_ENTROPY, get_test_address, is_core
|
||||
from ..tx_cache import TxCache
|
||||
from .bitcoin.signtx import (
|
||||
request_finished,
|
||||
@ -214,24 +214,26 @@ def test_wipe_device(client: Client):
|
||||
def test_reset_device(client: Client):
|
||||
assert client.features.pin_protection is False
|
||||
assert client.features.passphrase_protection is False
|
||||
with WITH_MOCK_URANDOM, client:
|
||||
with client:
|
||||
client.set_expected_responses(
|
||||
[messages.ButtonRequest]
|
||||
+ [messages.EntropyRequest]
|
||||
+ [messages.ButtonRequest] * 24
|
||||
+ [messages.Success, messages.Features]
|
||||
)
|
||||
device.reset(
|
||||
device.setup(
|
||||
client,
|
||||
strength=128,
|
||||
passphrase_protection=True,
|
||||
pin_protection=False,
|
||||
label="label",
|
||||
entropy_check_count=0,
|
||||
_get_entropy=MOCK_GET_ENTROPY,
|
||||
)
|
||||
|
||||
with pytest.raises(TrezorFailure):
|
||||
# This must fail, because device is already initialized
|
||||
# Using direct call because `device.reset` has its own check
|
||||
# Using direct call because `device.setup` has its own check
|
||||
client.call(
|
||||
messages.ResetDevice(
|
||||
strength=128,
|
||||
|
@ -25,7 +25,6 @@ from .. import translations as TR
|
||||
from ..common import (
|
||||
MNEMONIC_SLIP39_SINGLE_EXT_20,
|
||||
TEST_ADDRESS_N,
|
||||
WITH_MOCK_URANDOM,
|
||||
MNEMONIC_SLIP39_BASIC_20_3of6,
|
||||
)
|
||||
from ..input_flows import InputFlowSlip39BasicBackup, InputFlowSlip39BasicRecoveryDryRun
|
||||
@ -34,7 +33,6 @@ pytestmark = pytest.mark.models("core")
|
||||
|
||||
|
||||
@pytest.mark.setup_client(needs_backup=True, mnemonic=MNEMONIC_SLIP39_BASIC_20_3of6)
|
||||
@WITH_MOCK_URANDOM
|
||||
def test_repeated_backup(client: Client):
|
||||
assert client.features.backup_availability == messages.BackupAvailability.Required
|
||||
assert client.features.recovery_status == messages.RecoveryStatus.Nothing
|
||||
@ -63,8 +61,7 @@ def test_repeated_backup(client: Client):
|
||||
client, mnemonics[:3], unlock_repeated_backup=True
|
||||
)
|
||||
client.set_input_flow(IF.get())
|
||||
ret = device.recover(client, type=messages.RecoveryType.UnlockRepeatedBackup)
|
||||
assert ret == messages.Success(message="Backup unlocked")
|
||||
device.recover(client, type=messages.RecoveryType.UnlockRepeatedBackup)
|
||||
assert (
|
||||
client.features.backup_availability == messages.BackupAvailability.Available
|
||||
)
|
||||
@ -86,7 +83,6 @@ def test_repeated_backup(client: Client):
|
||||
|
||||
|
||||
@pytest.mark.setup_client(mnemonic=MNEMONIC_SLIP39_SINGLE_EXT_20)
|
||||
@WITH_MOCK_URANDOM
|
||||
def test_repeated_backup_upgrade_single(client: Client):
|
||||
assert (
|
||||
client.features.backup_availability == messages.BackupAvailability.NotAvailable
|
||||
@ -100,8 +96,7 @@ def test_repeated_backup_upgrade_single(client: Client):
|
||||
client, MNEMONIC_SLIP39_SINGLE_EXT_20, unlock_repeated_backup=True
|
||||
)
|
||||
client.set_input_flow(IF.get())
|
||||
ret = device.recover(client, type=messages.RecoveryType.UnlockRepeatedBackup)
|
||||
assert ret == messages.Success(message="Backup unlocked")
|
||||
device.recover(client, type=messages.RecoveryType.UnlockRepeatedBackup)
|
||||
assert (
|
||||
client.features.backup_availability == messages.BackupAvailability.Available
|
||||
)
|
||||
@ -125,7 +120,6 @@ def test_repeated_backup_upgrade_single(client: Client):
|
||||
|
||||
|
||||
@pytest.mark.setup_client(needs_backup=True, mnemonic=MNEMONIC_SLIP39_BASIC_20_3of6)
|
||||
@WITH_MOCK_URANDOM
|
||||
def test_repeated_backup_cancel(client: Client):
|
||||
assert client.features.backup_availability == messages.BackupAvailability.Required
|
||||
assert client.features.recovery_status == messages.RecoveryStatus.Nothing
|
||||
@ -154,8 +148,7 @@ def test_repeated_backup_cancel(client: Client):
|
||||
client, mnemonics[:3], unlock_repeated_backup=True
|
||||
)
|
||||
client.set_input_flow(IF.get())
|
||||
ret = device.recover(client, type=messages.RecoveryType.UnlockRepeatedBackup)
|
||||
assert ret == messages.Success(message="Backup unlocked")
|
||||
device.recover(client, type=messages.RecoveryType.UnlockRepeatedBackup)
|
||||
assert (
|
||||
client.features.backup_availability == messages.BackupAvailability.Available
|
||||
)
|
||||
@ -181,7 +174,6 @@ def test_repeated_backup_cancel(client: Client):
|
||||
|
||||
|
||||
@pytest.mark.setup_client(needs_backup=True, mnemonic=MNEMONIC_SLIP39_BASIC_20_3of6)
|
||||
@WITH_MOCK_URANDOM
|
||||
def test_repeated_backup_send_disallowed_message(client: Client):
|
||||
assert client.features.backup_availability == messages.BackupAvailability.Required
|
||||
assert client.features.recovery_status == messages.RecoveryStatus.Nothing
|
||||
@ -210,8 +202,7 @@ def test_repeated_backup_send_disallowed_message(client: Client):
|
||||
client, mnemonics[:3], unlock_repeated_backup=True
|
||||
)
|
||||
client.set_input_flow(IF.get())
|
||||
ret = device.recover(client, type=messages.RecoveryType.UnlockRepeatedBackup)
|
||||
assert ret == messages.Success(message="Backup unlocked")
|
||||
device.recover(client, type=messages.RecoveryType.UnlockRepeatedBackup)
|
||||
assert (
|
||||
client.features.backup_availability == messages.BackupAvailability.Available
|
||||
)
|
||||
|
@ -208,12 +208,14 @@ def test_upgrade_reset(gen: str, tag: str):
|
||||
assert not client.features.no_backup
|
||||
|
||||
with EmulatorWrapper(gen, tag) as emu:
|
||||
device.reset(
|
||||
device.setup(
|
||||
emu.client,
|
||||
strength=STRENGTH,
|
||||
passphrase_protection=False,
|
||||
pin_protection=False,
|
||||
label=LABEL,
|
||||
entropy_check_count=0,
|
||||
backup_type=BackupType.Bip39,
|
||||
)
|
||||
device_id = emu.client.features.device_id
|
||||
asserts(emu.client)
|
||||
@ -238,13 +240,15 @@ def test_upgrade_reset_skip_backup(gen: str, tag: str):
|
||||
assert not client.features.no_backup
|
||||
|
||||
with EmulatorWrapper(gen, tag) as emu:
|
||||
device.reset(
|
||||
device.setup(
|
||||
emu.client,
|
||||
strength=STRENGTH,
|
||||
passphrase_protection=False,
|
||||
pin_protection=False,
|
||||
label=LABEL,
|
||||
skip_backup=True,
|
||||
entropy_check_count=0,
|
||||
backup_type=BackupType.Bip39,
|
||||
)
|
||||
device_id = emu.client.features.device_id
|
||||
asserts(emu.client)
|
||||
@ -269,14 +273,17 @@ def test_upgrade_reset_no_backup(gen: str, tag: str):
|
||||
assert client.features.no_backup
|
||||
|
||||
with EmulatorWrapper(gen, tag) as emu:
|
||||
device.reset(
|
||||
device.setup(
|
||||
emu.client,
|
||||
strength=STRENGTH,
|
||||
passphrase_protection=False,
|
||||
pin_protection=False,
|
||||
label=LABEL,
|
||||
no_backup=True,
|
||||
entropy_check_count=0,
|
||||
backup_type=BackupType.Bip39,
|
||||
)
|
||||
|
||||
device_id = emu.client.features.device_id
|
||||
asserts(emu.client)
|
||||
address = btc.get_address(emu.client, "Bitcoin", PATH)
|
||||
@ -344,11 +351,12 @@ def test_upgrade_shamir_recovery(gen: str, tag: Optional[str]):
|
||||
def test_upgrade_shamir_backup(gen: str, tag: Optional[str]):
|
||||
with EmulatorWrapper(gen, tag) as emu:
|
||||
# Generate a new encrypted master secret and record it.
|
||||
device.reset(
|
||||
device.setup(
|
||||
emu.client,
|
||||
pin_protection=False,
|
||||
skip_backup=True,
|
||||
backup_type=BackupType.Slip39_Basic,
|
||||
entropy_check_count=0,
|
||||
)
|
||||
device_id = emu.client.features.device_id
|
||||
backup_type = emu.client.features.backup_type
|
||||
@ -414,8 +422,7 @@ def test_upgrade_u2f(gen: str, tag: str):
|
||||
label=LABEL,
|
||||
)
|
||||
|
||||
success = fido.set_counter(emu.client, 10)
|
||||
assert "U2F counter set" in success
|
||||
fido.set_counter(emu.client, 10)
|
||||
|
||||
counter = fido.get_next_counter(emu.client)
|
||||
assert counter == 11
|
||||
|
@ -46,10 +46,12 @@ mapping.DEFAULT_MAPPING.register(ApplySettingsCompat)
|
||||
def emulator(gen: str, tag: str) -> Iterator[Emulator]:
|
||||
with EmulatorWrapper(gen, tag) as emu:
|
||||
# set up a passphrase-protected device
|
||||
device.reset(
|
||||
device.setup(
|
||||
emu.client,
|
||||
pin_protection=False,
|
||||
skip_backup=True,
|
||||
entropy_check_count=0,
|
||||
backup_type=messages.BackupType.Bip39,
|
||||
)
|
||||
resp = emu.client.call(
|
||||
ApplySettingsCompat(use_passphrase=True, passphrase_source=SOURCE_HOST)
|
||||
|
Loading…
Reference in New Issue
Block a user