Add post-Merge fixtures and refactor #6
@ -1,4 +1,4 @@
|
||||
package chaindata
|
||||
package chains
|
||||
|
||||
import (
|
||||
"errors"
|
||||
@ -14,7 +14,9 @@ type Paths struct {
|
||||
|
||||
// List of names of chaindata fixtures accessible via ChainDataPaths
|
||||
var FixtureChains = []string{
|
||||
"small", "small2",
|
||||
"premerge1",
|
||||
"premerge2",
|
||||
"postmerge1",
|
||||
}
|
||||
|
||||
func IsFixture(chain string) bool {
|
||||
@ -41,20 +43,25 @@ func GetFixture(chain string) (*Paths, error) {
|
||||
return nil, errors.New("could not get function source path")
|
||||
}
|
||||
|
||||
chaindataPath := filepath.Join(filepath.Dir(thisPath), "_data", chain)
|
||||
chaindataPath := filepath.Join(filepath.Dir(thisPath), "data", chain, "geth", "chaindata")
|
||||
if _, err := os.Stat(chaindataPath); err != nil {
|
||||
return nil, errors.New("cannot access chaindata at " + chaindataPath)
|
||||
}
|
||||
|
||||
// Copy chaindata directory to a temporary directory
|
||||
// Note that we assume the ancient path is a subdirectory
|
||||
copyTo := filepath.Join(os.TempDir(), chain)
|
||||
copyTo, err := os.MkdirTemp("", chain+"-chaindata-*")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := copyDir(chaindataPath, copyTo); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ancientCopy := filepath.Join(copyTo, "ancient")
|
||||
|
||||
return &Paths{copyTo, ancientCopy}, nil
|
||||
return &Paths{
|
||||
copyTo,
|
||||
filepath.Join(copyTo, "ancient"),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func copyDir(src, dest string) error {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package chaindata_test
|
||||
package chains_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
@ -6,15 +6,18 @@ import (
|
||||
"github.com/ethereum/go-ethereum/core/rawdb"
|
||||
"github.com/ethereum/go-ethereum/core/state"
|
||||
|
||||
"github.com/cerc-io/eth-testing/chaindata"
|
||||
"github.com/cerc-io/eth-testing/chains"
|
||||
)
|
||||
|
||||
func testReadChainData(t *testing.T, data *chaindata.Paths) {
|
||||
kvdb, ldberr := rawdb.NewLevelDBDatabase(data.ChainData, 1024, 256, t.Name(), true)
|
||||
if ldberr != nil {
|
||||
t.Fatal(ldberr)
|
||||
}
|
||||
edb, err := rawdb.NewDatabaseWithFreezer(kvdb, data.Ancient, t.Name(), true)
|
||||
func testReadChainData(t *testing.T, data *chains.Paths) {
|
||||
edb, err := rawdb.Open(rawdb.OpenOptions{
|
||||
Directory: data.ChainData,
|
||||
AncientsDirectory: data.Ancient,
|
||||
Namespace: t.Name(),
|
||||
Cache: 1024,
|
||||
Handles: 256,
|
||||
ReadOnly: true,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -47,9 +50,9 @@ func testReadChainData(t *testing.T, data *chaindata.Paths) {
|
||||
}
|
||||
|
||||
func TestReadChainData(t *testing.T) {
|
||||
for _, name := range []string{"permerge1", "premerge2", "postmerge1"} {
|
||||
for _, name := range chains.FixtureChains {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
data, err := chaindata.GetFixture(name)
|
||||
data, err := chains.GetFixture(name)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user