forked from cerc-io/plugeth
tests, trie: use slices package for sorting (#27496)
Co-authored-by: Felix Lange <fjl@twurst.com>
This commit is contained in:
@@ -23,7 +23,6 @@ import (
|
||||
"fmt"
|
||||
"hash"
|
||||
"io"
|
||||
"sort"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/rawdb"
|
||||
@@ -33,6 +32,7 @@ import (
|
||||
"github.com/ethereum/go-ethereum/trie"
|
||||
"github.com/ethereum/go-ethereum/trie/trienode"
|
||||
"golang.org/x/crypto/sha3"
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
type fuzzer struct {
|
||||
@@ -104,19 +104,6 @@ func (b *spongeBatch) Replay(w ethdb.KeyValueWriter) error { return nil }
|
||||
type kv struct {
|
||||
k, v []byte
|
||||
}
|
||||
type kvs []kv
|
||||
|
||||
func (k kvs) Len() int {
|
||||
return len(k)
|
||||
}
|
||||
|
||||
func (k kvs) Less(i, j int) bool {
|
||||
return bytes.Compare(k[i].k, k[j].k) < 0
|
||||
}
|
||||
|
||||
func (k kvs) Swap(i, j int) {
|
||||
k[j], k[i] = k[i], k[j]
|
||||
}
|
||||
|
||||
// Fuzz is the fuzzing entry-point.
|
||||
// The function must return
|
||||
@@ -156,7 +143,7 @@ func (f *fuzzer) fuzz() int {
|
||||
trieB = trie.NewStackTrie(func(owner common.Hash, path []byte, hash common.Hash, blob []byte) {
|
||||
rawdb.WriteTrieNode(spongeB, owner, path, hash, blob, dbB.Scheme())
|
||||
})
|
||||
vals kvs
|
||||
vals []kv
|
||||
useful bool
|
||||
maxElements = 10000
|
||||
// operate on unique keys only
|
||||
@@ -192,7 +179,9 @@ func (f *fuzzer) fuzz() int {
|
||||
dbA.Commit(rootA, false)
|
||||
|
||||
// Stacktrie requires sorted insertion
|
||||
sort.Sort(vals)
|
||||
slices.SortFunc(vals, func(a, b kv) bool {
|
||||
return bytes.Compare(a.k, b.k) < 0
|
||||
})
|
||||
for _, kv := range vals {
|
||||
if f.debugging {
|
||||
fmt.Printf("{\"%#x\" , \"%#x\"} // stacktrie.Update\n", kv.k, kv.v)
|
||||
|
||||
Reference in New Issue
Block a user