2 Commits
Author SHA1 Message Date
roysc 05c6ca8f5a add test 2023-09-20 00:21:08 +08:00
roysc 422f0036fe fix data path 2023-09-20 00:21:08 +08:00
2 changed files with 43 additions and 1 deletions
+1 -1
View File
@@ -16,7 +16,7 @@ func ChainDataPaths(chain string) (string, string) {
panic("could not get function source path")
}
chainPath := filepath.Join(filepath.Dir(thisPath), "..", "chain", chain)
chainPath := filepath.Join(filepath.Dir(thisPath), "..", "data", chain)
chaindataPath, err := filepath.Abs(chainPath)
if err != nil {
+42
View File
@@ -0,0 +1,42 @@
package util_test
import (
"testing"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/cerc-io/eth-testing/chaindata/util"
)
func testReadChainData(t *testing.T, name string) {
ChainDataPath, AncientDataPath := util.ChainDataPaths(name)
kvdb, ldberr := rawdb.NewLevelDBDatabase(ChainDataPath, 1024, 256, "vdb-geth", false)
if ldberr != nil {
t.Fatal(ldberr)
}
edb, err := rawdb.NewDatabaseWithFreezer(kvdb, AncientDataPath, "vdb-geth", false)
if err != nil {
t.Fatal(err)
}
if err != nil {
t.Fatal(err)
}
defer edb.Close()
hash := rawdb.ReadHeadHeaderHash(edb)
height := rawdb.ReadHeaderNumber(edb, hash)
if height == nil {
t.Fatalf("unable to read header height for header hash %s", hash)
}
header := rawdb.ReadHeader(edb, hash, *height)
if header == nil {
t.Fatalf("unable to read canonical header at height %d", height)
}
}
func TestReadChainData(t *testing.T) {
for _, name := range []string{"small", "medium"} {
t.Run(name, func(t *testing.T) { testReadChainData(t, name) })
}
}