-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew_bintrie_test.py
27 lines (24 loc) · 1007 Bytes
/
new_bintrie_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
from new_bintrie import EphemDB, new_tree, get, update, make_merkle_proof, verify_proof, compress_proof, decompress_proof
import random
from ethereum.utils import sha3
KEYS = 500
db = EphemDB()
t = new_tree(db)
for i in range(KEYS):
t = update(db, t, sha3(str(i)), sha3(str(i**3)))
print('%d elements added' % KEYS)
for i in range(KEYS):
assert get(db, t, sha3(str(i))) == sha3(str(i**3))
print('Get requests for present elements successful')
for i in range(KEYS + 1, KEYS * 2):
assert get(db, t, sha3(str(i))) == b'\x00' * 32
print('Get requests for absent elements successful')
TL = 0
for i in range(KEYS * 2):
key = sha3(str(i))
value = sha3(str(i ** 3)) if i < KEYS else b'\x00' * 32
proof = make_merkle_proof(db, t, key)
assert verify_proof(proof, t, key, value)
assert decompress_proof(compress_proof(proof)) == proof
TL += len(compress_proof(proof))
print('Average total length at %d keys: %d, %d including key' % (KEYS, TL // KEYS // 2, TL // KEYS // 2 + 32))