From 05c6ca8f5ae4e0b7fe9c7f393505519e90af7096 Mon Sep 17 00:00:00 2001 From: Roy Crihfield Date: Wed, 20 Sep 2023 00:15:55 +0800 Subject: [PATCH] add test --- chaindata/util/chaindata_test.go | 42 ++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 chaindata/util/chaindata_test.go diff --git a/chaindata/util/chaindata_test.go b/chaindata/util/chaindata_test.go new file mode 100644 index 0000000..7f56957 --- /dev/null +++ b/chaindata/util/chaindata_test.go @@ -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) }) + } +}