Refactor code.
This commit is contained in:
parent
c44598971b
commit
7cd8a2dce1
@ -32,7 +32,6 @@ import (
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/database/sql"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/interfaces"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/node"
|
||||
sdtypes "github.com/ethereum/go-ethereum/statediff/types"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
@ -196,14 +195,7 @@ var _ = Describe("API", func() {
|
||||
tx interfaces.Batch
|
||||
)
|
||||
|
||||
testInfo := node.Info{
|
||||
GenesisBlock: test_helpers.Genesis.Hash().String(),
|
||||
NetworkID: "1",
|
||||
ID: "1",
|
||||
ClientName: "geth",
|
||||
ChainID: params.TestChainConfig.ChainID.Uint64(),
|
||||
}
|
||||
db, err = eth.Setup(ctx, testInfo)
|
||||
db, err = eth.SetupDB(ctx, test_helpers.Genesis.Hash())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
indexAndPublisher, err := sql.NewStateDiffIndexer(ctx, chainConfig, db)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
@ -23,7 +23,6 @@ import (
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/database/sql"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/interfaces"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/models"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/node"
|
||||
"github.com/ethereum/go-ethereum/trie"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
@ -218,17 +217,9 @@ var _ = Describe("Retriever", func() {
|
||||
)
|
||||
BeforeEach(func() {
|
||||
var err error
|
||||
testInfo := node.Info{
|
||||
GenesisBlock: test_helpers.Genesis.Hash().String(),
|
||||
NetworkID: "2",
|
||||
ID: "2",
|
||||
ClientName: "geth",
|
||||
ChainID: params.TestChainConfig.ChainID.Uint64(),
|
||||
}
|
||||
db, err = eth.Setup(ctx, testInfo)
|
||||
db, err = eth.SetupDB(ctx, test_helpers.Genesis.Hash())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
diffIndexer, err = sql.NewStateDiffIndexer(ctx, params.TestChainConfig, db)
|
||||
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
retriever = eth.NewCIDRetriever(db)
|
||||
|
@ -33,7 +33,6 @@ import (
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/ethereum/go-ethereum/statediff"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/database/sql"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/node"
|
||||
sdtypes "github.com/ethereum/go-ethereum/statediff/types"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
@ -75,15 +74,7 @@ var _ = Describe("eth state reading tests", func() {
|
||||
It("test init", func() {
|
||||
// db and type initializations
|
||||
var err error
|
||||
testInfo := node.Info{
|
||||
GenesisBlock: test_helpers.Genesis.Hash().String(),
|
||||
NetworkID: "3",
|
||||
ID: "3",
|
||||
ClientName: "geth",
|
||||
ChainID: params.TestChainConfig.ChainID.Uint64(),
|
||||
}
|
||||
|
||||
db, err = eth.Setup(ctx, testInfo)
|
||||
db, err = eth.SetupDB(ctx, test_helpers.Genesis.Hash())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
transformer, err := sql.NewStateDiffIndexer(ctx, chainConfig, db)
|
||||
|
@ -20,7 +20,6 @@ import (
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/database/sql"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/interfaces"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/node"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
@ -40,15 +39,8 @@ var _ = Describe("IPLDFetcher", func() {
|
||||
err error
|
||||
tx interfaces.Batch
|
||||
)
|
||||
testInfo := node.Info{
|
||||
GenesisBlock: test_helpers.Genesis.Hash().String(),
|
||||
NetworkID: "4",
|
||||
ID: "4",
|
||||
ClientName: "geth",
|
||||
ChainID: params.TestChainConfig.ChainID.Uint64(),
|
||||
}
|
||||
|
||||
db, err = eth.Setup(ctx, testInfo)
|
||||
db, err = eth.SetupDB(ctx, test_helpers.Genesis.Hash())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
pubAndIndexer, err = sql.NewStateDiffIndexer(ctx, params.TestChainConfig, db)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
@ -20,6 +20,8 @@ import (
|
||||
"context"
|
||||
"os"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/database/sql"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/database/sql/postgres"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/models"
|
||||
@ -27,8 +29,15 @@ import (
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
func Setup(ctx context.Context, info node.Info) (sql.Database, error) {
|
||||
driver, err := postgres.NewSQLXDriver(ctx, getConfig(), info)
|
||||
func SetupDB(ctx context.Context, genHash common.Hash) (sql.Database, error) {
|
||||
testInfo := node.Info{
|
||||
GenesisBlock: genHash.String(),
|
||||
NetworkID: "1",
|
||||
ID: "1",
|
||||
ClientName: "geth",
|
||||
ChainID: params.TestChainConfig.ChainID.Uint64(),
|
||||
}
|
||||
driver, err := postgres.NewSQLXDriver(ctx, getConfig(), testInfo)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
return postgres.NewPostgresDB(driver), nil
|
||||
}
|
||||
|
@ -31,7 +31,6 @@ import (
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/ethereum/go-ethereum/statediff"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/database/sql"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/node"
|
||||
sdtypes "github.com/ethereum/go-ethereum/statediff/types"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
@ -66,14 +65,7 @@ var _ = Describe("GraphQL", func() {
|
||||
|
||||
It("test init", func() {
|
||||
var err error
|
||||
testInfo := node.Info{
|
||||
GenesisBlock: test_helpers.Genesis.Hash().String(),
|
||||
NetworkID: "5",
|
||||
ID: "5",
|
||||
ClientName: "geth",
|
||||
ChainID: params.TestChainConfig.ChainID.Uint64(),
|
||||
}
|
||||
db, err = eth.Setup(ctx, testInfo)
|
||||
db, err = eth.SetupDB(ctx, test_helpers.Genesis.Hash())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
transformer, err := sql.NewStateDiffIndexer(ctx, chainConfig, db)
|
||||
|
Loading…
Reference in New Issue
Block a user