mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-17 13:12:05 +00:00
tests: nitpicks in resetdevice_skipbackup, add resetdevice_nobackup
This commit is contained in:
parent
d859fe36f7
commit
3424f01ae7
@ -0,0 +1,57 @@
|
|||||||
|
# This file is part of the Trezor project.
|
||||||
|
#
|
||||||
|
# Copyright (C) 2012-2018 SatoshiLabs and contributors
|
||||||
|
#
|
||||||
|
# This library is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Lesser General Public License version 3
|
||||||
|
# as published by the Free Software Foundation.
|
||||||
|
#
|
||||||
|
# This library is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Lesser General Public License for more details.
|
||||||
|
#
|
||||||
|
# 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>.
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from trezorlib import messages as proto
|
||||||
|
|
||||||
|
from .common import TrezorTest
|
||||||
|
|
||||||
|
|
||||||
|
class TestMsgResetDeviceNobackup(TrezorTest):
|
||||||
|
def test_reset_device_no_backup(self):
|
||||||
|
|
||||||
|
external_entropy = b"zlutoucky kun upel divoke ody" * 2
|
||||||
|
strength = 128
|
||||||
|
|
||||||
|
ret = self.client.call_raw(
|
||||||
|
proto.ResetDevice(
|
||||||
|
display_random=False,
|
||||||
|
strength=strength,
|
||||||
|
passphrase_protection=False,
|
||||||
|
pin_protection=False,
|
||||||
|
language="english",
|
||||||
|
label="test",
|
||||||
|
no_backup=True,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
# Provide entropy
|
||||||
|
assert isinstance(ret, proto.EntropyRequest)
|
||||||
|
internal_entropy = self.client.debug.read_reset_entropy()
|
||||||
|
ret = self.client.call_raw(proto.EntropyAck(entropy=external_entropy))
|
||||||
|
assert isinstance(ret, proto.Success)
|
||||||
|
|
||||||
|
# Check if device is properly initialized
|
||||||
|
ret = self.client.call_raw(proto.Initialize())
|
||||||
|
assert ret.initialized is True
|
||||||
|
assert ret.needs_backup is False
|
||||||
|
assert ret.unfinished_backup is False
|
||||||
|
assert ret.no_backup is True
|
||||||
|
|
||||||
|
# start backup - should fail
|
||||||
|
ret = self.client.call_raw(proto.BackupDevice())
|
||||||
|
assert isinstance(ret, proto.Failure)
|
@ -48,9 +48,11 @@ class TestMsgResetDeviceSkipbackup(TrezorTest):
|
|||||||
assert isinstance(ret, proto.Success)
|
assert isinstance(ret, proto.Success)
|
||||||
|
|
||||||
# Check if device is properly initialized
|
# Check if device is properly initialized
|
||||||
resp = self.client.call_raw(proto.Initialize())
|
ret = self.client.call_raw(proto.Initialize())
|
||||||
assert resp.initialized is True
|
assert ret.initialized is True
|
||||||
assert resp.needs_backup is True
|
assert ret.needs_backup is True
|
||||||
|
assert ret.unfinished_backup is False
|
||||||
|
assert ret.no_backup is False
|
||||||
|
|
||||||
# Generate mnemonic locally
|
# Generate mnemonic locally
|
||||||
entropy = generate_entropy(strength, internal_entropy, external_entropy)
|
entropy = generate_entropy(strength, internal_entropy, external_entropy)
|
||||||
@ -76,9 +78,9 @@ class TestMsgResetDeviceSkipbackup(TrezorTest):
|
|||||||
assert isinstance(ret, proto.ButtonRequest)
|
assert isinstance(ret, proto.ButtonRequest)
|
||||||
mnemonic.append(self.client.debug.read_reset_word())
|
mnemonic.append(self.client.debug.read_reset_word())
|
||||||
self.client.debug.press_yes()
|
self.client.debug.press_yes()
|
||||||
resp = self.client.call_raw(proto.ButtonAck())
|
ret = self.client.call_raw(proto.ButtonAck())
|
||||||
|
|
||||||
assert isinstance(resp, proto.Success)
|
assert isinstance(ret, proto.Success)
|
||||||
|
|
||||||
mnemonic = " ".join(mnemonic)
|
mnemonic = " ".join(mnemonic)
|
||||||
|
|
||||||
@ -112,21 +114,35 @@ class TestMsgResetDeviceSkipbackup(TrezorTest):
|
|||||||
assert isinstance(ret, proto.Success)
|
assert isinstance(ret, proto.Success)
|
||||||
|
|
||||||
# Check if device is properly initialized
|
# Check if device is properly initialized
|
||||||
resp = self.client.call_raw(proto.Initialize())
|
ret = self.client.call_raw(proto.Initialize())
|
||||||
assert resp.initialized is True
|
assert ret.initialized is True
|
||||||
assert resp.needs_backup is True
|
assert ret.needs_backup is True
|
||||||
|
assert ret.unfinished_backup is False
|
||||||
|
assert ret.no_backup is False
|
||||||
|
|
||||||
# start Backup workflow
|
# start Backup workflow
|
||||||
ret = self.client.call_raw(proto.BackupDevice())
|
ret = self.client.call_raw(proto.BackupDevice())
|
||||||
|
|
||||||
# send Initialize -> break workflow
|
# send Initialize -> break workflow
|
||||||
ret = self.client.call_raw(proto.Initialize())
|
ret = self.client.call_raw(proto.Initialize())
|
||||||
assert isinstance(resp, proto.Features)
|
assert isinstance(ret, proto.Features)
|
||||||
|
assert ret.initialized is True
|
||||||
|
assert ret.needs_backup is False
|
||||||
|
assert ret.unfinished_backup is True
|
||||||
|
assert ret.no_backup is False
|
||||||
|
|
||||||
# start backup again - should fail
|
# start backup again - should fail
|
||||||
ret = self.client.call_raw(proto.BackupDevice())
|
ret = self.client.call_raw(proto.BackupDevice())
|
||||||
assert isinstance(ret, proto.Failure)
|
assert isinstance(ret, proto.Failure)
|
||||||
|
|
||||||
|
# read Features again
|
||||||
|
ret = self.client.call_raw(proto.Initialize())
|
||||||
|
assert isinstance(ret, proto.Features)
|
||||||
|
assert ret.initialized is True
|
||||||
|
assert ret.needs_backup is False
|
||||||
|
assert ret.unfinished_backup is True
|
||||||
|
assert ret.no_backup is False
|
||||||
|
|
||||||
def test_initialized_device_backup_fail(self):
|
def test_initialized_device_backup_fail(self):
|
||||||
self.setup_mnemonic_nopin_nopassphrase()
|
self.setup_mnemonic_nopin_nopassphrase()
|
||||||
ret = self.client.call_raw(proto.BackupDevice())
|
ret = self.client.call_raw(proto.BackupDevice())
|
||||||
|
Loading…
Reference in New Issue
Block a user