1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-27 08:38:07 +00:00
trezor-firmware/tests/device_tests/test_msg_recoverydevice_bip39_t2.py

131 lines
3.9 KiB
Python
Raw Normal View History

# This file is part of the Trezor project.
2018-03-22 14:27:43 +00:00
#
2019-05-29 16:44:09 +00:00
# Copyright (C) 2012-2019 SatoshiLabs and contributors
2018-03-22 14:27:43 +00:00
#
# 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.
2018-03-22 14:27:43 +00:00
#
# 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>.
2018-03-22 14:27:43 +00:00
import pytest
from trezorlib import device, exceptions, messages
2018-08-13 16:21:24 +00:00
2019-09-11 12:43:32 +00:00
from ..common import MNEMONIC12
2018-03-22 14:27:43 +00:00
pytestmark = pytest.mark.skip_t1
2018-03-22 14:27:43 +00:00
@pytest.mark.setup_client(uninitialized=True)
def test_tt_pin_passphrase(client):
layout = client.debug.wait_layout
mnemonic = MNEMONIC12.split(" ")
def input_flow():
yield
assert "Do you really want to recover a wallet?" in layout().text
client.debug.press_yes()
yield
assert layout().text == "PinDialog"
client.debug.input("654")
2019-07-11 14:52:25 +00:00
yield
assert layout().text == "PinDialog"
client.debug.input("654")
2019-07-11 14:52:25 +00:00
yield
assert "Select number of words" in layout().text
client.debug.press_yes()
2019-07-11 14:52:25 +00:00
yield
assert "WordSelector" in layout().text
client.debug.input(str(len(mnemonic)))
2018-03-22 14:27:43 +00:00
yield
assert "Enter recovery seed" in layout().text
client.debug.press_yes()
2019-07-11 14:52:25 +00:00
yield
2018-03-22 14:27:43 +00:00
for word in mnemonic:
assert layout().text == "Bip39Keyboard"
client.debug.input(word)
2018-03-22 14:27:43 +00:00
yield
assert "You have successfully recovered your wallet." in layout().text
client.debug.press_yes()
with client:
client.set_input_flow(input_flow)
client.watch_layout()
device.recover(
client, pin_protection=True, passphrase_protection=True, label="hello"
2018-08-13 16:21:24 +00:00
)
2018-03-22 14:27:43 +00:00
assert client.debug.state().mnemonic_secret.decode() == MNEMONIC12
assert client.features.pin_protection is True
assert client.features.passphrase_protection is True
assert client.features.backup_type is messages.BackupType.Bip39
assert client.features.label == "hello"
@pytest.mark.setup_client(uninitialized=True)
def test_tt_nopin_nopassphrase(client):
layout = client.debug.wait_layout
mnemonic = MNEMONIC12.split(" ")
def input_flow():
yield
assert "Do you really want to recover a wallet?" in layout().text
client.debug.press_yes()
yield
assert "Select number of words" in layout().text
client.debug.press_yes()
2019-07-11 14:52:25 +00:00
yield
assert "WordSelector" in layout().text
client.debug.input(str(len(mnemonic)))
2018-03-22 14:27:43 +00:00
yield
assert "Enter recovery seed" in layout().text
client.debug.press_yes()
2019-07-11 14:52:25 +00:00
yield
2018-03-22 14:27:43 +00:00
for word in mnemonic:
assert layout().text == "Bip39Keyboard"
client.debug.input(word)
2018-03-22 14:27:43 +00:00
yield
assert "You have successfully recovered your wallet." in layout().text
client.debug.press_yes()
with client:
client.set_input_flow(input_flow)
client.watch_layout()
device.recover(
client, pin_protection=False, passphrase_protection=False, label="hello"
)
assert client.debug.state().mnemonic_secret.decode() == MNEMONIC12
assert client.features.pin_protection is False
assert client.features.passphrase_protection is False
assert client.features.backup_type is messages.BackupType.Bip39
assert client.features.label == "hello"
2018-03-22 14:27:43 +00:00
def test_already_initialized(client):
with pytest.raises(RuntimeError):
device.recover(client)
2018-03-22 14:27:43 +00:00
with pytest.raises(exceptions.TrezorFailure, match="Already initialized"):
client.call(messages.RecoveryDevice())