mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-05-03 11:41:48 +00:00
mpt: disallow empty keys
This is not a problem in practice, as all keys are prefixed by a contract ID. However in theory it can lead to a different state root after new portion of changes thus this fix.
This commit is contained in:
parent
5b1f6207de
commit
e833d333fe
3 changed files with 16 additions and 15 deletions
|
@ -85,10 +85,6 @@ func TestTrie_PutIntoBranchNode(t *testing.T) {
|
|||
b.Children[0x8] = NewHashNode(random.Uint256())
|
||||
tr := NewTrie(b, false, newTestStore())
|
||||
|
||||
// next
|
||||
require.NoError(t, tr.Put([]byte{}, []byte{0x12, 0x34}))
|
||||
tr.testHas(t, []byte{}, []byte{0x12, 0x34})
|
||||
|
||||
// empty hash node child
|
||||
require.NoError(t, tr.Put([]byte{0x66}, []byte{0x56}))
|
||||
tr.testHas(t, []byte{0x66}, []byte{0x56})
|
||||
|
@ -160,6 +156,9 @@ func TestTrie_PutInvalid(t *testing.T) {
|
|||
tr := NewTrie(nil, false, newTestStore())
|
||||
key, value := []byte("key"), []byte("value")
|
||||
|
||||
// empty key
|
||||
require.Error(t, tr.Put(nil, value))
|
||||
|
||||
// big key
|
||||
require.Error(t, tr.Put(make([]byte, maxPathLength+1), value))
|
||||
|
||||
|
@ -271,7 +270,7 @@ func TestTrie_Get(t *testing.T) {
|
|||
|
||||
func TestTrie_Flush(t *testing.T) {
|
||||
pairs := map[string][]byte{
|
||||
"": []byte("value0"),
|
||||
"x": []byte("value0"),
|
||||
"key1": []byte("value1"),
|
||||
"key2": []byte("value2"),
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue