mpt: strip branch node in a simple implementation
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
ae8f4ebd5e
commit
25428d53f1
2 changed files with 19 additions and 0 deletions
|
@ -310,6 +310,7 @@ func (t *Trie) deleteFromExtension(n *ExtensionNode, path []byte) (Node, error)
|
||||||
if nxt.IsEmpty() {
|
if nxt.IsEmpty() {
|
||||||
return nxt, nil
|
return nxt, nil
|
||||||
}
|
}
|
||||||
|
n.next = nxt
|
||||||
default:
|
default:
|
||||||
n.next = r
|
n.next = r
|
||||||
}
|
}
|
||||||
|
|
|
@ -395,6 +395,24 @@ func testTrieDelete(t *testing.T, enableGC bool) {
|
||||||
tr.testHas(t, []byte{}, nil)
|
tr.testHas(t, []byte{}, nil)
|
||||||
tr.testHas(t, []byte{0x56}, []byte{0x34})
|
tr.testHas(t, []byte{0x56}, []byte{0x34})
|
||||||
require.IsType(t, (*ExtensionNode)(nil), tr.root)
|
require.IsType(t, (*ExtensionNode)(nil), tr.root)
|
||||||
|
|
||||||
|
t.Run("WithHash, branch node replaced", func(t *testing.T) {
|
||||||
|
ch := NewLeafNode([]byte{5, 6})
|
||||||
|
h := ch.Hash()
|
||||||
|
|
||||||
|
b := NewBranchNode()
|
||||||
|
b.Children[3] = NewExtensionNode([]byte{4}, NewLeafNode([]byte{1, 2, 3}))
|
||||||
|
b.Children[lastChild] = NewHashNode(h)
|
||||||
|
|
||||||
|
tr := NewTrie(NewExtensionNode([]byte{1, 2}, b), enableGC, newTestStore())
|
||||||
|
tr.putToStore(ch)
|
||||||
|
|
||||||
|
require.NoError(t, tr.Delete([]byte{0x12, 0x34}))
|
||||||
|
tr.testHas(t, []byte{0x12, 0x34}, nil)
|
||||||
|
tr.testHas(t, []byte{0x12}, []byte{5, 6})
|
||||||
|
require.IsType(t, (*ExtensionNode)(nil), tr.root)
|
||||||
|
require.Equal(t, h, tr.root.(*ExtensionNode).next.Hash())
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("LeaveLeaf", func(t *testing.T) {
|
t.Run("LeaveLeaf", func(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue