core/state, trie: surface iterator entry hashes

This commit is contained in:
Péter Szilágyi
2016-01-06 12:11:56 +02:00
parent 7e29b0b5b4
commit 5a057a8ded
6 changed files with 114 additions and 20 deletions

View File

@ -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)
}
}
}