-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
45 lines (30 loc) · 1.22 KB
/
test.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
from blockchain import Blockchain
from entry import Entry
import time
class TestProductEntry(Entry):
def __init__(self, serial: str, employee: str, timestamp: int):
super().__init__()
self.serial = serial
self.employee = employee
self.timestamp = timestamp
def to_array(self):
return {
'serial': self.serial,
'employee': self.employee,
'timestamp': self.timestamp
}
@staticmethod
def from_array(data: dict):
return TestProductEntry(data['serial'], data['employee'], data['timestamp'])
difficulty = 4
block_size = 10
blockchain = Blockchain(difficulty, block_size)
for i in range(123):
entry = TestProductEntry('60125-0-%s-1' % i, 'Employee name', int(time.time() - 1500000 + (3600 * i)))
print(' [+] Add entry %s' % entry.get_hash())
blockchain.add_entry(entry)
blockchain.save('blockchain.db')
blockchain = Blockchain.from_file('blockchain.db', TestProductEntry)
print(' [+] Blockchain contain %s blocks' % blockchain.get_block_count())
print(' [+] Blockchain contain %s entry' % blockchain.get_entry_count())
print(' [+] Blockchain is valid' if blockchain.validate() else print(' [-] Blockchain is not valid'))