diff options
author | Felix Lange <fjl@twurst.com> | 2016-09-26 02:49:02 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2016-09-28 16:27:28 +0800 |
commit | cd791bd855b55b95afc8a5c8f56b8bf67863d099 (patch) | |
tree | 3955fe3abf4079eee5412119043ade1b7001bb61 /trie/iterator_test.go | |
parent | 863d166c7b0250cf2e99c8aad69578cdd144d386 (diff) | |
download | go-tangerine-cd791bd855b55b95afc8a5c8f56b8bf67863d099.tar go-tangerine-cd791bd855b55b95afc8a5c8f56b8bf67863d099.tar.gz go-tangerine-cd791bd855b55b95afc8a5c8f56b8bf67863d099.tar.bz2 go-tangerine-cd791bd855b55b95afc8a5c8f56b8bf67863d099.tar.lz go-tangerine-cd791bd855b55b95afc8a5c8f56b8bf67863d099.tar.xz go-tangerine-cd791bd855b55b95afc8a5c8f56b8bf67863d099.tar.zst go-tangerine-cd791bd855b55b95afc8a5c8f56b8bf67863d099.zip |
core, trie: replace state caches with trie journal
Diffstat (limited to 'trie/iterator_test.go')
-rw-r--r-- | trie/iterator_test.go | 51 |
1 files changed, 45 insertions, 6 deletions
diff --git a/trie/iterator_test.go b/trie/iterator_test.go index dc8276116..2bcc3700e 100644 --- a/trie/iterator_test.go +++ b/trie/iterator_test.go @@ -34,21 +34,60 @@ func TestIterator(t *testing.T) { {"dog", "puppy"}, {"somethingveryoddindeedthis is", "myothernodedata"}, } - v := make(map[string]bool) + all := make(map[string]string) for _, val := range vals { - v[val.k] = false + all[val.k] = val.v trie.Update([]byte(val.k), []byte(val.v)) } trie.Commit() + found := make(map[string]string) it := NewIterator(trie) for it.Next() { - v[string(it.Key)] = true + found[string(it.Key)] = string(it.Value) } - for k, found := range v { - if !found { - t.Error("iterator didn't find", k) + for k, v := range all { + if found[k] != v { + t.Errorf("iterator value mismatch for %s: got %q want %q", k, found[k], v) + } + } +} + +type kv struct { + k, v []byte + t bool +} + +func TestIteratorLargeData(t *testing.T) { + trie := newEmpty() + vals := make(map[string]*kv) + + for i := byte(0); i < 255; i++ { + value := &kv{common.LeftPadBytes([]byte{i}, 32), []byte{i}, false} + value2 := &kv{common.LeftPadBytes([]byte{10, i}, 32), []byte{i}, false} + trie.Update(value.k, value.v) + trie.Update(value2.k, value2.v) + vals[string(value.k)] = value + vals[string(value2.k)] = value2 + } + + it := NewIterator(trie) + for it.Next() { + vals[string(it.Key)].t = true + } + + var untouched []*kv + for _, value := range vals { + if !value.t { + untouched = append(untouched, value) + } + } + + if len(untouched) > 0 { + t.Errorf("Missed %d nodes", len(untouched)) + for _, value := range untouched { + t.Error(value) } } } |