mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-25 08:58:14 +00:00
tests: make {needs,no}_backup flags available in test suite
This commit is contained in:
parent
d9c581b95b
commit
862e582ec1
@ -450,7 +450,7 @@ class TrezorClientDebugLink(TrezorClient):
|
||||
|
||||
|
||||
@expect(proto.Success, field="message")
|
||||
def load_device_by_mnemonic(
|
||||
def load_device(
|
||||
client,
|
||||
mnemonic,
|
||||
pin,
|
||||
@ -458,6 +458,8 @@ def load_device_by_mnemonic(
|
||||
label,
|
||||
language="english",
|
||||
skip_checksum=False,
|
||||
needs_backup=False,
|
||||
no_backup=False,
|
||||
):
|
||||
if not isinstance(mnemonic, (list, tuple)):
|
||||
mnemonic = [mnemonic]
|
||||
@ -477,12 +479,18 @@ def load_device_by_mnemonic(
|
||||
language=language,
|
||||
label=label,
|
||||
skip_checksum=skip_checksum,
|
||||
needs_backup=needs_backup,
|
||||
no_backup=no_backup,
|
||||
)
|
||||
)
|
||||
client.init_device()
|
||||
return resp
|
||||
|
||||
|
||||
# keep the old name for compatibility
|
||||
load_device_by_mnemonic = load_device
|
||||
|
||||
|
||||
@expect(proto.Success, field="message")
|
||||
def self_test(client):
|
||||
if client.features.bootloader_mode is not True:
|
||||
|
@ -97,6 +97,8 @@ def client(request):
|
||||
mnemonic=" ".join(["all"] * 12),
|
||||
pin=None,
|
||||
passphrase=False,
|
||||
needs_backup=False,
|
||||
no_backup=False,
|
||||
)
|
||||
# fmt: on
|
||||
|
||||
@ -108,18 +110,23 @@ def client(request):
|
||||
if setup_params["pin"] is True:
|
||||
setup_params["pin"] = "1234"
|
||||
|
||||
debuglink.load_device_by_mnemonic(
|
||||
debuglink.load_device(
|
||||
client,
|
||||
mnemonic=setup_params["mnemonic"],
|
||||
pin=setup_params["pin"],
|
||||
passphrase_protection=setup_params["passphrase"],
|
||||
label="test",
|
||||
language="english",
|
||||
needs_backup=setup_params["needs_backup"],
|
||||
no_backup=setup_params["no_backup"],
|
||||
)
|
||||
client.clear_session()
|
||||
if setup_params["passphrase"] and client.features.model != "1":
|
||||
apply_settings(client, passphrase_source=PASSPHRASE_ON_HOST)
|
||||
|
||||
if setup_params["pin"]:
|
||||
# ClearSession locks the device. We only do that if the PIN is set.
|
||||
client.clear_session()
|
||||
|
||||
client.open()
|
||||
yield client
|
||||
client.close()
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
import pytest
|
||||
|
||||
from trezorlib import debuglink, messages
|
||||
from trezorlib import messages
|
||||
|
||||
from ..common import MNEMONIC12
|
||||
|
||||
@ -27,18 +27,8 @@ class TestDebuglink:
|
||||
layout = client.debug.state().layout
|
||||
assert len(layout) == 1024
|
||||
|
||||
# mnemonic_secret is not available when the device is locked, and the client fixture
|
||||
# locks the device after initialization.
|
||||
# It is easier to request an unintialized client and load it manually.
|
||||
@pytest.mark.setup_client(uninitialized=True)
|
||||
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
|
||||
def test_mnemonic(self, client):
|
||||
debuglink.load_device_by_mnemonic(
|
||||
client,
|
||||
mnemonic=MNEMONIC12,
|
||||
pin="",
|
||||
passphrase_protection=False,
|
||||
label="test",
|
||||
)
|
||||
mnemonic = client.debug.state().mnemonic_secret
|
||||
assert mnemonic == MNEMONIC12.encode()
|
||||
|
||||
|
@ -32,7 +32,7 @@ from ..common import (
|
||||
|
||||
|
||||
@pytest.mark.skip_t1 # TODO we want this for t1 too
|
||||
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
|
||||
@pytest.mark.setup_client(needs_backup=True, mnemonic=MNEMONIC12)
|
||||
def test_backup_bip39(client):
|
||||
assert client.features.needs_backup is True
|
||||
mnemonic = None
|
||||
@ -71,7 +71,7 @@ def test_backup_bip39(client):
|
||||
|
||||
|
||||
@pytest.mark.skip_t1
|
||||
@pytest.mark.setup_client(mnemonic=MNEMONIC_SLIP39_BASIC_20_3of6)
|
||||
@pytest.mark.setup_client(needs_backup=True, mnemonic=MNEMONIC_SLIP39_BASIC_20_3of6)
|
||||
def test_backup_slip39_basic(client):
|
||||
assert client.features.needs_backup is True
|
||||
mnemonics = []
|
||||
@ -136,7 +136,7 @@ def test_backup_slip39_basic(client):
|
||||
|
||||
|
||||
@pytest.mark.skip_t1
|
||||
@pytest.mark.setup_client(mnemonic=MNEMONIC_SLIP39_ADVANCED_20)
|
||||
@pytest.mark.setup_client(needs_backup=True, mnemonic=MNEMONIC_SLIP39_ADVANCED_20)
|
||||
def test_backup_slip39_advanced(client):
|
||||
assert client.features.needs_backup is True
|
||||
mnemonics = []
|
||||
@ -257,19 +257,8 @@ def test_backup_slip39_advanced(client):
|
||||
|
||||
|
||||
# we only test this with bip39 because the code path is always the same
|
||||
@pytest.mark.setup_client(uninitialized=True)
|
||||
@pytest.mark.setup_client(no_backup=True)
|
||||
def test_no_backup_fails(client):
|
||||
device.reset(
|
||||
client,
|
||||
display_random=False,
|
||||
strength=128,
|
||||
passphrase_protection=False,
|
||||
pin_protection=False,
|
||||
label="test",
|
||||
language="english",
|
||||
no_backup=True,
|
||||
)
|
||||
|
||||
assert client.features.initialized is True
|
||||
assert client.features.no_backup is True
|
||||
assert client.features.needs_backup is False
|
||||
@ -280,19 +269,8 @@ def test_no_backup_fails(client):
|
||||
|
||||
|
||||
# we only test this with bip39 because the code path is always the same
|
||||
@pytest.mark.setup_client(uninitialized=True)
|
||||
@pytest.mark.setup_client(needs_backup=True)
|
||||
def test_interrupt_backup_fails(client):
|
||||
device.reset(
|
||||
client,
|
||||
display_random=False,
|
||||
strength=128,
|
||||
passphrase_protection=False,
|
||||
pin_protection=False,
|
||||
label="test",
|
||||
language="english",
|
||||
skip_backup=True,
|
||||
)
|
||||
|
||||
assert client.features.initialized is True
|
||||
assert client.features.needs_backup is True
|
||||
assert client.features.unfinished_backup is False
|
||||
|
@ -30,7 +30,7 @@ from ..common import (
|
||||
@pytest.mark.setup_client(uninitialized=True)
|
||||
class TestDeviceLoad:
|
||||
def test_load_device_1(self, client):
|
||||
debuglink.load_device_by_mnemonic(
|
||||
debuglink.load_device(
|
||||
client,
|
||||
mnemonic=MNEMONIC12,
|
||||
pin="",
|
||||
@ -46,7 +46,7 @@ class TestDeviceLoad:
|
||||
assert address == "1EfKbQupktEMXf4gujJ9kCFo83k1iMqwqK"
|
||||
|
||||
def test_load_device_2(self, client):
|
||||
debuglink.load_device_by_mnemonic(
|
||||
debuglink.load_device(
|
||||
client,
|
||||
mnemonic=MNEMONIC12,
|
||||
pin="1234",
|
||||
@ -69,7 +69,7 @@ class TestDeviceLoad:
|
||||
|
||||
@pytest.mark.skip_t1
|
||||
def test_load_device_slip39_basic(self, client):
|
||||
debuglink.load_device_by_mnemonic(
|
||||
debuglink.load_device(
|
||||
client,
|
||||
mnemonic=MNEMONIC_SLIP39_BASIC_20_3of6,
|
||||
pin="",
|
||||
@ -80,7 +80,7 @@ class TestDeviceLoad:
|
||||
|
||||
@pytest.mark.skip_t1
|
||||
def test_load_device_slip39_advanced(self, client):
|
||||
debuglink.load_device_by_mnemonic(
|
||||
debuglink.load_device(
|
||||
client,
|
||||
mnemonic=MNEMONIC_SLIP39_ADVANCED_20,
|
||||
pin="",
|
||||
@ -109,7 +109,7 @@ class TestDeviceLoad:
|
||||
)
|
||||
|
||||
device.wipe(client)
|
||||
debuglink.load_device_by_mnemonic(
|
||||
debuglink.load_device(
|
||||
client,
|
||||
mnemonic=words_nfkd,
|
||||
pin="",
|
||||
@ -124,7 +124,7 @@ class TestDeviceLoad:
|
||||
address_nfkd = btc.get_address(client, "Bitcoin", [])
|
||||
|
||||
device.wipe(client)
|
||||
debuglink.load_device_by_mnemonic(
|
||||
debuglink.load_device(
|
||||
client,
|
||||
mnemonic=words_nfc,
|
||||
pin="",
|
||||
@ -139,7 +139,7 @@ class TestDeviceLoad:
|
||||
address_nfc = btc.get_address(client, "Bitcoin", [])
|
||||
|
||||
device.wipe(client)
|
||||
debuglink.load_device_by_mnemonic(
|
||||
debuglink.load_device(
|
||||
client,
|
||||
mnemonic=words_nfkc,
|
||||
pin="",
|
||||
@ -154,7 +154,7 @@ class TestDeviceLoad:
|
||||
address_nfkc = btc.get_address(client, "Bitcoin", [])
|
||||
|
||||
device.wipe(client)
|
||||
debuglink.load_device_by_mnemonic(
|
||||
debuglink.load_device(
|
||||
client,
|
||||
mnemonic=words_nfd,
|
||||
pin="",
|
||||
|
@ -75,7 +75,7 @@ def test_wipe(client):
|
||||
assert client.features.sd_protection is False
|
||||
|
||||
# Restore device to working status
|
||||
debuglink.load_device_by_mnemonic(
|
||||
debuglink.load_device(
|
||||
client, mnemonic=MNEMONIC12, pin=None, passphrase_protection=False, label="test"
|
||||
)
|
||||
assert client.features.sd_protection is False
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
import pytest
|
||||
|
||||
from trezorlib import btc, debuglink, device, messages as proto, misc
|
||||
from trezorlib import btc, device, messages as proto, misc
|
||||
from trezorlib.exceptions import TrezorFailure
|
||||
|
||||
from ..common import MNEMONIC12
|
||||
@ -106,36 +106,6 @@ class TestProtectionLevels:
|
||||
)
|
||||
device.wipe(client)
|
||||
|
||||
@pytest.mark.setup_client(uninitialized=True)
|
||||
def test_load_device(self, client):
|
||||
with client:
|
||||
client.set_expected_responses(
|
||||
[proto.ButtonRequest(), proto.Success(), proto.Features()]
|
||||
)
|
||||
debuglink.load_device_by_mnemonic(
|
||||
client,
|
||||
"this is mnemonic",
|
||||
"1234",
|
||||
True,
|
||||
"label",
|
||||
"english",
|
||||
skip_checksum=True,
|
||||
)
|
||||
|
||||
with pytest.raises(TrezorFailure):
|
||||
# This must fail, because device is already initialized
|
||||
# Using direct call because `load_device_by_mnemonic` has its own check
|
||||
client.call(
|
||||
proto.LoadDevice(
|
||||
mnemonics="this is mnemonic",
|
||||
pin="1234",
|
||||
passphrase_protection=True,
|
||||
language="english",
|
||||
label="label",
|
||||
skip_checksum=True,
|
||||
)
|
||||
)
|
||||
|
||||
@pytest.mark.setup_client(uninitialized=True)
|
||||
def test_reset_device(self, client):
|
||||
with client:
|
||||
|
Loading…
Reference in New Issue
Block a user