diff options
author | Péter Szilágyi <peterke@gmail.com> | 2016-02-23 16:26:25 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2016-02-23 16:26:25 +0800 |
commit | 3dca9cc550ff2b972815008e45b6a2ff1cf74af1 (patch) | |
tree | e562e5095a7b76bd3b8241ad319094cf052f6109 /trie/iterator_test.go | |
parent | f8d98f7fcd08bd2eff36d5366ac2a14b52255d57 (diff) | |
parent | b8d59d9c985feed9ec1d8851f65517c7e5c09deb (diff) | |
download | go-tangerine-3dca9cc550ff2b972815008e45b6a2ff1cf74af1.tar go-tangerine-3dca9cc550ff2b972815008e45b6a2ff1cf74af1.tar.gz go-tangerine-3dca9cc550ff2b972815008e45b6a2ff1cf74af1.tar.bz2 go-tangerine-3dca9cc550ff2b972815008e45b6a2ff1cf74af1.tar.lz go-tangerine-3dca9cc550ff2b972815008e45b6a2ff1cf74af1.tar.xz go-tangerine-3dca9cc550ff2b972815008e45b6a2ff1cf74af1.tar.zst go-tangerine-3dca9cc550ff2b972815008e45b6a2ff1cf74af1.zip |
Merge pull request #2095 from karalabe/trie-node-iterator
core/state, trie: add node iterator, test state/trie sync consistency
Diffstat (limited to 'trie/iterator_test.go')
-rw-r--r-- | trie/iterator_test.go | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/trie/iterator_test.go b/trie/iterator_test.go index fdc60b412..dc8276116 100644 --- a/trie/iterator_test.go +++ b/trie/iterator_test.go @@ -16,7 +16,12 @@ package trie -import "testing" +import ( + "testing" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/ethdb" +) func TestIterator(t *testing.T) { trie := newEmpty() @@ -47,3 +52,28 @@ func TestIterator(t *testing.T) { } } } + +// Tests that the node iterator indeed walks over the entire database contents. +func TestNodeIteratorCoverage(t *testing.T) { + // Create some arbitrary test trie to iterate + db, trie, _ := makeTestTrie() + + // Gather all the node hashes found by the iterator + hashes := make(map[common.Hash]struct{}) + for it := NewNodeIterator(trie); it.Next(); { + if it.Hash != (common.Hash{}) { + hashes[it.Hash] = struct{}{} + } + } + // Cross check the hashes and the database itself + for hash, _ := range hashes { + if _, err := db.Get(hash.Bytes()); err != nil { + t.Errorf("failed to retrieve reported node %x: %v", hash, err) + } + } + for _, key := range db.(*ethdb.MemDatabase).Keys() { + if _, ok := hashes[common.BytesToHash(key)]; !ok { + t.Errorf("state entry not reported %x", key) + } + } +} |