2019-10-18 11:36:08 +00:00
|
|
|
# This file is part of the Trezor project.
|
|
|
|
#
|
|
|
|
# Copyright (C) 2012-2019 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>.
|
|
|
|
|
2019-10-22 11:55:17 +00:00
|
|
|
import pytest
|
|
|
|
|
2019-10-18 11:36:08 +00:00
|
|
|
from trezorlib import device
|
|
|
|
|
|
|
|
from .. import buttons
|
2019-11-11 10:07:23 +00:00
|
|
|
from ..click_tests import recovery
|
|
|
|
from ..common import MNEMONIC_SLIP39_ADVANCED_20, MNEMONIC_SLIP39_BASIC_20_3of6
|
2019-10-18 11:36:08 +00:00
|
|
|
from ..device_handler import BackgroundDeviceHandler
|
|
|
|
from ..emulators import EmulatorWrapper
|
2019-10-25 12:04:05 +00:00
|
|
|
from ..upgrade_tests import core_only
|
2019-10-18 11:36:08 +00:00
|
|
|
|
|
|
|
|
2019-10-22 11:55:17 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def emulator():
|
2020-01-23 17:41:25 +00:00
|
|
|
with EmulatorWrapper("core") as emu:
|
2019-10-22 11:55:17 +00:00
|
|
|
yield emu
|
2019-10-18 11:36:08 +00:00
|
|
|
|
|
|
|
|
2020-01-23 17:41:25 +00:00
|
|
|
def _restart(device_handler, emulator):
|
2019-11-11 10:07:23 +00:00
|
|
|
device_handler.restart(emulator)
|
|
|
|
return device_handler.debuglink()
|
|
|
|
|
|
|
|
|
2019-10-22 11:55:17 +00:00
|
|
|
@core_only
|
2019-11-11 10:07:23 +00:00
|
|
|
def test_abort(emulator):
|
2019-10-22 11:55:17 +00:00
|
|
|
device_handler = BackgroundDeviceHandler(emulator.client)
|
|
|
|
debug = device_handler.debuglink()
|
|
|
|
features = device_handler.features()
|
|
|
|
|
|
|
|
assert features.recovery_mode is False
|
2019-10-18 11:36:08 +00:00
|
|
|
|
2019-10-22 11:55:17 +00:00
|
|
|
device_handler.run(device.recover, pin_protection=False)
|
|
|
|
layout = debug.wait_layout()
|
|
|
|
assert layout.text.startswith("Recovery mode")
|
2019-10-18 11:36:08 +00:00
|
|
|
|
2019-10-22 11:55:17 +00:00
|
|
|
layout = debug.click(buttons.OK, wait=True)
|
|
|
|
assert "Select number of words" in layout.text
|
2019-10-18 11:36:08 +00:00
|
|
|
|
2019-10-22 11:55:17 +00:00
|
|
|
device_handler.restart(emulator)
|
|
|
|
debug = device_handler.debuglink()
|
|
|
|
features = device_handler.features()
|
2019-10-18 11:36:08 +00:00
|
|
|
|
2019-10-22 11:55:17 +00:00
|
|
|
assert features.recovery_mode is True
|
2019-10-18 11:36:08 +00:00
|
|
|
|
2019-10-22 11:55:17 +00:00
|
|
|
# no waiting for layout because layout doesn't change
|
|
|
|
layout = debug.read_layout()
|
|
|
|
assert "Select number of words" in layout.text
|
|
|
|
layout = debug.click(buttons.CANCEL, wait=True)
|
2019-10-18 11:36:08 +00:00
|
|
|
|
2019-10-22 11:55:17 +00:00
|
|
|
assert layout.text.startswith("Abort recovery")
|
|
|
|
layout = debug.click(buttons.OK, wait=True)
|
2019-10-18 11:36:08 +00:00
|
|
|
|
2019-10-22 11:55:17 +00:00
|
|
|
assert layout.text == "Homescreen"
|
|
|
|
features = device_handler.features()
|
|
|
|
assert features.recovery_mode is False
|
2019-11-11 10:07:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
@core_only
|
|
|
|
def test_recovery_single_reset(emulator):
|
|
|
|
device_handler = BackgroundDeviceHandler(emulator.client)
|
|
|
|
debug = device_handler.debuglink()
|
|
|
|
features = device_handler.features()
|
|
|
|
|
|
|
|
assert features.initialized is False
|
|
|
|
assert features.recovery_mode is False
|
|
|
|
|
|
|
|
device_handler.run(device.recover, pin_protection=False)
|
|
|
|
recovery.confirm_recovery(debug)
|
|
|
|
|
|
|
|
recovery.select_number_of_words(debug)
|
|
|
|
|
|
|
|
debug = _restart(device_handler, emulator)
|
|
|
|
features = device_handler.features()
|
|
|
|
assert features.recovery_mode is True
|
|
|
|
|
|
|
|
# we need to enter the number of words again, that's a feature
|
|
|
|
recovery.select_number_of_words(debug)
|
|
|
|
recovery.enter_shares(debug, MNEMONIC_SLIP39_BASIC_20_3of6)
|
|
|
|
recovery.finalize(debug)
|
|
|
|
|
|
|
|
features = device_handler.features()
|
|
|
|
assert features.initialized is True
|
|
|
|
assert features.recovery_mode is False
|
|
|
|
|
|
|
|
|
|
|
|
@core_only
|
|
|
|
def test_recovery_multiple_resets(emulator):
|
|
|
|
def enter_shares_with_restarts(debug):
|
|
|
|
shares = MNEMONIC_SLIP39_ADVANCED_20
|
|
|
|
layout = debug.read_layout()
|
|
|
|
expected_text = "Enter any share"
|
|
|
|
remaining = len(shares)
|
|
|
|
for share in shares:
|
|
|
|
assert expected_text in layout.text
|
|
|
|
layout = recovery.enter_share(debug, share)
|
|
|
|
remaining -= 1
|
|
|
|
expected_text = "Success You have entered"
|
|
|
|
debug = _restart(device_handler, emulator)
|
|
|
|
|
|
|
|
assert "You have successfully recovered your wallet" in layout.text
|
|
|
|
|
|
|
|
device_handler = BackgroundDeviceHandler(emulator.client)
|
|
|
|
debug = device_handler.debuglink()
|
|
|
|
features = device_handler.features()
|
|
|
|
|
|
|
|
assert features.initialized is False
|
|
|
|
assert features.recovery_mode is False
|
|
|
|
|
|
|
|
# start device and recovery
|
|
|
|
device_handler.run(device.recover, pin_protection=False)
|
|
|
|
recovery.confirm_recovery(debug)
|
|
|
|
|
|
|
|
# set number of words
|
|
|
|
recovery.select_number_of_words(debug)
|
|
|
|
|
|
|
|
# restart
|
|
|
|
debug = _restart(device_handler, emulator)
|
|
|
|
features = device_handler.features()
|
|
|
|
assert features.recovery_mode is True
|
|
|
|
|
|
|
|
# enter the number of words again, that's a feature!
|
|
|
|
recovery.select_number_of_words(debug)
|
|
|
|
|
|
|
|
# enter shares and restart after each one
|
|
|
|
enter_shares_with_restarts(debug)
|
|
|
|
debug = device_handler.debuglink()
|
|
|
|
layout = debug.read_layout()
|
|
|
|
assert layout.text == "Homescreen"
|
|
|
|
|
|
|
|
features = device_handler.features()
|
|
|
|
assert features.initialized is True
|
|
|
|
assert features.recovery_mode is False
|