mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-29 02:48:18 +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")
|
@expect(proto.Success, field="message")
|
||||||
def load_device_by_mnemonic(
|
def load_device(
|
||||||
client,
|
client,
|
||||||
mnemonic,
|
mnemonic,
|
||||||
pin,
|
pin,
|
||||||
@ -458,6 +458,8 @@ def load_device_by_mnemonic(
|
|||||||
label,
|
label,
|
||||||
language="english",
|
language="english",
|
||||||
skip_checksum=False,
|
skip_checksum=False,
|
||||||
|
needs_backup=False,
|
||||||
|
no_backup=False,
|
||||||
):
|
):
|
||||||
if not isinstance(mnemonic, (list, tuple)):
|
if not isinstance(mnemonic, (list, tuple)):
|
||||||
mnemonic = [mnemonic]
|
mnemonic = [mnemonic]
|
||||||
@ -477,12 +479,18 @@ def load_device_by_mnemonic(
|
|||||||
language=language,
|
language=language,
|
||||||
label=label,
|
label=label,
|
||||||
skip_checksum=skip_checksum,
|
skip_checksum=skip_checksum,
|
||||||
|
needs_backup=needs_backup,
|
||||||
|
no_backup=no_backup,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
client.init_device()
|
client.init_device()
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
|
|
||||||
|
# keep the old name for compatibility
|
||||||
|
load_device_by_mnemonic = load_device
|
||||||
|
|
||||||
|
|
||||||
@expect(proto.Success, field="message")
|
@expect(proto.Success, field="message")
|
||||||
def self_test(client):
|
def self_test(client):
|
||||||
if client.features.bootloader_mode is not True:
|
if client.features.bootloader_mode is not True:
|
||||||
|
@ -97,6 +97,8 @@ def client(request):
|
|||||||
mnemonic=" ".join(["all"] * 12),
|
mnemonic=" ".join(["all"] * 12),
|
||||||
pin=None,
|
pin=None,
|
||||||
passphrase=False,
|
passphrase=False,
|
||||||
|
needs_backup=False,
|
||||||
|
no_backup=False,
|
||||||
)
|
)
|
||||||
# fmt: on
|
# fmt: on
|
||||||
|
|
||||||
@ -108,18 +110,23 @@ def client(request):
|
|||||||
if setup_params["pin"] is True:
|
if setup_params["pin"] is True:
|
||||||
setup_params["pin"] = "1234"
|
setup_params["pin"] = "1234"
|
||||||
|
|
||||||
debuglink.load_device_by_mnemonic(
|
debuglink.load_device(
|
||||||
client,
|
client,
|
||||||
mnemonic=setup_params["mnemonic"],
|
mnemonic=setup_params["mnemonic"],
|
||||||
pin=setup_params["pin"],
|
pin=setup_params["pin"],
|
||||||
passphrase_protection=setup_params["passphrase"],
|
passphrase_protection=setup_params["passphrase"],
|
||||||
label="test",
|
label="test",
|
||||||
language="english",
|
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":
|
if setup_params["passphrase"] and client.features.model != "1":
|
||||||
apply_settings(client, passphrase_source=PASSPHRASE_ON_HOST)
|
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()
|
client.open()
|
||||||
yield client
|
yield client
|
||||||
client.close()
|
client.close()
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from trezorlib import debuglink, messages
|
from trezorlib import messages
|
||||||
|
|
||||||
from ..common import MNEMONIC12
|
from ..common import MNEMONIC12
|
||||||
|
|
||||||
@ -27,18 +27,8 @@ class TestDebuglink:
|
|||||||
layout = client.debug.state().layout
|
layout = client.debug.state().layout
|
||||||
assert len(layout) == 1024
|
assert len(layout) == 1024
|
||||||
|
|
||||||
# mnemonic_secret is not available when the device is locked, and the client fixture
|
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
|
||||||
# locks the device after initialization.
|
|
||||||
# It is easier to request an unintialized client and load it manually.
|
|
||||||
@pytest.mark.setup_client(uninitialized=True)
|
|
||||||
def test_mnemonic(self, client):
|
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
|
mnemonic = client.debug.state().mnemonic_secret
|
||||||
assert mnemonic == MNEMONIC12.encode()
|
assert mnemonic == MNEMONIC12.encode()
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ from ..common import (
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.skip_t1 # TODO we want this for t1 too
|
@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):
|
def test_backup_bip39(client):
|
||||||
assert client.features.needs_backup is True
|
assert client.features.needs_backup is True
|
||||||
mnemonic = None
|
mnemonic = None
|
||||||
@ -71,7 +71,7 @@ def test_backup_bip39(client):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.skip_t1
|
@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):
|
def test_backup_slip39_basic(client):
|
||||||
assert client.features.needs_backup is True
|
assert client.features.needs_backup is True
|
||||||
mnemonics = []
|
mnemonics = []
|
||||||
@ -136,7 +136,7 @@ def test_backup_slip39_basic(client):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.skip_t1
|
@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):
|
def test_backup_slip39_advanced(client):
|
||||||
assert client.features.needs_backup is True
|
assert client.features.needs_backup is True
|
||||||
mnemonics = []
|
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
|
# 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):
|
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.initialized is True
|
||||||
assert client.features.no_backup is True
|
assert client.features.no_backup is True
|
||||||
assert client.features.needs_backup is False
|
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
|
# 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):
|
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.initialized is True
|
||||||
assert client.features.needs_backup is True
|
assert client.features.needs_backup is True
|
||||||
assert client.features.unfinished_backup is False
|
assert client.features.unfinished_backup is False
|
||||||
|
@ -30,7 +30,7 @@ from ..common import (
|
|||||||
@pytest.mark.setup_client(uninitialized=True)
|
@pytest.mark.setup_client(uninitialized=True)
|
||||||
class TestDeviceLoad:
|
class TestDeviceLoad:
|
||||||
def test_load_device_1(self, client):
|
def test_load_device_1(self, client):
|
||||||
debuglink.load_device_by_mnemonic(
|
debuglink.load_device(
|
||||||
client,
|
client,
|
||||||
mnemonic=MNEMONIC12,
|
mnemonic=MNEMONIC12,
|
||||||
pin="",
|
pin="",
|
||||||
@ -46,7 +46,7 @@ class TestDeviceLoad:
|
|||||||
assert address == "1EfKbQupktEMXf4gujJ9kCFo83k1iMqwqK"
|
assert address == "1EfKbQupktEMXf4gujJ9kCFo83k1iMqwqK"
|
||||||
|
|
||||||
def test_load_device_2(self, client):
|
def test_load_device_2(self, client):
|
||||||
debuglink.load_device_by_mnemonic(
|
debuglink.load_device(
|
||||||
client,
|
client,
|
||||||
mnemonic=MNEMONIC12,
|
mnemonic=MNEMONIC12,
|
||||||
pin="1234",
|
pin="1234",
|
||||||
@ -69,7 +69,7 @@ class TestDeviceLoad:
|
|||||||
|
|
||||||
@pytest.mark.skip_t1
|
@pytest.mark.skip_t1
|
||||||
def test_load_device_slip39_basic(self, client):
|
def test_load_device_slip39_basic(self, client):
|
||||||
debuglink.load_device_by_mnemonic(
|
debuglink.load_device(
|
||||||
client,
|
client,
|
||||||
mnemonic=MNEMONIC_SLIP39_BASIC_20_3of6,
|
mnemonic=MNEMONIC_SLIP39_BASIC_20_3of6,
|
||||||
pin="",
|
pin="",
|
||||||
@ -80,7 +80,7 @@ class TestDeviceLoad:
|
|||||||
|
|
||||||
@pytest.mark.skip_t1
|
@pytest.mark.skip_t1
|
||||||
def test_load_device_slip39_advanced(self, client):
|
def test_load_device_slip39_advanced(self, client):
|
||||||
debuglink.load_device_by_mnemonic(
|
debuglink.load_device(
|
||||||
client,
|
client,
|
||||||
mnemonic=MNEMONIC_SLIP39_ADVANCED_20,
|
mnemonic=MNEMONIC_SLIP39_ADVANCED_20,
|
||||||
pin="",
|
pin="",
|
||||||
@ -109,7 +109,7 @@ class TestDeviceLoad:
|
|||||||
)
|
)
|
||||||
|
|
||||||
device.wipe(client)
|
device.wipe(client)
|
||||||
debuglink.load_device_by_mnemonic(
|
debuglink.load_device(
|
||||||
client,
|
client,
|
||||||
mnemonic=words_nfkd,
|
mnemonic=words_nfkd,
|
||||||
pin="",
|
pin="",
|
||||||
@ -124,7 +124,7 @@ class TestDeviceLoad:
|
|||||||
address_nfkd = btc.get_address(client, "Bitcoin", [])
|
address_nfkd = btc.get_address(client, "Bitcoin", [])
|
||||||
|
|
||||||
device.wipe(client)
|
device.wipe(client)
|
||||||
debuglink.load_device_by_mnemonic(
|
debuglink.load_device(
|
||||||
client,
|
client,
|
||||||
mnemonic=words_nfc,
|
mnemonic=words_nfc,
|
||||||
pin="",
|
pin="",
|
||||||
@ -139,7 +139,7 @@ class TestDeviceLoad:
|
|||||||
address_nfc = btc.get_address(client, "Bitcoin", [])
|
address_nfc = btc.get_address(client, "Bitcoin", [])
|
||||||
|
|
||||||
device.wipe(client)
|
device.wipe(client)
|
||||||
debuglink.load_device_by_mnemonic(
|
debuglink.load_device(
|
||||||
client,
|
client,
|
||||||
mnemonic=words_nfkc,
|
mnemonic=words_nfkc,
|
||||||
pin="",
|
pin="",
|
||||||
@ -154,7 +154,7 @@ class TestDeviceLoad:
|
|||||||
address_nfkc = btc.get_address(client, "Bitcoin", [])
|
address_nfkc = btc.get_address(client, "Bitcoin", [])
|
||||||
|
|
||||||
device.wipe(client)
|
device.wipe(client)
|
||||||
debuglink.load_device_by_mnemonic(
|
debuglink.load_device(
|
||||||
client,
|
client,
|
||||||
mnemonic=words_nfd,
|
mnemonic=words_nfd,
|
||||||
pin="",
|
pin="",
|
||||||
|
@ -75,7 +75,7 @@ def test_wipe(client):
|
|||||||
assert client.features.sd_protection is False
|
assert client.features.sd_protection is False
|
||||||
|
|
||||||
# Restore device to working status
|
# Restore device to working status
|
||||||
debuglink.load_device_by_mnemonic(
|
debuglink.load_device(
|
||||||
client, mnemonic=MNEMONIC12, pin=None, passphrase_protection=False, label="test"
|
client, mnemonic=MNEMONIC12, pin=None, passphrase_protection=False, label="test"
|
||||||
)
|
)
|
||||||
assert client.features.sd_protection is False
|
assert client.features.sd_protection is False
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
import pytest
|
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 trezorlib.exceptions import TrezorFailure
|
||||||
|
|
||||||
from ..common import MNEMONIC12
|
from ..common import MNEMONIC12
|
||||||
@ -106,36 +106,6 @@ class TestProtectionLevels:
|
|||||||
)
|
)
|
||||||
device.wipe(client)
|
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)
|
@pytest.mark.setup_client(uninitialized=True)
|
||||||
def test_reset_device(self, client):
|
def test_reset_device(self, client):
|
||||||
with client:
|
with client:
|
||||||
|
Loading…
Reference in New Issue
Block a user