diff options
author | Péter Szilágyi <peterke@gmail.com> | 2016-01-06 18:11:56 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2016-02-16 18:21:08 +0800 |
commit | 5a057a8dedd1fa284e04bc2e7780e74d4600fdeb (patch) | |
tree | 3285474d93d6e83f9326c2bc0435527e12d0b768 /trie/iterator_test.go | |
parent | 7e29b0b5b4e5cf7ded9a5a75789de6f8121caec9 (diff) | |
download | go-tangerine-5a057a8dedd1fa284e04bc2e7780e74d4600fdeb.tar go-tangerine-5a057a8dedd1fa284e04bc2e7780e74d4600fdeb.tar.gz go-tangerine-5a057a8dedd1fa284e04bc2e7780e74d4600fdeb.tar.bz2 go-tangerine-5a057a8dedd1fa284e04bc2e7780e74d4600fdeb.tar.lz go-tangerine-5a057a8dedd1fa284e04bc2e7780e74d4600fdeb.tar.xz go-tangerine-5a057a8dedd1fa284e04bc2e7780e74d4600fdeb.tar.zst go-tangerine-5a057a8dedd1fa284e04bc2e7780e74d4600fdeb.zip |
core/state, trie: surface iterator entry hashes
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) + } + } +} |