1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-13 19:18:56 +00:00

tests: nitpicks in resetdevice_skipbackup, add resetdevice_nobackup

This commit is contained in:
Pavol Rusnak 2018-10-04 17:37:49 +02:00
parent d859fe36f7
commit 3424f01ae7
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
2 changed files with 82 additions and 9 deletions

View File

@ -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)

View File

@ -48,9 +48,11 @@ class TestMsgResetDeviceSkipbackup(TrezorTest):
assert isinstance(ret, proto.Success)
# Check if device is properly initialized
resp = self.client.call_raw(proto.Initialize())
assert resp.initialized is True
assert resp.needs_backup is True
ret = self.client.call_raw(proto.Initialize())
assert ret.initialized is True
assert ret.needs_backup is True
assert ret.unfinished_backup is False
assert ret.no_backup is False
# Generate mnemonic locally
entropy = generate_entropy(strength, internal_entropy, external_entropy)
@ -76,9 +78,9 @@ class TestMsgResetDeviceSkipbackup(TrezorTest):
assert isinstance(ret, proto.ButtonRequest)
mnemonic.append(self.client.debug.read_reset_word())
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)
@ -112,21 +114,35 @@ class TestMsgResetDeviceSkipbackup(TrezorTest):
assert isinstance(ret, proto.Success)
# Check if device is properly initialized
resp = self.client.call_raw(proto.Initialize())
assert resp.initialized is True
assert resp.needs_backup is True
ret = self.client.call_raw(proto.Initialize())
assert ret.initialized is True
assert ret.needs_backup is True
assert ret.unfinished_backup is False
assert ret.no_backup is False
# start Backup workflow
ret = self.client.call_raw(proto.BackupDevice())
# send Initialize -> break workflow
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
ret = self.client.call_raw(proto.BackupDevice())
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):
self.setup_mnemonic_nopin_nopassphrase()
ret = self.client.call_raw(proto.BackupDevice())