diff --git a/chaindata/mainnet/chain_test.go b/chaindata/mainnet/chain_test.go new file mode 100644 index 0000000..94ec8b1 --- /dev/null +++ b/chaindata/mainnet/chain_test.go @@ -0,0 +1,23 @@ +package mainnet_test + +import ( + "testing" + + "github.com/ethereum/go-ethereum/consensus/ethash" + "github.com/ethereum/go-ethereum/core" + "github.com/ethereum/go-ethereum/core/rawdb" + "github.com/ethereum/go-ethereum/core/vm" + + "github.com/cerc-io/eth-testing/chaindata/mainnet" +) + +func TestLoadChain(t *testing.T) { + db := rawdb.NewMemoryDatabase() + core.DefaultGenesisBlock().MustCommit(db) + blocks := mainnet.GetBlocks() + chain, _ := core.NewBlockChain(db, nil, nil, nil, ethash.NewFaker(), vm.Config{}, nil, nil) + _, err := chain.InsertChain(blocks[1:]) + if err != nil { + t.Fatal(err) + } +} 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) }) + } +} diff --git a/go.mod b/go.mod index 349b67d..eb61478 100644 --- a/go.mod +++ b/go.mod @@ -17,6 +17,7 @@ require ( github.com/cockroachdb/redact v1.1.3 // indirect github.com/deckarep/golang-set/v2 v2.1.0 // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect + github.com/edsrzf/mmap-go v1.0.0 // indirect github.com/getsentry/sentry-go v0.18.0 // indirect github.com/go-ole/go-ole v1.2.1 // indirect github.com/go-stack/stack v1.8.1 // indirect diff --git a/go.sum b/go.sum index 3d93c2e..77bea1a 100644 --- a/go.sum +++ b/go.sum @@ -57,6 +57,7 @@ github.com/dgraph-io/badger v1.6.0/go.mod h1:zwt7syl517jmP8s94KqSxTlM6IMsdhYy6ps github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/edsrzf/mmap-go v1.0.0 h1:CEBF7HpRnUCSJgGUb5h1Gm7e3VkmVDrR8lvWVLtrOFw= +github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M= github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385/go.mod h1:0vRUJqYpeSZifjYj7uP3BG/gKcuzL9xWVV/Y+cK33KM= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=