1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-27 16:48:09 +00:00

Renamed unittests for better consistency

This commit is contained in:
slush0 2014-02-21 02:31:34 +01:00
parent 443ffab619
commit c870b65f22
5 changed files with 0 additions and 311 deletions

View File

@ -1,68 +0,0 @@
import unittest
import common
from trezorlib import messages_pb2 as messages
class TestDeviceLoad(common.TrezorTest):
def test_load_device_1(self):
self.setup_mnemonic_nopin_nopassphrase()
mnemonic = self.client.debug.read_mnemonic()
self.assertEqual(mnemonic, self.mnemonic12)
pin = self.client.debug.read_pin()[0]
self.assertEqual(pin, '')
passphrase_protection = self.client.debug.read_passphrase_protection()
self.assertEqual(passphrase_protection, False)
def test_load_device_2(self):
self.setup_mnemonic_pin_passphrase()
mnemonic = self.client.debug.read_mnemonic()
self.assertEqual(mnemonic, self.mnemonic12)
pin = self.client.debug.read_pin()[0]
self.assertEqual(pin, self.pin4)
passphrase_protection = self.client.debug.read_passphrase_protection()
self.assertEqual(passphrase_protection, True)
def test_load_device_utf(self):
words_nfkd = u'Pr\u030ci\u0301s\u030cerne\u030c z\u030clut\u030couc\u030cky\u0301 ku\u030an\u030c u\u0301pe\u030cl d\u030ca\u0301belske\u0301 o\u0301dy za\u0301ker\u030cny\u0301 uc\u030cen\u030c be\u030cz\u030ci\u0301 pode\u0301l zo\u0301ny u\u0301lu\u030a'
words_nfc = u'P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f'
words_nfkc = u'P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f'
words_nfd = u'Pr\u030ci\u0301s\u030cerne\u030c z\u030clut\u030couc\u030cky\u0301 ku\u030an\u030c u\u0301pe\u030cl d\u030ca\u0301belske\u0301 o\u0301dy za\u0301ker\u030cny\u0301 uc\u030cen\u030c be\u030cz\u030ci\u0301 pode\u0301l zo\u0301ny u\u0301lu\u030a'
passphrase_nfkd = u'Neuve\u030cr\u030citelne\u030c bezpec\u030cne\u0301 hesli\u0301c\u030cko'
passphrase_nfc = u'Neuv\u011b\u0159iteln\u011b bezpe\u010dn\xe9 hesl\xed\u010dko'
passphrase_nfkc = u'Neuv\u011b\u0159iteln\u011b bezpe\u010dn\xe9 hesl\xed\u010dko'
passphrase_nfd = u'Neuve\u030cr\u030citelne\u030c bezpec\u030cne\u0301 hesli\u0301c\u030cko'
self.client.wipe_device()
self.client.load_device_by_mnemonic(mnemonic=words_nfkd, pin='', passphrase_protection=True, label='test', language='english', skip_checksum=True)
self.client.set_passphrase(passphrase_nfkd)
address_nfkd = self.client.get_address('Bitcoin', [])
self.client.wipe_device()
self.client.load_device_by_mnemonic(mnemonic=words_nfc, pin='', passphrase_protection=True, label='test', language='english', skip_checksum=True)
self.client.set_passphrase(passphrase_nfc)
address_nfc = self.client.get_address('Bitcoin', [])
self.client.wipe_device()
self.client.load_device_by_mnemonic(mnemonic=words_nfkc, pin='', passphrase_protection=True, label='test', language='english', skip_checksum=True)
self.client.set_passphrase(passphrase_nfkc)
address_nfkc = self.client.get_address('Bitcoin', [])
self.client.wipe_device()
self.client.load_device_by_mnemonic(mnemonic=words_nfd, pin='', passphrase_protection=True, label='test', language='english', skip_checksum=True)
self.client.set_passphrase(passphrase_nfd)
address_nfd = self.client.get_address('Bitcoin', [])
self.assertEqual(address_nfkd, address_nfc)
self.assertEqual(address_nfkd, address_nfkc)
self.assertEqual(address_nfkd, address_nfd)
if __name__ == '__main__':
unittest.main()

View File

@ -1,12 +0,0 @@
import unittest
import common
from trezorlib import messages_pb2 as messages
class TestDeviceRecover(common.TrezorTest):
def test_recover_device(self):
pass
if __name__ == '__main__':
unittest.main()

View File

@ -1,175 +0,0 @@
import unittest
import common
import hashlib
from trezorlib import messages_pb2 as proto
from mnemonic import Mnemonic
def generate_entropy(strength, internal_entropy, external_entropy):
'''
strength - length of produced seed. One of 128, 192, 256
random - binary stream of random data from external HRNG
'''
if strength not in (128, 192, 256):
raise Exception("Invalid strength")
if not internal_entropy:
raise Exception("Internal entropy is not provided")
if len(internal_entropy) < 32:
raise Exception("Internal entropy too short")
if not external_entropy:
raise Exception("External entropy is not provided")
if len(external_entropy) < 32:
raise Exception("External entropy too short")
entropy = hashlib.sha256(internal_entropy + external_entropy).digest()
entropy_stripped = entropy[:strength / 8]
if len(entropy_stripped) * 8 != strength:
raise Exception("Entropy length mismatch")
return entropy_stripped
class TestDeviceReset(common.TrezorTest):
def test_reset_device(self):
# No PIN, no passphrase
external_entropy = 'zlutoucky kun upel divoke ody' * 2
strength = 128
ret = self.client.call_raw(proto.ResetDevice(display_random=False,
strength=strength,
passphrase_protection=False,
pin_protection=False,
language='english',
label='test'))
self.assertIsInstance(ret, proto.ButtonRequest)
self.client.debug.press_yes()
ret = self.client.call_raw(proto.ButtonAck())
self.assertIsInstance(ret, proto.EntropyRequest)
ret = self.client.call_raw(proto.EntropyAck(entropy=external_entropy))
# Read internal entropy and generate mnemonic locally
internal_entropy = self.client.debug.read_entropy()
entropy = generate_entropy(strength, internal_entropy, external_entropy)
expected_mnemonic = Mnemonic('english').to_mnemonic(entropy)
mnemonic = []
for _ in range(12):
self.assertIsInstance(ret, proto.ButtonRequest)
mnemonic.append(self.client.debug.read_word()[0])
self.client.debug.press_yes()
self.client.call_raw(proto.ButtonAck())
mnemonic = ' '.join(mnemonic)
# Compare that device generated proper mnemonic for given entropies
self.assertEqual(mnemonic, expected_mnemonic)
mnemonic = []
for _ in range(12):
self.assertIsInstance(ret, proto.ButtonRequest)
mnemonic.append(self.client.debug.read_word()[0])
self.client.debug.press_yes()
resp = self.client.call_raw(proto.ButtonAck())
self.assertIsInstance(resp, proto.Success)
mnemonic = ' '.join(mnemonic)
# Compare that second pass printed out the same mnemonic once again
self.assertEqual(mnemonic, expected_mnemonic)
# Check if device is properly initialized
resp = self.client.call_raw(proto.Initialize())
self.assertFalse(resp.pin_protection)
self.assertFalse(resp.passphrase_protection)
# Do passphrase-protected action, PassphraseRequest should NOT be raised
resp = self.client.call_raw(proto.Ping(passphrase_protection=True))
self.assertIsInstance(resp, proto.Success)
# Do PIN-protected action, PinRequest should NOT be raised
resp = self.client.call_raw(proto.Ping(pin_protection=True))
self.assertIsInstance(resp, proto.Success)
def test_reset_device_pin(self):
external_entropy = 'zlutoucky kun upel divoke ody' * 2
strength = 128
ret = self.client.call_raw(proto.ResetDevice(display_random=True,
strength=strength,
passphrase_protection=True,
pin_protection=True,
language='english',
label='test'))
self.assertIsInstance(ret, proto.ButtonRequest)
self.client.debug.press_yes()
ret = self.client.call_raw(proto.ButtonAck())
self.assertIsInstance(ret, proto.EntropyRequest)
ret = self.client.call_raw(proto.EntropyAck(entropy=external_entropy))
self.assertIsInstance(ret, proto.PinMatrixRequest)
# Enter PIN for first time
pin_encoded = self.client.debug.encode_pin('654')
ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded))
self.assertIsInstance(ret, proto.PinMatrixRequest)
# Enter PIN for second time
pin_encoded = self.client.debug.encode_pin('654')
ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded))
# Read internal entropy and generate mnemonic locally
internal_entropy = self.client.debug.read_entropy()
entropy = generate_entropy(strength, internal_entropy, external_entropy)
expected_mnemonic = Mnemonic('english').to_mnemonic(entropy)
mnemonic = []
for _ in range(12):
self.assertIsInstance(ret, proto.ButtonRequest)
mnemonic.append(self.client.debug.read_word()[0])
self.client.debug.press_yes()
self.client.call_raw(proto.ButtonAck())
mnemonic = ' '.join(mnemonic)
# Compare that device generated proper mnemonic for given entropies
self.assertEqual(mnemonic, expected_mnemonic)
mnemonic = []
for _ in range(12):
self.assertIsInstance(ret, proto.ButtonRequest)
mnemonic.append(self.client.debug.read_word()[0])
self.client.debug.press_yes()
resp = self.client.call_raw(proto.ButtonAck())
self.assertIsInstance(resp, proto.Success)
mnemonic = ' '.join(mnemonic)
# Compare that second pass printed out the same mnemonic once again
self.assertEqual(mnemonic, expected_mnemonic)
# Check if device is properly initialized
resp = self.client.call_raw(proto.Initialize())
self.assertTrue(resp.pin_protection)
self.assertTrue(resp.passphrase_protection)
# Do passphrase-protected action, PassphraseRequest should be raised
resp = self.client.call_raw(proto.Ping(passphrase_protection=True))
self.assertIsInstance(resp, proto.PassphraseRequest)
# Do PIN-protected action, PinRequest should be raised
resp = self.client.call_raw(proto.Ping(pin_protection=True))
self.assertIsInstance(resp, proto.PinMatrixRequest)
if __name__ == '__main__':
unittest.main()

View File

@ -1,25 +0,0 @@
import unittest
import common
from trezorlib import messages_pb2 as proto
class TestDeviceWipe(common.TrezorTest):
def test_wipe_device(self):
self.setup_mnemonic_pin_passphrase()
features = self.client.call_raw(proto.Initialize())
self.assertEqual(features.initialized, True)
self.assertEqual(features.pin_protection, True)
self.assertEqual(features.passphrase_protection, True)
device_id = features.device_id
self.client.wipe_device()
features = self.client.call_raw(proto.Initialize())
self.assertEqual(features.initialized, False)
self.assertEqual(features.pin_protection, False)
self.assertEqual(features.passphrase_protection, False)
self.assertNotEqual(features.device_id, device_id)
if __name__ == '__main__':
unittest.main()

View File

@ -1,31 +0,0 @@
import unittest
import common
import math
import trezorlib.messages_pb2 as proto
import trezorlib.types_pb2 as proto_types
def entropy(data):
counts = {}
for c in data:
if c in counts:
counts[c] += 1
else:
counts[c] = 1
e = 0
for _, v in counts.iteritems():
p = 1.0 * v / len(data)
e -= p * math.log(p, 256)
return e
class TestEntropy(common.TrezorTest):
def test_entropy(self):
for l in [0, 1, 2, 3, 4, 5, 8, 9, 16, 17, 32, 33, 64, 65, 128, 129, 256, 257, 512, 513, 1024]:
self.client.set_expected_responses([proto.ButtonRequest(code=proto_types.ButtonRequest_Other), proto.Entropy()])
ent = self.client.get_entropy(l)
self.assertTrue(len(ent) >= l)
print 'entropy = ', entropy(ent)
if __name__ == '__main__':
unittest.main()