Fix function, add test #2

Merged
roysc merged 2 commits from dev into main 2023-09-19 16:37:36 +00:00
4 changed files with 67 additions and 0 deletions
Showing only changes of commit 1a95309093 - Show all commits

View File

@ -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)
}
}

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) })
}
}

1
go.mod
View File

@ -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

1
go.sum
View File

@ -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=