aboutsummaryrefslogtreecommitdiffstats
path: root/trie/trie_test.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2019-03-14 21:25:12 +0800
committerGitHub <noreply@github.com>2019-03-14 21:25:12 +0800
commit91eec1251c06727581063cd7e942ba913d806971 (patch)
treee47da6be2a8b15116b773855cf06473d5b4b64ed /trie/trie_test.go
parente270a753bec7e723e7909b55543a54e26210dd8a (diff)
downloadgo-tangerine-91eec1251c06727581063cd7e942ba913d806971.tar
go-tangerine-91eec1251c06727581063cd7e942ba913d806971.tar.gz
go-tangerine-91eec1251c06727581063cd7e942ba913d806971.tar.bz2
go-tangerine-91eec1251c06727581063cd7e942ba913d806971.tar.lz
go-tangerine-91eec1251c06727581063cd7e942ba913d806971.tar.xz
go-tangerine-91eec1251c06727581063cd7e942ba913d806971.tar.zst
go-tangerine-91eec1251c06727581063cd7e942ba913d806971.zip
cmd, core, eth, trie: get rid of trie cache generations (#19262)
* cmd, core, eth, trie: get rid of trie cache generations * core, trie: get rid of remainder of cache gen boilerplate
Diffstat (limited to 'trie/trie_test.go')
-rw-r--r--trie/trie_test.go72
1 files changed, 1 insertions, 71 deletions
diff --git a/trie/trie_test.go b/trie/trie_test.go
index 1c874370c..ea0b3cbdd 100644
--- a/trie/trie_test.go
+++ b/trie/trie_test.go
@@ -19,7 +19,6 @@ package trie
import (
"bytes"
"encoding/binary"
- "errors"
"fmt"
"io/ioutil"
"math/big"
@@ -328,38 +327,6 @@ func (db *countingDB) Get(key []byte) ([]byte, error) {
return db.KeyValueStore.Get(key)
}
-// TestCacheUnload checks that decoded nodes are unloaded after a
-// certain number of commit operations.
-func TestCacheUnload(t *testing.T) {
- // Create test trie with two branches.
- trie := newEmpty()
- key1 := "---------------------------------"
- key2 := "---some other branch"
- updateString(trie, key1, "this is the branch of key1.")
- updateString(trie, key2, "this is the branch of key2.")
-
- root, _ := trie.Commit(nil)
- trie.db.Commit(root, true)
-
- // Commit the trie repeatedly and access key1.
- // The branch containing it is loaded from DB exactly two times:
- // in the 0th and 6th iteration.
- diskdb := &countingDB{KeyValueStore: trie.db.diskdb, gets: make(map[string]int)}
- triedb := NewDatabase(diskdb)
- trie, _ = New(root, triedb)
- trie.SetCacheLimit(5)
- for i := 0; i < 12; i++ {
- getString(trie, key1)
- trie.Commit(nil)
- }
- // Check that it got loaded two times.
- for dbkey, count := range diskdb.gets {
- if count != 2 {
- t.Errorf("db key %x loaded %d times, want %d times", []byte(dbkey), count, 2)
- }
- }
-}
-
// randTest performs random trie operations.
// Instances of this test are created by Generate.
type randTest []randTestStep
@@ -379,7 +346,6 @@ const (
opHash
opReset
opItercheckhash
- opCheckCacheInvariant
opMax // boundary value, not an actual op
)
@@ -458,8 +424,6 @@ func runRandTest(rt randTest) bool {
if tr.Hash() != checktr.Hash() {
rt[i].err = fmt.Errorf("hash mismatch in opItercheckhash")
}
- case opCheckCacheInvariant:
- rt[i].err = checkCacheInvariant(tr.root, nil, tr.cachegen, false, 0)
}
// Abort the test on error.
if rt[i].err != nil {
@@ -469,40 +433,6 @@ func runRandTest(rt randTest) bool {
return true
}
-func checkCacheInvariant(n, parent node, parentCachegen uint16, parentDirty bool, depth int) error {
- var children []node
- var flag nodeFlag
- switch n := n.(type) {
- case *shortNode:
- flag = n.flags
- children = []node{n.Val}
- case *fullNode:
- flag = n.flags
- children = n.Children[:]
- default:
- return nil
- }
-
- errorf := func(format string, args ...interface{}) error {
- msg := fmt.Sprintf(format, args...)
- msg += fmt.Sprintf("\nat depth %d node %s", depth, spew.Sdump(n))
- msg += fmt.Sprintf("parent: %s", spew.Sdump(parent))
- return errors.New(msg)
- }
- if flag.gen > parentCachegen {
- return errorf("cache invariant violation: %d > %d\n", flag.gen, parentCachegen)
- }
- if depth > 0 && !parentDirty && flag.dirty {
- return errorf("cache invariant violation: %d > %d\n", flag.gen, parentCachegen)
- }
- for _, child := range children {
- if err := checkCacheInvariant(child, n, flag.gen, flag.dirty, depth+1); err != nil {
- return err
- }
- }
- return nil
-}
-
func TestRandom(t *testing.T) {
if err := quick.Check(runRandTest, nil); err != nil {
if cerr, ok := err.(*quick.CheckError); ok {
@@ -626,6 +556,6 @@ func TestDecodeNode(t *testing.T) {
for i := 0; i < 5000000; i++ {
rand.Read(hash)
rand.Read(elems)
- decodeNode(hash, elems, 1)
+ decodeNode(hash, elems)
}
}