removed some dead code in tests
[p2pool.git] / p2pool / test / bitcoin / test_sha256.py
1 from __future__ import division
2
3 import unittest
4 import hashlib
5 import random
6
7 from p2pool.bitcoin import sha256
8
9 class Test(unittest.TestCase):
10     def test_all(self):
11         for test in ['', 'a', 'b', 'abc', 'abc'*50, 'hello world']:
12             #print test
13             #print sha256.sha256(test).hexdigest()
14             #print hashlib.sha256(test).hexdigest()
15             #print
16             assert sha256.sha256(test).hexdigest() == hashlib.sha256(test).hexdigest()
17         def random_str(l):
18             return ''.join(chr(random.randrange(256)) for i in xrange(l))
19         for length in xrange(150):
20             test = random_str(length)
21             a = sha256.sha256(test).hexdigest()
22             b = hashlib.sha256(test).hexdigest()
23             assert a == b
24         for i in xrange(100):
25             test = random_str(int(random.expovariate(1/100)))
26             test2 = random_str(int(random.expovariate(1/100)))
27             
28             a = sha256.sha256(test)
29             a = a.copy()
30             a.update(test2)
31             a = a.hexdigest()
32             
33             b = hashlib.sha256(test)
34             b = b.copy()
35             b.update(test2)
36             b = b.hexdigest()
37             assert a == b