aeternity / elixir-merkle-patricia-tree

Elixir implementation of modified Merkle Patricia tree (trie)
MIT License
10 stars 6 forks source link

Updating key when longer key exists #13

Closed cytadela8 closed 6 years ago

cytadela8 commented 6 years ago

Root hash is wrong when we update a key when there exists a longer key:

Steps to reproduce:

db = MerklePatriciaTree.DB.ETS.random_ets_db()
trie1 = Trie.new(db)
trie2 = Trie.new(db)
trie1 = Trie.update(trie1, "key", "oldvalue")
trie1 = Trie.update(trie1, "key_loner", "loner_key_value")
trie1 = Trie.update(trie1, "key", "newvalue")
trie2 = Trie.update(trie2, "key", "newvalue")
trie2 = Trie.update(trie2, "key_loner", "loner_key_value")
trie1.root_hash == trie2.root_hash

Result: false

Expected result: true

I added a test that fails.

Note: Ethereum tests also fail - #10