add "small2" and refactor
This commit is contained in:
parent
6e0b733323
commit
4f2242eb71
@ -1,15 +1,16 @@
|
|||||||
package util_test
|
package chaindata_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/core/rawdb"
|
"github.com/ethereum/go-ethereum/core/rawdb"
|
||||||
|
"github.com/ethereum/go-ethereum/core/state"
|
||||||
|
|
||||||
"github.com/cerc-io/eth-testing/chaindata/util"
|
"github.com/cerc-io/eth-testing/chaindata/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func testReadChainData(t *testing.T, name string) {
|
func testReadChainData(t *testing.T, name string) {
|
||||||
ChainDataPath, AncientDataPath := util.ChainDataPaths(name)
|
ChainDataPath, AncientDataPath := util.GetChainData(name)
|
||||||
|
|
||||||
kvdb, ldberr := rawdb.NewLevelDBDatabase(ChainDataPath, 1024, 256, "vdb-geth", true)
|
kvdb, ldberr := rawdb.NewLevelDBDatabase(ChainDataPath, 1024, 256, "vdb-geth", true)
|
||||||
if ldberr != nil {
|
if ldberr != nil {
|
||||||
@ -33,10 +34,15 @@ func testReadChainData(t *testing.T, name string) {
|
|||||||
if header == nil {
|
if header == nil {
|
||||||
t.Fatalf("unable to read canonical header at height %d", height)
|
t.Fatalf("unable to read canonical header at height %d", height)
|
||||||
}
|
}
|
||||||
|
sdb := state.NewDatabase(edb)
|
||||||
|
_, err = sdb.OpenTrie(header.Root)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReadChainData(t *testing.T) {
|
func TestReadChainData(t *testing.T) {
|
||||||
for _, name := range []string{"small"} {
|
for _, name := range []string{"small", "small2"} {
|
||||||
t.Run(name, func(t *testing.T) { testReadChainData(t, name) })
|
t.Run(name, func(t *testing.T) { testReadChainData(t, name) })
|
||||||
}
|
}
|
||||||
}
|
}
|
BIN
chaindata/data/small2/000002.ldb
Normal file
BIN
chaindata/data/small2/000002.ldb
Normal file
Binary file not shown.
0
chaindata/data/small2/ancient/chain/FLOCK
Normal file
0
chaindata/data/small2/ancient/chain/FLOCK
Normal file
BIN
chaindata/data/small2/ancient/chain/bodies.cidx
Normal file
BIN
chaindata/data/small2/ancient/chain/bodies.cidx
Normal file
Binary file not shown.
1
chaindata/data/small2/ancient/chain/bodies.meta
Normal file
1
chaindata/data/small2/ancient/chain/bodies.meta
Normal file
@ -0,0 +1 @@
|
|||||||
|
<EFBFBD><01>
|
0
chaindata/data/small2/ancient/chain/diffs.0000.rdat
Normal file
0
chaindata/data/small2/ancient/chain/diffs.0000.rdat
Normal file
1
chaindata/data/small2/ancient/chain/diffs.meta
Normal file
1
chaindata/data/small2/ancient/chain/diffs.meta
Normal file
@ -0,0 +1 @@
|
|||||||
|
<EFBFBD><01>
|
BIN
chaindata/data/small2/ancient/chain/diffs.ridx
Normal file
BIN
chaindata/data/small2/ancient/chain/diffs.ridx
Normal file
Binary file not shown.
1
chaindata/data/small2/ancient/chain/hashes.meta
Normal file
1
chaindata/data/small2/ancient/chain/hashes.meta
Normal file
@ -0,0 +1 @@
|
|||||||
|
<EFBFBD><01>
|
BIN
chaindata/data/small2/ancient/chain/hashes.ridx
Normal file
BIN
chaindata/data/small2/ancient/chain/hashes.ridx
Normal file
Binary file not shown.
BIN
chaindata/data/small2/ancient/chain/headers.cidx
Normal file
BIN
chaindata/data/small2/ancient/chain/headers.cidx
Normal file
Binary file not shown.
1
chaindata/data/small2/ancient/chain/headers.meta
Normal file
1
chaindata/data/small2/ancient/chain/headers.meta
Normal file
@ -0,0 +1 @@
|
|||||||
|
<EFBFBD><01>
|
BIN
chaindata/data/small2/ancient/chain/receipts.cidx
Normal file
BIN
chaindata/data/small2/ancient/chain/receipts.cidx
Normal file
Binary file not shown.
1
chaindata/data/small2/ancient/chain/receipts.meta
Normal file
1
chaindata/data/small2/ancient/chain/receipts.meta
Normal file
@ -0,0 +1 @@
|
|||||||
|
<EFBFBD><01>
|
@ -5,5 +5,5 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ChainDataPath, AncientDataPath = util.ChainDataPaths("small")
|
ChainDataPath, AncientDataPath = util.GetChainData("small")
|
||||||
)
|
)
|
||||||
|
9
chaindata/small2/chain.go
Normal file
9
chaindata/small2/chain.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package small2
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/cerc-io/eth-testing/chaindata/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
ChainDataPath, AncientDataPath = util.GetChainData("small2")
|
||||||
|
)
|
@ -1,32 +1,55 @@
|
|||||||
package util
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ChainDataPath returns the absolute paths to fixture chaindata for the given name.
|
type ChainData struct {
|
||||||
// Currently the only chains are:
|
Path, AncientPath string
|
||||||
// - small: 32-block small-size chain
|
}
|
||||||
// - medium: a short medium-sized chain
|
|
||||||
func ChainDataPaths(chain string) (string, string) {
|
// List of names of chaindata fixtures accessible via ChainDataPaths
|
||||||
|
var FixtureChains = []string{
|
||||||
|
"small", "small2",
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsFixture(chain string) bool {
|
||||||
|
has := false
|
||||||
|
for _, fixture := range FixtureChains {
|
||||||
|
if chain == fixture {
|
||||||
|
has = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return has
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetChainData returns the absolute paths to fixture chaindata for the given name.
|
||||||
|
func GetChainData(chain string) (*ChainData, error) {
|
||||||
|
// fail if chain not in FixtureChains
|
||||||
|
if !IsFixture(chain) {
|
||||||
|
return nil, errors.New("no fixture named " + chain)
|
||||||
|
}
|
||||||
|
|
||||||
_, thisPath, _, ok := runtime.Caller(0)
|
_, thisPath, _, ok := runtime.Caller(0)
|
||||||
if !ok {
|
if !ok {
|
||||||
panic("could not get function source path")
|
return nil, errors.New("could not get function source path")
|
||||||
}
|
}
|
||||||
|
|
||||||
chainPath := filepath.Join(filepath.Dir(thisPath), "..", "data", chain)
|
chainPath := filepath.Join(filepath.Dir(thisPath), "..", "data", chain)
|
||||||
|
|
||||||
chaindataPath, err := filepath.Abs(chainPath)
|
chaindataPath, err := filepath.Abs(chainPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("cannot resolve path " + chainPath)
|
return nil, errors.New("cannot resolve path " + chainPath)
|
||||||
}
|
}
|
||||||
ancientdataPath := filepath.Join(chaindataPath, "ancient")
|
ancientdataPath := filepath.Join(chaindataPath, "ancient")
|
||||||
|
|
||||||
if _, err := os.Stat(chaindataPath); err != nil {
|
if _, err := os.Stat(chaindataPath); err != nil {
|
||||||
panic("must populate chaindata at " + chaindataPath)
|
return nil, errors.New("must populate chaindata at " + chaindataPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
return chaindataPath, ancientdataPath
|
return &ChainData{chaindataPath, ancientdataPath}, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user