Add unit tests for fill service
This commit is contained in:
+3
-2
@@ -38,6 +38,7 @@ import (
|
||||
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/eth"
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/eth/test_helpers"
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/shared"
|
||||
ethServerShared "github.com/vulcanize/ipld-eth-server/pkg/shared"
|
||||
)
|
||||
|
||||
@@ -195,7 +196,7 @@ var _ = Describe("API", func() {
|
||||
tx interfaces.Batch
|
||||
)
|
||||
|
||||
db = eth.SetupTestDB()
|
||||
db = shared.SetupDB()
|
||||
indexAndPublisher := eth.SetupTestStateDiffIndexer(ctx, chainConfig, test_helpers.Genesis.Hash())
|
||||
|
||||
backend, err := eth.NewEthBackend(db, ð.Config{
|
||||
@@ -251,7 +252,7 @@ var _ = Describe("API", func() {
|
||||
})
|
||||
|
||||
// Single test db tear down at end of all tests
|
||||
defer It("test teardown", func() { eth.TearDownTestDB(db) })
|
||||
defer It("test teardown", func() { shared.TearDownDB(db) })
|
||||
/*
|
||||
|
||||
Headers and blocks
|
||||
|
||||
@@ -31,6 +31,7 @@ import (
|
||||
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/eth"
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/eth/test_helpers"
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/shared"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -215,13 +216,13 @@ var _ = Describe("Retriever", func() {
|
||||
retriever *eth.CIDRetriever
|
||||
)
|
||||
BeforeEach(func() {
|
||||
db = eth.SetupTestDB()
|
||||
db = shared.SetupDB()
|
||||
diffIndexer = eth.SetupTestStateDiffIndexer(ctx, params.TestChainConfig, test_helpers.Genesis.Hash())
|
||||
|
||||
retriever = eth.NewCIDRetriever(db)
|
||||
})
|
||||
AfterEach(func() {
|
||||
eth.TearDownTestDB(db)
|
||||
shared.TearDownDB(db)
|
||||
})
|
||||
|
||||
Describe("Retrieve", func() {
|
||||
|
||||
@@ -39,6 +39,7 @@ import (
|
||||
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/eth"
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/eth/test_helpers"
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/shared"
|
||||
ethServerShared "github.com/vulcanize/ipld-eth-server/pkg/shared"
|
||||
)
|
||||
|
||||
@@ -74,7 +75,7 @@ var _ = Describe("eth state reading tests", func() {
|
||||
It("test init", func() {
|
||||
// db and type initializations
|
||||
var err error
|
||||
db = eth.SetupTestDB()
|
||||
db = shared.SetupDB()
|
||||
transformer := eth.SetupTestStateDiffIndexer(ctx, chainConfig, test_helpers.Genesis.Hash())
|
||||
|
||||
backend, err = eth.NewEthBackend(db, ð.Config{
|
||||
@@ -181,7 +182,7 @@ var _ = Describe("eth state reading tests", func() {
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
defer It("test teardown", func() {
|
||||
eth.TearDownTestDB(db)
|
||||
shared.TearDownDB(db)
|
||||
chain.Stop()
|
||||
})
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/eth"
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/eth/test_helpers"
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/shared"
|
||||
)
|
||||
|
||||
var _ = Describe("IPLDFetcher", func() {
|
||||
@@ -39,7 +40,7 @@ var _ = Describe("IPLDFetcher", func() {
|
||||
err error
|
||||
tx interfaces.Batch
|
||||
)
|
||||
db = eth.SetupTestDB()
|
||||
db = shared.SetupDB()
|
||||
pubAndIndexer = eth.SetupTestStateDiffIndexer(ctx, params.TestChainConfig, test_helpers.Genesis.Hash())
|
||||
|
||||
tx, err = pubAndIndexer.PushBlock(test_helpers.MockBlock, test_helpers.MockReceipts, test_helpers.MockBlock.Difficulty())
|
||||
@@ -54,7 +55,7 @@ var _ = Describe("IPLDFetcher", func() {
|
||||
|
||||
})
|
||||
AfterEach(func() {
|
||||
eth.TearDownTestDB(db)
|
||||
shared.TearDownDB(db)
|
||||
})
|
||||
|
||||
It("Fetches and returns IPLDs for the CIDs provided in the CIDWrapper", func() {
|
||||
|
||||
@@ -28,41 +28,9 @@ import (
|
||||
"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/jmoiron/sqlx"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/vulcanize/ipld-eth-server/pkg/shared"
|
||||
)
|
||||
|
||||
func SetupTestDB() *sqlx.DB {
|
||||
config := getTestDBConfig()
|
||||
|
||||
db, err := shared.NewDB(config.DbConnectionString(), config)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
return db
|
||||
}
|
||||
|
||||
// TearDownTestDB is used to tear down the watcher dbs after tests
|
||||
func TearDownTestDB(db *sqlx.DB) {
|
||||
tx, err := db.Beginx()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
_, err = tx.Exec(`DELETE FROM eth.transaction_cids`)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
_, err = tx.Exec(`DELETE FROM eth.receipt_cids`)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
_, err = tx.Exec(`DELETE FROM eth.state_cids`)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
_, err = tx.Exec(`DELETE FROM eth.storage_cids`)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
_, err = tx.Exec(`DELETE FROM blocks`)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
_, err = tx.Exec(`DELETE FROM eth.log_cids`)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
err = tx.Commit()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
|
||||
func SetupTestStateDiffIndexer(ctx context.Context, chainConfig *params.ChainConfig, genHash common.Hash) interfaces.StateDiffIndexer {
|
||||
testInfo := node.Info{
|
||||
GenesisBlock: genHash.String(),
|
||||
|
||||
Reference in New Issue
Block a user