From 3424f01ae77fad98aaa52bf53e6bd74a3a81ac30 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Thu, 4 Oct 2018 17:37:49 +0200 Subject: [PATCH] tests: nitpicks in resetdevice_skipbackup, add resetdevice_nobackup --- .../test_msg_resetdevice_nobackup.py | 57 +++++++++++++++++++ .../test_msg_resetdevice_skipbackup.py | 34 ++++++++--- 2 files changed, 82 insertions(+), 9 deletions(-) create mode 100644 trezorlib/tests/device_tests/test_msg_resetdevice_nobackup.py diff --git a/trezorlib/tests/device_tests/test_msg_resetdevice_nobackup.py b/trezorlib/tests/device_tests/test_msg_resetdevice_nobackup.py new file mode 100644 index 000000000..8fa2b8263 --- /dev/null +++ b/trezorlib/tests/device_tests/test_msg_resetdevice_nobackup.py @@ -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 . + +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) diff --git a/trezorlib/tests/device_tests/test_msg_resetdevice_skipbackup.py b/trezorlib/tests/device_tests/test_msg_resetdevice_skipbackup.py index 2c34831ce..11e7b91cf 100644 --- a/trezorlib/tests/device_tests/test_msg_resetdevice_skipbackup.py +++ b/trezorlib/tests/device_tests/test_msg_resetdevice_skipbackup.py @@ -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())