From e34874b7c1e070d0d68a121fb898e291625f5ede Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Wed, 29 Jan 2014 19:09:24 +0100 Subject: [PATCH] add entropy message test --- tests/test_entropy.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/test_entropy.py diff --git a/tests/test_entropy.py b/tests/test_entropy.py new file mode 100644 index 0000000000..11eedcfa2c --- /dev/null +++ b/tests/test_entropy.py @@ -0,0 +1,35 @@ +import unittest +import common +import math + +from trezorlib import messages_pb2 as messages + +def entropy(data): + 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) + 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) + print 'entropy = ', entropy(ent) + +if __name__ == '__main__': + unittest.main()