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

tests: improve clicktests

This commit is contained in:
matejcik 2019-11-15 15:54:16 +01:00
parent 9e33d69607
commit 40a2c2ce93
3 changed files with 136 additions and 129 deletions

View File

@ -0,0 +1,4 @@
import pytest
pytest.register_assert_rewrite("tests.click_tests.reset")
pytest.register_assert_rewrite("tests.click_tests.recovery")

View File

@ -35,21 +35,24 @@ def read_words(debug, is_advanced=False):
assert layout.text.startswith("Group") assert layout.text.startswith("Group")
else: else:
assert layout.text.startswith("Recovery share") assert layout.text.startswith("Recovery share")
for i in range(6):
lines = debug.read_layout().lines lines = layout.lines
if i == 0: # first screen
words.append(read_word(lines[3])) words.append(read_word(lines[3]))
words.append(read_word(lines[4])) words.append(read_word(lines[4]))
debug.input(swipe=messages.DebugSwipeDirection.UP, wait=True) lines = debug.input(swipe=messages.DebugSwipeDirection.UP, wait=True).lines
elif i == 5:
words.append(read_word(lines[1])) # screens 2 through
words.append(read_word(lines[2])) for _ in range(4):
else: words.append(read_word(lines[1]))
words.append(read_word(lines[1])) words.append(read_word(lines[2]))
words.append(read_word(lines[2])) words.append(read_word(lines[3]))
words.append(read_word(lines[3])) words.append(read_word(lines[4]))
words.append(read_word(lines[4])) lines = debug.input(swipe=messages.DebugSwipeDirection.UP, wait=True).lines
debug.input(swipe=messages.DebugSwipeDirection.UP, wait=True)
# final screen
words.append(read_word(lines[1]))
words.append(read_word(lines[2]))
debug.press_yes() debug.press_yes()
return words return words
@ -57,11 +60,13 @@ def read_words(debug, is_advanced=False):
def confirm_words(debug, words): def confirm_words(debug, words):
layout = debug.wait_layout() layout = debug.wait_layout()
layout.text.startswith("Check share") assert "Select word" in layout.text
for _ in range(3): for _ in range(3):
word_pos = int(debug.state().layout_lines[1].split()[2]) # "Select word 3 of 20"
button_pos = debug.state().layout_lines.index(words[word_pos - 1]) - 2 # ^
debug.click(buttons.RESET_WORD_CHECK[button_pos], wait=True) word_pos = int(layout.lines[1].split()[2])
button_pos = layout.lines.index(words[word_pos - 1]) - 2
layout = debug.click(buttons.RESET_WORD_CHECK[button_pos], wait=True)
def validate_mnemonics(mnemonics, expected_ems): def validate_mnemonics(mnemonics, expected_ems):

View File

@ -26,168 +26,166 @@ from . import reset
EXTERNAL_ENTROPY = b"zlutoucky kun upel divoke ody" * 2 EXTERNAL_ENTROPY = b"zlutoucky kun upel divoke ody" * 2
with_mock_urandom = mock.patch("os.urandom", mock.Mock(return_value=EXTERNAL_ENTROPY))
@pytest.mark.skip_t1 @pytest.mark.skip_t1
@pytest.mark.setup_client(uninitialized=True) @pytest.mark.setup_client(uninitialized=True)
@with_mock_urandom
def test_reset_slip39_advanced_2of2groups_2of2shares(device_handler): def test_reset_slip39_advanced_2of2groups_2of2shares(device_handler):
features = device_handler.features() features = device_handler.features()
debug = device_handler.debuglink() debug = device_handler.debuglink()
assert features.initialized is False assert features.initialized is False
os_urandom = mock.Mock(return_value=EXTERNAL_ENTROPY) device_handler.run(
with mock.patch("os.urandom", os_urandom), device_handler: device.reset,
device_handler.run( backup_type=messages.BackupType.Slip39_Advanced,
device.reset, pin_protection=False,
strength=128, )
backup_type=messages.BackupType.Slip39_Advanced,
pin_protection=False,
)
# confirm new wallet # confirm new wallet
reset.confirm_wait(debug, "Create new wallet") reset.confirm_wait(debug, "Create new wallet")
# confirm back up # confirm back up
reset.confirm_wait(debug, "Success") reset.confirm_wait(debug, "Success")
# confirm checklist # confirm checklist
reset.confirm_read(debug, "Checklist") reset.confirm_read(debug, "Checklist")
# set num of groups # set num of groups
reset.set_selection(debug, buttons.RESET_MINUS, 3)
# confirm checklist
reset.confirm_read(debug, "Checklist")
# set group threshold
reset.set_selection(debug, buttons.RESET_MINUS, 0)
# confirm checklist
reset.confirm_read(debug, "Checklist")
# set share num and threshold for groups
for _ in range(2):
# set num of shares
reset.set_selection(debug, buttons.RESET_MINUS, 3) reset.set_selection(debug, buttons.RESET_MINUS, 3)
# confirm checklist # set share threshold
reset.confirm_read(debug, "Checklist")
# set group threshold
reset.set_selection(debug, buttons.RESET_MINUS, 0) reset.set_selection(debug, buttons.RESET_MINUS, 0)
# confirm checklist # confirm backup warning
reset.confirm_read(debug, "Checklist") reset.confirm_read(debug, "Caution")
# set share num and threshold for groups all_words = []
for _ in range(2):
for _ in range(2): for _ in range(2):
# set num of shares # read words
reset.set_selection(debug, buttons.RESET_MINUS, 3) words = reset.read_words(debug, True)
# set share threshold # confirm words
reset.set_selection(debug, buttons.RESET_MINUS, 0) reset.confirm_words(debug, words)
# confirm backup warning # confirm share checked
reset.confirm_read(debug, "Caution") reset.confirm_read(debug, "Success")
all_words = [] all_words.append(" ".join(words))
for _ in range(2):
for _ in range(2):
# read words
words = reset.read_words(debug, True)
# confirm words # confirm backup done
reset.confirm_words(debug, words) reset.confirm_read(debug, "Success")
# confirm share checked # generate secret locally
reset.confirm_read(debug, "Success") internal_entropy = debug.state().reset_entropy
secret = generate_entropy(128, internal_entropy, EXTERNAL_ENTROPY)
all_words.append(" ".join(words)) # validate that all combinations will result in the correct master secret
reset.validate_mnemonics(all_words, secret)
# confirm backup done assert device_handler.result() == "Initialized"
reset.confirm_read(debug, "Success")
# generate secret locally features = device_handler.features()
internal_entropy = debug.state().reset_entropy assert features.initialized is True
secret = generate_entropy(128, internal_entropy, EXTERNAL_ENTROPY) assert features.needs_backup is False
assert features.pin_protection is False
# validate that all combinations will result in the correct master secret assert features.passphrase_protection is False
reset.validate_mnemonics(all_words, secret) assert features.backup_type is messages.BackupType.Slip39_Advanced
assert device_handler.result() == "Initialized"
features = device_handler.features()
assert features.initialized is True
assert features.needs_backup is False
assert features.pin_protection is False
assert features.passphrase_protection is False
assert features.backup_type is messages.BackupType.Slip39_Advanced
@pytest.mark.skip_t1 @pytest.mark.skip_t1
@pytest.mark.setup_client(uninitialized=True) @pytest.mark.setup_client(uninitialized=True)
@with_mock_urandom
def test_reset_slip39_advanced_16of16groups_16of16shares(device_handler): def test_reset_slip39_advanced_16of16groups_16of16shares(device_handler):
features = device_handler.features() features = device_handler.features()
debug = device_handler.debuglink() debug = device_handler.debuglink()
assert features.initialized is False assert features.initialized is False
os_urandom = mock.Mock(return_value=EXTERNAL_ENTROPY) device_handler.run(
with mock.patch("os.urandom", os_urandom), device_handler: device.reset,
device_handler.run( backup_type=messages.BackupType.Slip39_Advanced,
device.reset, pin_protection=False,
strength=128, )
backup_type=messages.BackupType.Slip39_Advanced,
pin_protection=False,
)
# confirm new wallet # confirm new wallet
reset.confirm_wait(debug, "Create new wallet") reset.confirm_wait(debug, "Create new wallet")
# confirm back up # confirm back up
reset.confirm_wait(debug, "Success") reset.confirm_wait(debug, "Success")
# confirm checklist # confirm checklist
reset.confirm_read(debug, "Checklist") reset.confirm_read(debug, "Checklist")
# set num of groups # set num of groups
reset.set_selection(debug, buttons.RESET_PLUS, 11)
# confirm checklist
reset.confirm_read(debug, "Checklist")
# set group threshold
reset.set_selection(debug, buttons.RESET_PLUS, 11)
# confirm checklist
reset.confirm_read(debug, "Checklist")
# set share num and threshold for groups
for _ in range(16):
# set num of shares
reset.set_selection(debug, buttons.RESET_PLUS, 11) reset.set_selection(debug, buttons.RESET_PLUS, 11)
# confirm checklist # set share threshold
reset.confirm_read(debug, "Checklist")
# set group threshold
reset.set_selection(debug, buttons.RESET_PLUS, 11) reset.set_selection(debug, buttons.RESET_PLUS, 11)
# confirm checklist # confirm backup warning
reset.confirm_read(debug, "Checklist") reset.confirm_read(debug, "Caution")
# set share num and threshold for groups all_words = []
for _ in range(16):
for _ in range(16): for _ in range(16):
# set num of shares # read words
reset.set_selection(debug, buttons.RESET_PLUS, 11) words = reset.read_words(debug, True)
# set share threshold # confirm words
reset.set_selection(debug, buttons.RESET_PLUS, 11) reset.confirm_words(debug, words)
# confirm backup warning # confirm share checked
reset.confirm_read(debug, "Caution") reset.confirm_read(debug, "Success")
all_words = [] all_words.append(" ".join(words))
for _ in range(16):
for _ in range(16):
# read words
words = reset.read_words(debug, True)
# confirm words # confirm backup done
reset.confirm_words(debug, words) reset.confirm_read(debug, "Success")
# confirm share checked # generate secret locally
reset.confirm_read(debug, "Success") internal_entropy = debug.state().reset_entropy
secret = generate_entropy(128, internal_entropy, EXTERNAL_ENTROPY)
all_words.append(" ".join(words)) # validate that all combinations will result in the correct master secret
reset.validate_mnemonics(all_words, secret)
# confirm backup done assert device_handler.result() == "Initialized"
reset.confirm_read(debug, "Success")
# generate secret locally features = device_handler.features()
internal_entropy = debug.state().reset_entropy assert features.initialized is True
secret = generate_entropy(128, internal_entropy, EXTERNAL_ENTROPY) assert features.needs_backup is False
assert features.pin_protection is False
# validate that all combinations will result in the correct master secret assert features.passphrase_protection is False
reset.validate_mnemonics(all_words, secret) assert features.backup_type is messages.BackupType.Slip39_Advanced
assert device_handler.result() == "Initialized"
features = device_handler.features()
assert features.initialized is True
assert features.needs_backup is False
assert features.pin_protection is False
assert features.passphrase_protection is False
assert features.backup_type is messages.BackupType.Slip39_Advanced