From 07137cae9147dee5b0a2979bbc0536c481b646f1 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Thu, 6 Feb 2014 00:34:58 +0100 Subject: [PATCH] test_entropy does not need load_device --- tests/test_entropy.py | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/tests/test_entropy.py b/tests/test_entropy.py index 11eedcfa2c..407c33d232 100644 --- a/tests/test_entropy.py +++ b/tests/test_entropy.py @@ -5,27 +5,21 @@ import math from trezorlib import messages_pb2 as messages def entropy(data): + counts = {} + for c in data: + if c in counts: + counts[c] += 1 + else: + counts[c] = 1 e = 0 - for i in range(256): - p = 0 - for c in data: - if ord(c) == i: - p += 1 - if p == 0: - continue - p = 1.0 * p / len(data) + for k,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): - self.client.load_device_by_mnemonic(mnemonic=self.mnemonic1, - pin='', - passphrase_protection=False, - label='test', - language='english') - for l in [0, 1, 2, 3, 4, 5, 8, 9, 16, 17, 32, 33, 64, 65, 128, 129, 256, 257, 512, 513, 1024]: ent = self.client.get_entropy(l) self.assertTrue(len(ent) >= l)