-
Notifications
You must be signed in to change notification settings - Fork 56
/
test_sanity.py
executable file
·60 lines (45 loc) · 1.57 KB
/
test_sanity.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import unittest
from merkle_tree import *
class SanityCheck(unittest.TestCase):
def test_sanity_HashLeaf(self):
"""Ensure HashLeaf structures work as intended"""
tx1 = 'a'
tx2 = 'b'
data = tx1 + tx2
data = hash_data(data, 'sha256')
hash_leaf = HashLeaf(tx1, tx2, 'sha256')
self.assertEqual(hash_leaf.data, data)
self.assertEqual(hash_leaf.height, 1)
def test_sanity_HashNode(self):
"""Ensure HashNode structures work as intended"""
tx1 = 'a'
tx2 = 'b'
tx3 = 'c'
tx4 = 'd'
data1 = tx1 + tx2
data1 = hash_data(data1, 'sha256')
data2 = tx3 + tx4
data2 = hash_data(data2, 'sha256')
data = data1 + data2
data = hash_data(data, 'sha256')
hash_leaf1 = HashLeaf(tx1, tx2, 'sha256')
hash_leaf2 = HashLeaf(tx3, tx4, 'sha256')
hash_node = HashNode(hash_leaf1, hash_leaf2, 'sha256')
self.assertEqual(hash_node.data, data)
self.assertEqual(hash_node.height, 2)
def test_sanity_check_MerkleTree(self):
"""Ensure MerkleTree structures work as intended"""
tx1 = 'a'
tx2 = 'b'
tx3 = 'c'
tx4 = 'd'
data1 = tx1 + tx2
data1 = hash_data(data1, 'sha256')
data2 = tx3 + tx4
data2 = hash_data(data2, 'sha256')
data = data1 + data2
data = hash_data(data, 'sha256')
merkle_tree = MerkleTree([tx1, tx2, tx3, tx4])
self.assertEqual(merkle_tree.block_header, data)
if __name__ == '__main__':
unittest.main()