1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-04-25 11:39:02 +00:00

tests: update shamir tests for setup_client markers

This commit is contained in:
matejcik 2019-08-28 17:05:01 +02:00
parent 8e1d5374b1
commit 122f6c8085
4 changed files with 34 additions and 31 deletions

View File

@ -67,6 +67,7 @@ def enter_all_shares(debug, shares):
debug.press_yes() debug.press_yes()
@pytest.mark.setup_client(uninitialized=True)
def test_recover_no_pin_no_passphrase(client): def test_recover_no_pin_no_passphrase(client):
debug = client.debug debug = client.debug
@ -89,6 +90,7 @@ def test_recover_no_pin_no_passphrase(client):
assert client.features.passphrase_protection is False assert client.features.passphrase_protection is False
@pytest.mark.setup_client(uninitialized=True)
def test_abort(client): def test_abort(client):
debug = client.debug debug = client.debug
@ -108,6 +110,7 @@ def test_abort(client):
assert client.features.initialized is False assert client.features.initialized is False
@pytest.mark.setup_client(uninitialized=True)
def test_noabort(client): def test_noabort(client):
debug = client.debug debug = client.debug

View File

@ -3,8 +3,6 @@ import pytest
from trezorlib import device, messages from trezorlib import device, messages
from trezorlib.exceptions import TrezorFailure from trezorlib.exceptions import TrezorFailure
from .conftest import setup_client
pytestmark = pytest.mark.skip_t1 pytestmark = pytest.mark.skip_t1
SHARES_20_2of3_2of3_GROUPS = [ SHARES_20_2of3_2of3_GROUPS = [
@ -23,7 +21,7 @@ INVALID_SHARES_20_2of3_2of3_GROUPS = [
] ]
@setup_client(mnemonic=SHARES_20_2of3_2of3_GROUPS[1:5], passphrase=False) @pytest.mark.setup_client(mnemonic=SHARES_20_2of3_2of3_GROUPS[1:5], passphrase=False)
def test_2of3_dryrun(client): def test_2of3_dryrun(client):
debug = client.debug debug = client.debug
@ -50,7 +48,7 @@ def test_2of3_dryrun(client):
) )
@setup_client(mnemonic=SHARES_20_2of3_2of3_GROUPS[1:5], passphrase=True) @pytest.mark.setup_client(mnemonic=SHARES_20_2of3_2of3_GROUPS[1:5], passphrase=True)
def test_2of3_invalid_seed_dryrun(client): def test_2of3_invalid_seed_dryrun(client):
debug = client.debug debug = client.debug

View File

@ -14,7 +14,8 @@ EXTERNAL_ENTROPY = b"zlutoucky kun upel divoke ody" * 2
@pytest.mark.skip_t1 @pytest.mark.skip_t1
class TestMsgResetDeviceT2(TrezorTest): class TestMsgResetDeviceT2(TrezorTest):
# TODO: test with different options # TODO: test with different options
def test_reset_device_supershamir(self): @pytest.mark.setup_client(uninitialized=True)
def test_reset_device_supershamir(self, client):
strength = 128 strength = 128
member_threshold = 3 member_threshold = 3
all_mnemonics = [] all_mnemonics = []
@ -23,53 +24,53 @@ class TestMsgResetDeviceT2(TrezorTest):
# Confirm Reset # Confirm Reset
btn_code = yield btn_code = yield
assert btn_code == B.ResetDevice assert btn_code == B.ResetDevice
self.client.debug.press_yes() client.debug.press_yes()
# Backup your seed # Backup your seed
btn_code = yield btn_code = yield
assert btn_code == B.ResetDevice assert btn_code == B.ResetDevice
self.client.debug.press_yes() client.debug.press_yes()
# Confirm warning # Confirm warning
btn_code = yield btn_code = yield
assert btn_code == B.ResetDevice assert btn_code == B.ResetDevice
self.client.debug.press_yes() client.debug.press_yes()
# shares info # shares info
btn_code = yield btn_code = yield
assert btn_code == B.ResetDevice assert btn_code == B.ResetDevice
self.client.debug.press_yes() client.debug.press_yes()
# Set & Confirm number of groups # Set & Confirm number of groups
btn_code = yield btn_code = yield
assert btn_code == B.ResetDevice assert btn_code == B.ResetDevice
self.client.debug.press_yes() client.debug.press_yes()
# threshold info # threshold info
btn_code = yield btn_code = yield
assert btn_code == B.ResetDevice assert btn_code == B.ResetDevice
self.client.debug.press_yes() client.debug.press_yes()
# Set & confirm group threshold value # Set & confirm group threshold value
btn_code = yield btn_code = yield
assert btn_code == B.ResetDevice assert btn_code == B.ResetDevice
self.client.debug.press_yes() client.debug.press_yes()
for _ in range(5): for _ in range(5):
# Set & Confirm number of share # Set & Confirm number of share
btn_code = yield btn_code = yield
assert btn_code == B.ResetDevice assert btn_code == B.ResetDevice
self.client.debug.press_yes() client.debug.press_yes()
# Set & confirm share threshold value # Set & confirm share threshold value
btn_code = yield btn_code = yield
assert btn_code == B.ResetDevice assert btn_code == B.ResetDevice
self.client.debug.press_yes() client.debug.press_yes()
# Confirm show seeds # Confirm show seeds
btn_code = yield btn_code = yield
assert btn_code == B.ResetDevice assert btn_code == B.ResetDevice
self.client.debug.press_yes() client.debug.press_yes()
# show & confirm shares for all groups # show & confirm shares for all groups
for g in range(5): for g in range(5):
@ -81,33 +82,33 @@ class TestMsgResetDeviceT2(TrezorTest):
# mnemonic phrases # mnemonic phrases
# 20 word over 6 pages for strength 128, 33 words over 9 pages for strength 256 # 20 word over 6 pages for strength 128, 33 words over 9 pages for strength 256
for i in range(6): for i in range(6):
words.extend(self.client.debug.read_reset_word().split()) words.extend(client.debug.read_reset_word().split())
if i < 5: if i < 5:
self.client.debug.swipe_down() client.debug.swipe_down()
else: else:
# last page is confirmation # last page is confirmation
self.client.debug.press_yes() client.debug.press_yes()
# check share # check share
for _ in range(3): for _ in range(3):
index = self.client.debug.read_reset_word_pos() index = client.debug.read_reset_word_pos()
self.client.debug.input(words[index]) client.debug.input(words[index])
all_mnemonics.extend([" ".join(words)]) all_mnemonics.extend([" ".join(words)])
# Confirm continue to next share # Confirm continue to next share
btn_code = yield btn_code = yield
assert btn_code == B.Success assert btn_code == B.Success
self.client.debug.press_yes() client.debug.press_yes()
# safety warning # safety warning
btn_code = yield btn_code = yield
assert btn_code == B.Success assert btn_code == B.Success
self.client.debug.press_yes() client.debug.press_yes()
os_urandom = mock.Mock(return_value=EXTERNAL_ENTROPY) os_urandom = mock.Mock(return_value=EXTERNAL_ENTROPY)
with mock.patch("os.urandom", os_urandom), self.client: with mock.patch("os.urandom", os_urandom), client:
self.client.set_expected_responses( client.set_expected_responses(
[ [
proto.ButtonRequest(code=B.ResetDevice), proto.ButtonRequest(code=B.ResetDevice),
proto.EntropyRequest(), proto.EntropyRequest(),
@ -193,11 +194,11 @@ class TestMsgResetDeviceT2(TrezorTest):
proto.Features(), proto.Features(),
] ]
) )
self.client.set_input_flow(input_flow) client.set_input_flow(input_flow)
# No PIN, no passphrase, don't display random # No PIN, no passphrase, don't display random
device.reset( device.reset(
self.client, client,
display_random=False, display_random=False,
strength=strength, strength=strength,
passphrase_protection=False, passphrase_protection=False,
@ -208,17 +209,17 @@ class TestMsgResetDeviceT2(TrezorTest):
) )
# generate secret locally # generate secret locally
internal_entropy = self.client.debug.state().reset_entropy internal_entropy = client.debug.state().reset_entropy
secret = generate_entropy(strength, internal_entropy, EXTERNAL_ENTROPY) secret = generate_entropy(strength, internal_entropy, EXTERNAL_ENTROPY)
# validate that all combinations will result in the correct master secret # validate that all combinations will result in the correct master secret
validate_mnemonics(all_mnemonics, member_threshold, secret) validate_mnemonics(all_mnemonics, member_threshold, secret)
# Check if device is properly initialized # Check if device is properly initialized
assert self.client.features.initialized is True assert client.features.initialized is True
assert self.client.features.needs_backup is False assert client.features.needs_backup is False
assert self.client.features.pin_protection is False assert client.features.pin_protection is False
assert self.client.features.passphrase_protection is False assert client.features.passphrase_protection is False
def validate_mnemonics(mnemonics, threshold, expected_ems): def validate_mnemonics(mnemonics, threshold, expected_ems):

View File

@ -6,6 +6,7 @@ from trezorlib.tools import parse_path
@pytest.mark.skip_t1 @pytest.mark.skip_t1
@pytest.mark.setup_client(uninitialized=True)
def test_reset_recovery(client): def test_reset_recovery(client):
mnemonics = reset(client) mnemonics = reset(client)
address_before = btc.get_address(client, "Bitcoin", parse_path("44'/0'/0'/0/0")) address_before = btc.get_address(client, "Bitcoin", parse_path("44'/0'/0'/0/0"))