Skip to content

Commit 9fafc88

Browse files
committed
Use existing write functions
1 parent da31fc8 commit 9fafc88

File tree

1 file changed

+23
-28
lines changed

1 file changed

+23
-28
lines changed

core/rawdb/database_ext_test.go

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,27 @@ package rawdb
33
import (
44
"fmt"
55

6+
"github.com/ava-labs/libevm/common"
67
"github.com/ava-labs/libevm/ethdb"
78
)
89

910
func ExampleInspectDatabase() {
10-
extendRight := func(base []byte, totalLength int) []byte {
11-
if len(base) > totalLength {
12-
return base[:totalLength]
13-
}
14-
extended := make([]byte, totalLength)
15-
copy(extended, base)
16-
return extended
17-
}
18-
1911
db := &stubDatabase{
20-
iterator: &stubIterator{
21-
kvs: []keyValue{
22-
// Extra metadata keys: (17 + 1) + (9 + 1) = 28 bytes
23-
{key: snapshotBlockHashKey, value: []byte("a")},
24-
{key: syncRootKey, value: []byte("b")},
25-
// Trie segments: 77 + 1 = 78 bytes
26-
{key: extendRight(syncSegmentsPrefix, syncSegmentsKeyLength), value: []byte("c")},
27-
// Storage tries to fetch: 76 + 1 = 77 bytes
28-
{key: extendRight(syncStorageTriesPrefix, syncStorageTriesKeyLength), value: []byte("d")},
29-
// Code to fetch: 34 + 1 = 35 bytes
30-
{key: extendRight(CodeToFetchPrefix, codeToFetchKeyLength), value: []byte("e")},
31-
// Block numbers synced to: 22 + 1 = 23 bytes
32-
{key: extendRight(syncPerformedPrefix, syncPerformedKeyLength), value: []byte("f")},
33-
},
34-
},
12+
iterator: &stubIterator{},
3513
}
3614

15+
// Extra metadata keys: (17 + 32) + (12 + 32) = 93 bytes
16+
WriteSnapshotBlockHash(db, common.Hash{})
17+
WriteSnapshotRoot(db, common.Hash{})
18+
// Trie segments: (77 + 2) + 1 = 80 bytes
19+
_ = WriteSyncSegment(db, common.Hash{}, common.Hash{}.Bytes())
20+
// Storage tries to fetch: 76 + 1 = 77 bytes
21+
_ = WriteSyncStorageTrie(db, common.Hash{}, common.Hash{})
22+
// Code to fetch: 34 + 0 = 34 bytes
23+
AddCodeToFetch(db, common.Hash{})
24+
// Block numbers synced to: 22 + 1 = 23 bytes
25+
_ = WriteSyncPerformed(db, 0)
26+
3727
keyPrefix := []byte(nil)
3828
keyStart := []byte(nil)
3929

@@ -61,21 +51,21 @@ func ExampleInspectDatabase() {
6151
// | Key-Value store | Account snapshot | 0.00 B | 0 |
6252
// | Key-Value store | Storage snapshot | 0.00 B | 0 |
6353
// | Key-Value store | Clique snapshots | 0.00 B | 0 |
64-
// | Key-Value store | Singleton metadata | 28.00 B | 2 |
54+
// | Key-Value store | Singleton metadata | 93.00 B | 2 |
6555
// | Light client | CHT trie nodes | 0.00 B | 0 |
6656
// | Light client | Bloom trie nodes | 0.00 B | 0 |
6757
// | State sync | Trie segments | 78.00 B | 1 |
6858
// | State sync | Storage tries to fetch | 77.00 B | 1 |
69-
// | State sync | Code to fetch | 35.00 B | 1 |
59+
// | State sync | Code to fetch | 34.00 B | 1 |
7060
// | State sync | Block numbers synced to | 23.00 B | 1 |
7161
// +-----------------+-------------------------+----------+-------+
72-
// | TOTAL | 241.00 B | |
62+
// | TOTAL | 305.00 B | |
7363
// +-----------------+-------------------------+----------+-------+
7464
}
7565

7666
type stubDatabase struct {
7767
ethdb.Database
78-
iterator ethdb.Iterator
68+
iterator *stubIterator
7969
}
8070

8171
func (s *stubDatabase) NewIterator(keyPrefix, keyStart []byte) ethdb.Iterator {
@@ -95,6 +85,11 @@ func (s *stubDatabase) Tail() (uint64, error) {
9585
return 0, nil
9686
}
9787

88+
func (s *stubDatabase) Put(key, value []byte) error {
89+
s.iterator.kvs = append(s.iterator.kvs, keyValue{key: key, value: value})
90+
return nil
91+
}
92+
9893
func (s *stubDatabase) Get(key []byte) ([]byte, error) {
9994
return nil, nil
10095
}

0 commit comments

Comments
 (0)