MCPcopy
hub / github.com/bnb-chain/bsc / testNodeIteratorCoverage

Function testNodeIteratorCoverage

core/state/iterator_test.go:33–88  ·  view source on GitHub ↗
(t *testing.T, scheme string)

Source from the content-addressed store, hash-verified

31}
32
33func testNodeIteratorCoverage(t *testing.T, scheme string) {
34 // Create some arbitrary test state to iterate
35 db, sdb, ndb, root, _ := makeTestState(scheme)
36 ndb.Commit(root, false)
37
38 state, err := New(root, sdb, nil)
39 if err != nil {
40 t.Fatalf("failed to create state trie at %x: %v", root, err)
41 }
42 // Gather all the node hashes found by the iterator
43 hashes := make(map[common.Hash]struct{})
44 for it := newNodeIterator(state); it.Next(); {
45 if it.Hash != (common.Hash{}) {
46 hashes[it.Hash] = struct{}{}
47 }
48 }
49 // Check in-disk nodes
50 var (
51 seenNodes = make(map[common.Hash]struct{})
52 seenCodes = make(map[common.Hash]struct{})
53 )
54 it := db.NewIterator(nil, nil)
55 for it.Next() {
56 ok, hash := isTrieNode(scheme, it.Key(), it.Value())
57 if !ok {
58 continue
59 }
60 seenNodes[hash] = struct{}{}
61 }
62 it.Release()
63
64 // Check in-disk codes
65 it = db.NewIterator(nil, nil)
66 for it.Next() {
67 ok, hash := rawdb.IsCodeKey(it.Key())
68 if !ok {
69 continue
70 }
71 if _, ok := hashes[common.BytesToHash(hash)]; !ok {
72 t.Errorf("state entry not reported %x", it.Key())
73 }
74 seenCodes[common.BytesToHash(hash)] = struct{}{}
75 }
76 it.Release()
77
78 // Cross check the iterated hashes and the database/nodepool content
79 for hash := range hashes {
80 _, ok := seenNodes[hash]
81 if !ok {
82 _, ok = seenCodes[hash]
83 }
84 if !ok {
85 t.Errorf("failed to retrieve reported node %x", hash)
86 }
87 }
88}
89
90// isTrieNode is a helper function which reports if the provided

Callers 1

TestNodeIteratorCoverageFunction · 0.70

Calls 14

NextMethod · 0.95
KeyMethod · 0.95
ValueMethod · 0.95
ReleaseMethod · 0.95
IsCodeKeyFunction · 0.92
BytesToHashFunction · 0.92
makeTestStateFunction · 0.85
ErrorfMethod · 0.80
NewFunction · 0.70
newNodeIteratorFunction · 0.70
isTrieNodeFunction · 0.70
CommitMethod · 0.65

Tested by

no test coverage detected