diff --git a/chaindata/util/chaindata_test.go b/chaindata/chaindata_test.go similarity index 76% rename from chaindata/util/chaindata_test.go rename to chaindata/chaindata_test.go index 6fa3f3c..0583364 100644 --- a/chaindata/util/chaindata_test.go +++ b/chaindata/chaindata_test.go @@ -1,15 +1,16 @@ -package util_test +package chaindata_test import ( "testing" "github.com/ethereum/go-ethereum/core/rawdb" + "github.com/ethereum/go-ethereum/core/state" "github.com/cerc-io/eth-testing/chaindata/util" ) 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) if ldberr != nil { @@ -33,10 +34,15 @@ func testReadChainData(t *testing.T, name string) { if header == nil { 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) { - for _, name := range []string{"small"} { + for _, name := range []string{"small", "small2"} { t.Run(name, func(t *testing.T) { testReadChainData(t, name) }) } } diff --git a/chaindata/data/small2/000002.ldb b/chaindata/data/small2/000002.ldb new file mode 100644 index 0000000..5770fee Binary files /dev/null and b/chaindata/data/small2/000002.ldb differ diff --git a/chaindata/data/small2/ancient/chain/FLOCK b/chaindata/data/small2/ancient/chain/FLOCK new file mode 100644 index 0000000..e69de29 diff --git a/chaindata/data/small2/ancient/chain/bodies.0000.cdat b/chaindata/data/small2/ancient/chain/bodies.0000.cdat new file mode 100644 index 0000000..e69de29 diff --git a/chaindata/data/small2/ancient/chain/bodies.cidx b/chaindata/data/small2/ancient/chain/bodies.cidx new file mode 100644 index 0000000..ab2c684 Binary files /dev/null and b/chaindata/data/small2/ancient/chain/bodies.cidx differ diff --git a/chaindata/data/small2/ancient/chain/bodies.meta b/chaindata/data/small2/ancient/chain/bodies.meta new file mode 100644 index 0000000..59ee616 --- /dev/null +++ b/chaindata/data/small2/ancient/chain/bodies.meta @@ -0,0 +1 @@ +€ \ No newline at end of file diff --git a/chaindata/data/small2/ancient/chain/diffs.0000.rdat b/chaindata/data/small2/ancient/chain/diffs.0000.rdat new file mode 100644 index 0000000..e69de29 diff --git a/chaindata/data/small2/ancient/chain/diffs.meta b/chaindata/data/small2/ancient/chain/diffs.meta new file mode 100644 index 0000000..59ee616 --- /dev/null +++ b/chaindata/data/small2/ancient/chain/diffs.meta @@ -0,0 +1 @@ +€ \ No newline at end of file diff --git a/chaindata/data/small2/ancient/chain/diffs.ridx b/chaindata/data/small2/ancient/chain/diffs.ridx new file mode 100644 index 0000000..ab2c684 Binary files /dev/null and b/chaindata/data/small2/ancient/chain/diffs.ridx differ diff --git a/chaindata/data/small2/ancient/chain/hashes.0000.rdat b/chaindata/data/small2/ancient/chain/hashes.0000.rdat new file mode 100644 index 0000000..e69de29 diff --git a/chaindata/data/small2/ancient/chain/hashes.meta b/chaindata/data/small2/ancient/chain/hashes.meta new file mode 100644 index 0000000..59ee616 --- /dev/null +++ b/chaindata/data/small2/ancient/chain/hashes.meta @@ -0,0 +1 @@ +€ \ No newline at end of file diff --git a/chaindata/data/small2/ancient/chain/hashes.ridx b/chaindata/data/small2/ancient/chain/hashes.ridx new file mode 100644 index 0000000..ab2c684 Binary files /dev/null and b/chaindata/data/small2/ancient/chain/hashes.ridx differ diff --git a/chaindata/data/small2/ancient/chain/headers.0000.cdat b/chaindata/data/small2/ancient/chain/headers.0000.cdat new file mode 100644 index 0000000..e69de29 diff --git a/chaindata/data/small2/ancient/chain/headers.cidx b/chaindata/data/small2/ancient/chain/headers.cidx new file mode 100644 index 0000000..ab2c684 Binary files /dev/null and b/chaindata/data/small2/ancient/chain/headers.cidx differ diff --git a/chaindata/data/small2/ancient/chain/headers.meta b/chaindata/data/small2/ancient/chain/headers.meta new file mode 100644 index 0000000..59ee616 --- /dev/null +++ b/chaindata/data/small2/ancient/chain/headers.meta @@ -0,0 +1 @@ +€ \ No newline at end of file diff --git a/chaindata/data/small2/ancient/chain/receipts.0000.cdat b/chaindata/data/small2/ancient/chain/receipts.0000.cdat new file mode 100644 index 0000000..e69de29 diff --git a/chaindata/data/small2/ancient/chain/receipts.cidx b/chaindata/data/small2/ancient/chain/receipts.cidx new file mode 100644 index 0000000..ab2c684 Binary files /dev/null and b/chaindata/data/small2/ancient/chain/receipts.cidx differ diff --git a/chaindata/data/small2/ancient/chain/receipts.meta b/chaindata/data/small2/ancient/chain/receipts.meta new file mode 100644 index 0000000..59ee616 --- /dev/null +++ b/chaindata/data/small2/ancient/chain/receipts.meta @@ -0,0 +1 @@ +€ \ No newline at end of file diff --git a/chaindata/small/chain.go b/chaindata/small/chain.go index 8daaf81..75a891b 100644 --- a/chaindata/small/chain.go +++ b/chaindata/small/chain.go @@ -5,5 +5,5 @@ import ( ) var ( - ChainDataPath, AncientDataPath = util.ChainDataPaths("small") + ChainDataPath, AncientDataPath = util.GetChainData("small") ) diff --git a/chaindata/small2/chain.go b/chaindata/small2/chain.go new file mode 100644 index 0000000..1e5f392 --- /dev/null +++ b/chaindata/small2/chain.go @@ -0,0 +1,9 @@ +package small2 + +import ( + "github.com/cerc-io/eth-testing/chaindata/util" +) + +var ( + ChainDataPath, AncientDataPath = util.GetChainData("small2") +) diff --git a/chaindata/util/chaindata.go b/chaindata/util/chaindata.go index c4ebfa8..7f1d5b0 100644 --- a/chaindata/util/chaindata.go +++ b/chaindata/util/chaindata.go @@ -1,32 +1,55 @@ package util import ( + "errors" "os" "path/filepath" "runtime" ) -// ChainDataPath returns the absolute paths to fixture chaindata for the given name. -// Currently the only chains are: -// - small: 32-block small-size chain -// - medium: a short medium-sized chain -func ChainDataPaths(chain string) (string, string) { +type ChainData struct { + Path, AncientPath 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) 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) chaindataPath, err := filepath.Abs(chainPath) if err != nil { - panic("cannot resolve path " + chainPath) + return nil, errors.New("cannot resolve path " + chainPath) } ancientdataPath := filepath.Join(chaindataPath, "ancient") 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 }