Skip to content

Commit

Permalink
re-enable shamir mnemonic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ciny committed Jul 22, 2019
1 parent e344eea commit 5d01390
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 63 deletions.
83 changes: 45 additions & 38 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions python/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
ecdsa>=0.9
mnemonic>=0.17
shamir-mnemonic>=0.1.0
requests>=2.4.0
click>=7,<8
pyblake2>=0.9.3
Expand Down
2 changes: 1 addition & 1 deletion python/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ combine_as_imports = True
line_length = 88
not_skip=__init__.py
known_first_party=trezorlib
known_third_party=hidapi, rlp, ethjsonrpc, ecdsa, mnemonic, requests, click, pyblake2, \
known_third_party=hidapi, rlp, ethjsonrpc, ecdsa, mnemonic, shamir-mnemonic, requests, click, pyblake2, \
usb, construct, pytest
1 change: 1 addition & 0 deletions python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"setuptools>=19.0",
"ecdsa>=0.9",
"mnemonic>=0.17",
"shamir-mnemonic>=0.1.0",
"requests>=2.4.0",
"click>=7,<8",
"pyblake2>=0.9.3",
Expand Down
43 changes: 19 additions & 24 deletions python/trezorlib/tests/device_tests/test_msg_resetdevice_shamir.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import time
from itertools import combinations
from unittest import mock

import pytest
import shamir_mnemonic as shamir
from shamir_mnemonic import MnemonicError

from trezorlib import device, messages as proto
from trezorlib.messages import ButtonRequestType as B

from .common import TrezorTest

# TODO: uncomment when python_shamir_mnemonic is uploaded to pypi
# import shamir_mnemonic as shamir
# from shamir_mnemonic import MnemonicError

from .common import TrezorTest, generate_entropy

EXTERNAL_ENTROPY = b"zlutoucky kun upel divoke ody" * 2

Expand All @@ -21,8 +19,7 @@ class TestMsgResetDeviceT2(TrezorTest):
# TODO: test with different options
def test_reset_device_shamir(self):
strength = 128
# TODO: uncomment when python_shamir_mnemonic is uploaded to pypi
# member_threshold = 2
member_threshold = 3

def input_flow():
# Confirm Reset
Expand Down Expand Up @@ -97,11 +94,11 @@ def input_flow():
self.client.debug.press_yes()

# generate secret locally
# internal_entropy = self.client.debug.state().reset_entropy
# secret = generate_entropy(strength, internal_entropy, EXTERNAL_ENTROPY)
internal_entropy = self.client.debug.state().reset_entropy
secret = generate_entropy(strength, internal_entropy, EXTERNAL_ENTROPY)

# 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)

# safety warning
btn_code = yield
Expand Down Expand Up @@ -158,16 +155,14 @@ def input_flow():
assert resp.passphrase_protection is False


# TODO: uncomment when python_shamir_mnemonic is uploaded to pypi

# def validate_mnemonics(mnemonics, threshold, expected_secret):
# # We expect these combinations to recreate the secret properly
# for test_group in combinations(mnemonics, threshold):
# secret = shamir.combine_mnemonics(test_group)
# assert secret == expected_secret
# # We expect these combinations to raise MnemonicError
# for test_group in combinations(mnemonics, threshold - 1):
# with pytest.raises(
# MnemonicError, match=r".*Expected {} mnemonics.*".format(threshold)
# ):
# secret = shamir.combine_mnemonics(test_group)
def validate_mnemonics(mnemonics, threshold, expected_secret):
# We expect these combinations to recreate the secret properly
for test_group in combinations(mnemonics, threshold):
secret = shamir.combine_mnemonics(test_group)
assert secret == expected_secret
# We expect these combinations to raise MnemonicError
for test_group in combinations(mnemonics, threshold - 1):
with pytest.raises(
MnemonicError, match=r".*Expected {} mnemonics.*".format(threshold)
):
secret = shamir.combine_mnemonics(test_group)

0 comments on commit 5d01390

Please sign in to comment.