@ -26,6 +26,7 @@ import (
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/trie/testutil"
"github.com/ethereum/go-ethereum/trie/testutil"
"github.com/stretchr/testify/assert"
"golang.org/x/exp/slices"
"golang.org/x/exp/slices"
)
)
@ -463,3 +464,24 @@ func TestPartialStackTrie(t *testing.T) {
}
}
}
}
}
}
func TestStackTrieErrors ( t * testing . T ) {
s := NewStackTrie ( nil )
// Deletion
if err := s . Update ( nil , nil ) ; err == nil {
t . Fatal ( "expected error" )
}
if err := s . Update ( nil , [ ] byte { } ) ; err == nil {
t . Fatal ( "expected error" )
}
if err := s . Update ( [ ] byte { 0xa } , [ ] byte { } ) ; err == nil {
t . Fatal ( "expected error" )
}
// Non-ascending keys (going backwards or repeating)
assert . Nil ( t , s . Update ( [ ] byte { 0xaa } , [ ] byte { 0xa } ) )
assert . NotNil ( t , s . Update ( [ ] byte { 0xaa } , [ ] byte { 0xa } ) , "repeat insert same key" )
assert . NotNil ( t , s . Update ( [ ] byte { 0xaa } , [ ] byte { 0xb } ) , "repeat insert same key" )
assert . Nil ( t , s . Update ( [ ] byte { 0xab } , [ ] byte { 0xa } ) )
assert . NotNil ( t , s . Update ( [ ] byte { 0x10 } , [ ] byte { 0xb } ) , "out of order insert" )
assert . NotNil ( t , s . Update ( [ ] byte { 0xaa } , [ ] byte { 0xb } ) , "repeat insert same key" )
}