Skip to content

Commit ade7ba3

Browse files
committed
refactor: implement review requests
1 parent a8fa698 commit ade7ba3

File tree

1 file changed

+47
-43
lines changed

1 file changed

+47
-43
lines changed

core/rawdb/database.libevm_test.go

Lines changed: 47 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package rawdb_test
1919
import (
2020
"bytes"
2121
"fmt"
22+
"sort"
2223

2324
"github.com/ava-labs/libevm/common"
2425
// To ensure that all methods are available to importing packages, this test
@@ -74,22 +75,19 @@ func ExampleInspectDatabase() {
7475
rawdb.WithDatabaseMetadataKeys(func(key []byte) bool {
7576
return bytes.Equal(key, []byte("mymetadatakey"))
7677
}),
77-
rawdb.WithDatabaseStatsTransformer(func(s [][]string) [][]string {
78-
var modified [][]string
79-
// Remove lines
80-
for _, line := range s {
81-
database, category := line[0], line[1]
82-
switch {
83-
case database == "Ancient store (Chain)":
84-
case database == "Key-Value store" && category == "Difficulties":
85-
default:
86-
modified = append(modified, line)
78+
rawdb.WithDatabaseStatsTransformer(func(rows [][]string) [][]string {
79+
sort.Slice(rows, func(i, j int) bool {
80+
ri, rj := rows[i], rows[j]
81+
if ri[0] != rj[0] {
82+
return ri[0] < rj[0]
8783
}
88-
}
89-
// Add lines for data collected with [rawdb.WithDatabaseStatRecorder]
90-
line := []string{"My database", "My category", myStat.Size(), myStat.Count()}
91-
modified = append(modified, line)
92-
return modified
84+
return ri[1] < rj[1]
85+
})
86+
87+
return append(
88+
rows,
89+
[]string{"My database", "My category", myStat.Size(), myStat.Count()},
90+
)
9391
}),
9492
}
9593

@@ -98,33 +96,39 @@ func ExampleInspectDatabase() {
9896
fmt.Println(err)
9997
}
10098
// Output:
101-
// +-----------------+-------------------------+---------+-------+
102-
// | DATABASE | CATEGORY | SIZE | ITEMS |
103-
// +-----------------+-------------------------+---------+-------+
104-
// | Key-Value store | Headers | 0.00 B | 0 |
105-
// | Key-Value store | Bodies | 0.00 B | 0 |
106-
// | Key-Value store | Receipt lists | 0.00 B | 0 |
107-
// | Key-Value store | Block number->hash | 0.00 B | 0 |
108-
// | Key-Value store | Block hash->number | 0.00 B | 0 |
109-
// | Key-Value store | Transaction index | 0.00 B | 0 |
110-
// | Key-Value store | Bloombit index | 6.00 B | 1 |
111-
// | Key-Value store | Contract codes | 0.00 B | 0 |
112-
// | Key-Value store | Hash trie nodes | 0.00 B | 0 |
113-
// | Key-Value store | Path trie state lookups | 0.00 B | 0 |
114-
// | Key-Value store | Path trie account nodes | 0.00 B | 0 |
115-
// | Key-Value store | Path trie storage nodes | 0.00 B | 0 |
116-
// | Key-Value store | Trie preimages | 0.00 B | 0 |
117-
// | Key-Value store | Account snapshot | 0.00 B | 0 |
118-
// | Key-Value store | Storage snapshot | 0.00 B | 0 |
119-
// | Key-Value store | Beacon sync headers | 0.00 B | 0 |
120-
// | Key-Value store | Clique snapshots | 0.00 B | 0 |
121-
// | Key-Value store | Singleton metadata | 20.00 B | 1 |
122-
// | Light client | CHT trie nodes | 0.00 B | 0 |
123-
// | Light client | Bloom trie nodes | 0.00 B | 0 |
124-
// | My database | My category | 12.00 B | 1 |
125-
// +-----------------+-------------------------+---------+-------+
126-
// | TOTAL | 38.00 B | |
127-
// +-----------------+-------------------------+---------+-------+
99+
// +-----------------------+-------------------------+---------+-------+
100+
// | DATABASE | CATEGORY | SIZE | ITEMS |
101+
// +-----------------------+-------------------------+---------+-------+
102+
// | Ancient store (Chain) | Bodies | 0.00 B | 0 |
103+
// | Ancient store (Chain) | Diffs | 0.00 B | 0 |
104+
// | Ancient store (Chain) | Hashes | 0.00 B | 0 |
105+
// | Ancient store (Chain) | Headers | 0.00 B | 0 |
106+
// | Ancient store (Chain) | Receipts | 0.00 B | 0 |
107+
// | Key-Value store | Account snapshot | 0.00 B | 0 |
108+
// | Key-Value store | Beacon sync headers | 0.00 B | 0 |
109+
// | Key-Value store | Block hash->number | 0.00 B | 0 |
110+
// | Key-Value store | Block number->hash | 0.00 B | 0 |
111+
// | Key-Value store | Bloombit index | 6.00 B | 1 |
112+
// | Key-Value store | Bodies | 0.00 B | 0 |
113+
// | Key-Value store | Clique snapshots | 0.00 B | 0 |
114+
// | Key-Value store | Contract codes | 0.00 B | 0 |
115+
// | Key-Value store | Difficulties | 0.00 B | 0 |
116+
// | Key-Value store | Hash trie nodes | 0.00 B | 0 |
117+
// | Key-Value store | Headers | 0.00 B | 0 |
118+
// | Key-Value store | Path trie account nodes | 0.00 B | 0 |
119+
// | Key-Value store | Path trie state lookups | 0.00 B | 0 |
120+
// | Key-Value store | Path trie storage nodes | 0.00 B | 0 |
121+
// | Key-Value store | Receipt lists | 0.00 B | 0 |
122+
// | Key-Value store | Singleton metadata | 20.00 B | 1 |
123+
// | Key-Value store | Storage snapshot | 0.00 B | 0 |
124+
// | Key-Value store | Transaction index | 0.00 B | 0 |
125+
// | Key-Value store | Trie preimages | 0.00 B | 0 |
126+
// | Light client | Bloom trie nodes | 0.00 B | 0 |
127+
// | Light client | CHT trie nodes | 0.00 B | 0 |
128+
// | My database | My category | 12.00 B | 1 |
129+
// +-----------------------+-------------------------+---------+-------+
130+
// | TOTAL | 38.00 B | |
131+
// +-----------------------+-------------------------+---------+-------+
128132
}
129133

130134
type stubDatabase struct {
@@ -159,7 +163,7 @@ func (s *stubDatabase) ReadAncients(fn func(ethdb.AncientReaderOp) error) error
159163

160164
type stubIterator struct {
161165
ethdb.Iterator
162-
i int // see pos()
166+
i int // see [stubIterator.pos]
163167
kvs []keyValue
164168
}
165169

0 commit comments

Comments
 (0)