Created
August 15, 2019 00:09
Star
You must be signed in to star a gist
showing a bug in py-trie
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import rlp | |
from trie import HexaryTrie | |
ZERO_HASH32 = 32 * b'\x00' | |
BLANK_ROOT_HASH = b'V\xe8\x1f\x17\x1b\xccU\xa6\xff\x83E\xe6\x92\xc0\xf8n\x5bH\xe0\x1b\x99l\xad\xc0\x01b/\xb5\xe3c\xb4!' | |
def make_trie_root_and_nodes( items): | |
return _make_trie_root_and_nodes(tuple(rlp.encode(item) for item in items)) | |
def _make_trie_root_and_nodes(items): | |
kv_store = {} # type: Dict[bytes, bytes] | |
trie = HexaryTrie(kv_store, BLANK_ROOT_HASH, prune=True) | |
memory_trie = trie | |
for index, item in enumerate(items): | |
index_key = rlp.encode(index, sedes=rlp.sedes.big_endian_int) | |
print('ZZZZZZZZZZZZZ') | |
print(index) | |
print(index_key) | |
print(item) | |
memory_trie[index_key] = item | |
return trie.root_hash, kv_store | |
def test_trie_root(): | |
from secrets import token_bytes | |
list_of_bytes = [] | |
for i in range(129): | |
#random_bytes = token_bytes(1)*999 | |
random_bytes = ZERO_HASH32 | |
list_of_bytes.append(random_bytes) | |
#print(list_of_bytes) | |
print(_make_trie_root_and_nodes(list_of_bytes)) | |
test_trie_root() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment