tests: improve layout_lines API

pull/632/head
matejcik 5 years ago
parent 598e828844
commit c970ad437d

@ -14,6 +14,7 @@
# 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>.
from collections import namedtuple
from copy import deepcopy
from mnemonic import Mnemonic
@ -25,6 +26,13 @@ from .tools import expect
EXPECTED_RESPONSES_CONTEXT_LINES = 3
LayoutLines = namedtuple("LayoutLines", "lines text")
def layout_lines(lines):
return LayoutLines(lines, " ".join(lines))
class DebugLink:
def __init__(self, transport, auto_interact=True):
self.transport = transport
@ -46,9 +54,12 @@ class DebugLink:
def state(self):
return self._call(proto.DebugLinkGetState())
def read_layout(self):
return layout_lines(self.state().layout_lines)
def wait_layout(self):
obj = self._call(proto.DebugLinkGetState(wait_layout=True))
return obj.layout_lines
return layout_lines(obj.layout_lines)
def read_pin(self):
state = self.state()
@ -100,7 +111,7 @@ class DebugLink:
)
ret = self._call(decision, nowait=not wait)
if ret is not None:
return ret.lines
return layout_lines(ret.lines)
def click(self, click, wait=False):
x, y = click

@ -1,3 +1,19 @@
# 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>.
import pytest
from trezorlib import device, messages
@ -10,11 +26,7 @@ def enter_word(debug, word):
word = word[:4]
for coords in buttons.type_word(word):
debug.click(coords)
return " ".join(debug.click(buttons.CONFIRM_WORD, wait=True))
def click_ok(debug):
return " ".join(debug.click(buttons.OK, wait=True))
return debug.click(buttons.CONFIRM_WORD, wait=True)
@pytest.mark.skip_t1
@ -27,36 +39,36 @@ def test_recovery(device_handler):
device_handler.run(device.recover, pin_protection=False)
# select number of words
text = " ".join(debug.wait_layout())
assert text.startswith("Recovery mode")
text = click_ok(debug)
layout = debug.wait_layout()
assert layout.text.startswith("Recovery mode")
layout = debug.click(buttons.OK, wait=True)
assert "Select number of words" in text
text = click_ok(debug)
assert "Select number of words" in layout.text
layout = debug.click(buttons.OK, wait=True)
assert text == "WordSelector"
assert layout.text == "WordSelector"
# click "20" at 2, 2
coords = buttons.grid34(2, 2)
lines = debug.click(coords, wait=True)
text = " ".join(lines)
layout = " ".join(lines)
expected_text = "Enter any share (20 words)"
remaining = len(MNEMONIC_SLIP39_BASIC_20_3of6)
for share in MNEMONIC_SLIP39_BASIC_20_3of6:
assert expected_text in text
text = click_ok(debug)
assert expected_text in layout.text
layout = debug.click(buttons.OK, wait=True)
assert text == "Slip39Keyboard"
assert layout.text == "Slip39Keyboard"
for word in share.split(" "):
text = enter_word(debug, word)
layout = enter_word(debug, word)
remaining -= 1
expected_text = "RecoveryHomescreen {} more".format(remaining)
assert "You have successfully recovered your wallet" in text
text = click_ok(debug)
assert "You have successfully recovered your wallet" in layout.text
layout = debug.click(buttons.OK, wait=True)
assert text == "Homescreen"
assert layout.text == "Homescreen"
assert isinstance(device_handler.result(), messages.Success)
features = device_handler.features()

Loading…
Cancel
Save