From 77812f26734022e6a09cd813fea7c70503226d49 Mon Sep 17 00:00:00 2001 From: nabarun Date: Mon, 21 Mar 2022 11:41:34 +0530 Subject: [PATCH] Move SetupTestStateDiffIndexer to shared test helpers --- .github/workflows/on-pr.yaml | 4 ++-- pkg/eth/api_test.go | 4 ++-- pkg/eth/cid_retriever_test.go | 2 +- pkg/eth/eth_state_test.go | 4 ++-- pkg/eth/ipld_fetcher_test.go | 2 +- pkg/eth/test_helpers.go | 38 ----------------------------------- pkg/fill/service_test.go | 3 +-- pkg/graphql/graphql_test.go | 4 ++-- pkg/shared/test_helpers.go | 21 +++++++++++++++++++ test/integration_test.go | 2 +- 10 files changed, 33 insertions(+), 51 deletions(-) diff --git a/.github/workflows/on-pr.yaml b/.github/workflows/on-pr.yaml index 9b6235fb..2fc0f567 100644 --- a/.github/workflows/on-pr.yaml +++ b/.github/workflows/on-pr.yaml @@ -64,7 +64,7 @@ jobs: DB_WRITE: true ETH_FORWARD_ETH_CALLS: false ETH_PROXY_ON_ERROR: false - ETH_HTTP_PATH: "" + ETH_HTTP_PATH: "dapptools:8545" strategy: matrix: go-version: [1.16.x] @@ -122,7 +122,7 @@ jobs: DB_WRITE: true ETH_FORWARD_ETH_CALLS: false ETH_PROXY_ON_ERROR: false - ETH_HTTP_PATH: "" + ETH_HTTP_PATH: "dapptools:8545" WATCHED_ADDRESS_GAP_FILLER_ENABLED: true WATCHED_ADDRESS_GAP_FILLER_INTERVAL: 2 strategy: diff --git a/pkg/eth/api_test.go b/pkg/eth/api_test.go index 62d77140..f76ea6ba 100644 --- a/pkg/eth/api_test.go +++ b/pkg/eth/api_test.go @@ -197,7 +197,7 @@ var _ = Describe("API", func() { ) 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, ð.Config{ ChainConfig: chainConfig, @@ -242,7 +242,7 @@ var _ = Describe("API", func() { // setting chain config to for london block 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()) Expect(err).ToNot(HaveOccurred()) diff --git a/pkg/eth/cid_retriever_test.go b/pkg/eth/cid_retriever_test.go index 1aa62ad3..b8b28f34 100644 --- a/pkg/eth/cid_retriever_test.go +++ b/pkg/eth/cid_retriever_test.go @@ -217,7 +217,7 @@ var _ = Describe("Retriever", func() { ) BeforeEach(func() { 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) }) diff --git a/pkg/eth/eth_state_test.go b/pkg/eth/eth_state_test.go index 362089c9..887e6d35 100644 --- a/pkg/eth/eth_state_test.go +++ b/pkg/eth/eth_state_test.go @@ -76,7 +76,7 @@ var _ = Describe("eth state reading tests", func() { // db and type initializations var err error 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, ð.Config{ 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 - 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()) Expect(err).ToNot(HaveOccurred()) diff --git a/pkg/eth/ipld_fetcher_test.go b/pkg/eth/ipld_fetcher_test.go index 668966fb..dc93be77 100644 --- a/pkg/eth/ipld_fetcher_test.go +++ b/pkg/eth/ipld_fetcher_test.go @@ -41,7 +41,7 @@ var _ = Describe("IPLDFetcher", func() { tx interfaces.Batch ) 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()) for _, node := range test_helpers.MockStateNodes { diff --git a/pkg/eth/test_helpers.go b/pkg/eth/test_helpers.go index 19625adb..f59f4b43 100644 --- a/pkg/eth/test_helpers.go +++ b/pkg/eth/test_helpers.go @@ -17,35 +17,9 @@ package eth 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/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 func TxModelsContainsCID(txs []models.TxModel, cid string) bool { for _, tx := range txs { @@ -65,15 +39,3 @@ func ReceiptModelsContainsCID(rcts []models.ReceiptModel, cid string) bool { } 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, - } -} diff --git a/pkg/fill/service_test.go b/pkg/fill/service_test.go index 7d4b19ae..83b3990a 100644 --- a/pkg/fill/service_test.go +++ b/pkg/fill/service_test.go @@ -28,7 +28,6 @@ import ( sdtypes "github.com/ethereum/go-ethereum/statediff/types" "github.com/jmoiron/sqlx" - "github.com/vulcanize/ipld-eth-server/pkg/eth" "github.com/vulcanize/ipld-eth-server/pkg/eth/test_helpers" fill "github.com/vulcanize/ipld-eth-server/pkg/fill" "github.com/vulcanize/ipld-eth-server/pkg/serve" @@ -57,7 +56,7 @@ var _ = Describe("Service", func() { // indexer initialization // 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()) // fill service intialization diff --git a/pkg/graphql/graphql_test.go b/pkg/graphql/graphql_test.go index 1770ef25..00cc381a 100644 --- a/pkg/graphql/graphql_test.go +++ b/pkg/graphql/graphql_test.go @@ -67,7 +67,7 @@ var _ = Describe("GraphQL", func() { It("test init", func() { var err error 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, ð.Config{ 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 - indexAndPublisher := eth.SetupTestStateDiffIndexer(ctx, chainConfig, test_helpers.Genesis.Hash()) + indexAndPublisher := shared.SetupTestStateDiffIndexer(ctx, chainConfig, test_helpers.Genesis.Hash()) blockHash = test_helpers.MockBlock.Hash() contractAddress = test_helpers.ContractAddr diff --git a/pkg/shared/test_helpers.go b/pkg/shared/test_helpers.go index d2b0e56d..3bb14683 100644 --- a/pkg/shared/test_helpers.go +++ b/pkg/shared/test_helpers.go @@ -18,13 +18,19 @@ package shared import ( "bytes" + "context" "os" "strconv" . "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/interfaces" "github.com/ethereum/go-ethereum/statediff/indexer/models" + "github.com/ethereum/go-ethereum/statediff/indexer/node" "github.com/jmoiron/sqlx" ) @@ -73,6 +79,21 @@ func TearDownDB(db *sqlx.DB) { 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 { port, _ := strconv.Atoi(os.Getenv("DATABASE_PORT")) return postgres.Config{ diff --git a/test/integration_test.go b/test/integration_test.go index b4a332f1..cb2850ab 100644 --- a/test/integration_test.go +++ b/test/integration_test.go @@ -410,7 +410,7 @@ var _ = Describe("Integration test", func() { 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) Expect(contractErr).ToNot(HaveOccurred()) countAIndex := "0x5"