Move SetupTestStateDiffIndexer to shared test helpers

This commit is contained in:
nabarun 2022-03-21 11:41:34 +05:30 committed by prathamesh0
parent 849b17f4bd
commit 77812f2673
10 changed files with 33 additions and 51 deletions

View File

@ -64,7 +64,7 @@ jobs:
DB_WRITE: true DB_WRITE: true
ETH_FORWARD_ETH_CALLS: false ETH_FORWARD_ETH_CALLS: false
ETH_PROXY_ON_ERROR: false ETH_PROXY_ON_ERROR: false
ETH_HTTP_PATH: "" ETH_HTTP_PATH: "dapptools:8545"
strategy: strategy:
matrix: matrix:
go-version: [1.16.x] go-version: [1.16.x]
@ -122,7 +122,7 @@ jobs:
DB_WRITE: true DB_WRITE: true
ETH_FORWARD_ETH_CALLS: false ETH_FORWARD_ETH_CALLS: false
ETH_PROXY_ON_ERROR: false ETH_PROXY_ON_ERROR: false
ETH_HTTP_PATH: "" ETH_HTTP_PATH: "dapptools:8545"
WATCHED_ADDRESS_GAP_FILLER_ENABLED: true WATCHED_ADDRESS_GAP_FILLER_ENABLED: true
WATCHED_ADDRESS_GAP_FILLER_INTERVAL: 2 WATCHED_ADDRESS_GAP_FILLER_INTERVAL: 2
strategy: strategy:

View File

@ -197,7 +197,7 @@ var _ = Describe("API", func() {
) )
db = shared.SetupDB() db = shared.SetupDB()
indexAndPublisher := eth.SetupTestStateDiffIndexer(ctx, chainConfig, test_helpers.Genesis.Hash()) indexAndPublisher := shared.SetupTestStateDiffIndexer(ctx, chainConfig, test_helpers.Genesis.Hash())
backend, err := eth.NewEthBackend(db, &eth.Config{ backend, err := eth.NewEthBackend(db, &eth.Config{
ChainConfig: chainConfig, ChainConfig: chainConfig,
@ -242,7 +242,7 @@ var _ = Describe("API", func() {
// setting chain config to for london block // setting chain config to for london block
chainConfig.LondonBlock = big.NewInt(2) chainConfig.LondonBlock = big.NewInt(2)
indexAndPublisher = eth.SetupTestStateDiffIndexer(ctx, chainConfig, test_helpers.Genesis.Hash()) indexAndPublisher = shared.SetupTestStateDiffIndexer(ctx, chainConfig, test_helpers.Genesis.Hash())
tx, err = indexAndPublisher.PushBlock(test_helpers.MockLondonBlock, test_helpers.MockLondonReceipts, test_helpers.MockLondonBlock.Difficulty()) tx, err = indexAndPublisher.PushBlock(test_helpers.MockLondonBlock, test_helpers.MockLondonReceipts, test_helpers.MockLondonBlock.Difficulty())
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())

View File

@ -217,7 +217,7 @@ var _ = Describe("Retriever", func() {
) )
BeforeEach(func() { BeforeEach(func() {
db = shared.SetupDB() db = shared.SetupDB()
diffIndexer = eth.SetupTestStateDiffIndexer(ctx, params.TestChainConfig, test_helpers.Genesis.Hash()) diffIndexer = shared.SetupTestStateDiffIndexer(ctx, params.TestChainConfig, test_helpers.Genesis.Hash())
retriever = eth.NewCIDRetriever(db) retriever = eth.NewCIDRetriever(db)
}) })

View File

@ -76,7 +76,7 @@ var _ = Describe("eth state reading tests", func() {
// db and type initializations // db and type initializations
var err error var err error
db = shared.SetupDB() db = shared.SetupDB()
transformer := eth.SetupTestStateDiffIndexer(ctx, chainConfig, test_helpers.Genesis.Hash()) transformer := shared.SetupTestStateDiffIndexer(ctx, chainConfig, test_helpers.Genesis.Hash())
backend, err = eth.NewEthBackend(db, &eth.Config{ backend, err = eth.NewEthBackend(db, &eth.Config{
ChainConfig: chainConfig, ChainConfig: chainConfig,
@ -156,7 +156,7 @@ var _ = Describe("eth state reading tests", func() {
} }
// Insert some non-canonical data into the database so that we test our ability to discern canonicity // Insert some non-canonical data into the database so that we test our ability to discern canonicity
indexAndPublisher := eth.SetupTestStateDiffIndexer(ctx, chainConfig, test_helpers.Genesis.Hash()) indexAndPublisher := shared.SetupTestStateDiffIndexer(ctx, chainConfig, test_helpers.Genesis.Hash())
tx, err := indexAndPublisher.PushBlock(test_helpers.MockBlock, test_helpers.MockReceipts, test_helpers.MockBlock.Difficulty()) tx, err := indexAndPublisher.PushBlock(test_helpers.MockBlock, test_helpers.MockReceipts, test_helpers.MockBlock.Difficulty())
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())

View File

@ -41,7 +41,7 @@ var _ = Describe("IPLDFetcher", func() {
tx interfaces.Batch tx interfaces.Batch
) )
db = shared.SetupDB() db = shared.SetupDB()
pubAndIndexer = eth.SetupTestStateDiffIndexer(ctx, params.TestChainConfig, test_helpers.Genesis.Hash()) pubAndIndexer = shared.SetupTestStateDiffIndexer(ctx, params.TestChainConfig, test_helpers.Genesis.Hash())
tx, err = pubAndIndexer.PushBlock(test_helpers.MockBlock, test_helpers.MockReceipts, test_helpers.MockBlock.Difficulty()) tx, err = pubAndIndexer.PushBlock(test_helpers.MockBlock, test_helpers.MockReceipts, test_helpers.MockBlock.Difficulty())
for _, node := range test_helpers.MockStateNodes { for _, node := range test_helpers.MockStateNodes {

View File

@ -17,35 +17,9 @@
package eth package eth
import ( import (
"context"
"os"
"strconv"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/statediff/indexer"
"github.com/ethereum/go-ethereum/statediff/indexer/database/sql/postgres"
"github.com/ethereum/go-ethereum/statediff/indexer/interfaces"
"github.com/ethereum/go-ethereum/statediff/indexer/models" "github.com/ethereum/go-ethereum/statediff/indexer/models"
"github.com/ethereum/go-ethereum/statediff/indexer/node"
. "github.com/onsi/gomega"
) )
func SetupTestStateDiffIndexer(ctx context.Context, chainConfig *params.ChainConfig, genHash common.Hash) interfaces.StateDiffIndexer {
testInfo := node.Info{
GenesisBlock: genHash.String(),
NetworkID: "1",
ID: "1",
ClientName: "geth",
ChainID: params.TestChainConfig.ChainID.Uint64(),
}
stateDiffIndexer, err := indexer.NewStateDiffIndexer(ctx, chainConfig, testInfo, getTestDBConfig())
Expect(err).NotTo(HaveOccurred())
return stateDiffIndexer
}
// TxModelsContainsCID used to check if a list of TxModels contains a specific cid string // TxModelsContainsCID used to check if a list of TxModels contains a specific cid string
func TxModelsContainsCID(txs []models.TxModel, cid string) bool { func TxModelsContainsCID(txs []models.TxModel, cid string) bool {
for _, tx := range txs { for _, tx := range txs {
@ -65,15 +39,3 @@ func ReceiptModelsContainsCID(rcts []models.ReceiptModel, cid string) bool {
} }
return false return false
} }
func getTestDBConfig() postgres.Config {
port, _ := strconv.Atoi(os.Getenv("DATABASE_PORT"))
return postgres.Config{
Hostname: os.Getenv("DATABASE_HOSTNAME"),
DatabaseName: os.Getenv("DATABASE_NAME"),
Username: os.Getenv("DATABASE_USER"),
Password: os.Getenv("DATABASE_PASSWORD"),
Port: port,
Driver: postgres.PGX,
}
}

View File

@ -28,7 +28,6 @@ import (
sdtypes "github.com/ethereum/go-ethereum/statediff/types" sdtypes "github.com/ethereum/go-ethereum/statediff/types"
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
"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/eth/test_helpers"
fill "github.com/vulcanize/ipld-eth-server/pkg/fill" fill "github.com/vulcanize/ipld-eth-server/pkg/fill"
"github.com/vulcanize/ipld-eth-server/pkg/serve" "github.com/vulcanize/ipld-eth-server/pkg/serve"
@ -57,7 +56,7 @@ var _ = Describe("Service", func() {
// indexer initialization // indexer initialization
// statediffIndexer, err = indexer.NewStateDiffIndexer(nil, db) // statediffIndexer, err = indexer.NewStateDiffIndexer(nil, db)
statediffIndexer = eth.SetupTestStateDiffIndexer(ctx, chainConfig, test_helpers.Genesis.Hash()) statediffIndexer = shared.SetupTestStateDiffIndexer(ctx, chainConfig, test_helpers.Genesis.Hash())
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
// fill service intialization // fill service intialization

View File

@ -67,7 +67,7 @@ var _ = Describe("GraphQL", func() {
It("test init", func() { It("test init", func() {
var err error var err error
db = shared.SetupDB() db = shared.SetupDB()
transformer := eth.SetupTestStateDiffIndexer(ctx, chainConfig, test_helpers.Genesis.Hash()) transformer := shared.SetupTestStateDiffIndexer(ctx, chainConfig, test_helpers.Genesis.Hash())
backend, err = eth.NewEthBackend(db, &eth.Config{ backend, err = eth.NewEthBackend(db, &eth.Config{
ChainConfig: chainConfig, ChainConfig: chainConfig,
@ -131,7 +131,7 @@ var _ = Describe("GraphQL", func() {
} }
// Insert some non-canonical data into the database so that we test our ability to discern canonicity // Insert some non-canonical data into the database so that we test our ability to discern canonicity
indexAndPublisher := eth.SetupTestStateDiffIndexer(ctx, chainConfig, test_helpers.Genesis.Hash()) indexAndPublisher := shared.SetupTestStateDiffIndexer(ctx, chainConfig, test_helpers.Genesis.Hash())
blockHash = test_helpers.MockBlock.Hash() blockHash = test_helpers.MockBlock.Hash()
contractAddress = test_helpers.ContractAddr contractAddress = test_helpers.ContractAddr

View File

@ -18,13 +18,19 @@ package shared
import ( import (
"bytes" "bytes"
"context"
"os" "os"
"strconv" "strconv"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/statediff/indexer"
"github.com/ethereum/go-ethereum/statediff/indexer/database/sql/postgres" "github.com/ethereum/go-ethereum/statediff/indexer/database/sql/postgres"
"github.com/ethereum/go-ethereum/statediff/indexer/interfaces"
"github.com/ethereum/go-ethereum/statediff/indexer/models" "github.com/ethereum/go-ethereum/statediff/indexer/models"
"github.com/ethereum/go-ethereum/statediff/indexer/node"
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
) )
@ -73,6 +79,21 @@ func TearDownDB(db *sqlx.DB) {
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
} }
func SetupTestStateDiffIndexer(ctx context.Context, chainConfig *params.ChainConfig, genHash common.Hash) interfaces.StateDiffIndexer {
testInfo := node.Info{
GenesisBlock: genHash.String(),
NetworkID: "1",
ID: "1",
ClientName: "geth",
ChainID: params.TestChainConfig.ChainID.Uint64(),
}
stateDiffIndexer, err := indexer.NewStateDiffIndexer(ctx, chainConfig, testInfo, getTestDBConfig())
Expect(err).NotTo(HaveOccurred())
return stateDiffIndexer
}
func getTestDBConfig() postgres.Config { func getTestDBConfig() postgres.Config {
port, _ := strconv.Atoi(os.Getenv("DATABASE_PORT")) port, _ := strconv.Atoi(os.Getenv("DATABASE_PORT"))
return postgres.Config{ return postgres.Config{

View File

@ -410,7 +410,7 @@ var _ = Describe("Integration test", func() {
Expect(gethStorage).To(Equal(ipldStorage)) Expect(gethStorage).To(Equal(ipldStorage))
}) })
It("get storage for SLV countA", func() { It("get storage for SLV countA after tx", func() {
slvContract, contractErr = integration.Create2Contract("SLVToken", contractSalt) slvContract, contractErr = integration.Create2Contract("SLVToken", contractSalt)
Expect(contractErr).ToNot(HaveOccurred()) Expect(contractErr).ToNot(HaveOccurred())
countAIndex := "0x5" countAIndex := "0x5"