From e0bce193ed3180604135ca29ce4ddcfd89c42d5d Mon Sep 17 00:00:00 2001 From: Jordan Krage Date: Thu, 11 Jan 2024 18:11:15 -0600 Subject: [PATCH] integration-tests/smoke: TestOCRv2BasicWithChainReaderAndCodec add subtests for pulgins and chainreader/codec --- .../smoke/chain_reader_and_codec_test.go | 203 ++++++++++-------- 1 file changed, 112 insertions(+), 91 deletions(-) diff --git a/integration-tests/smoke/chain_reader_and_codec_test.go b/integration-tests/smoke/chain_reader_and_codec_test.go index 3eb81820dc9..d721c13bbc3 100644 --- a/integration-tests/smoke/chain_reader_and_codec_test.go +++ b/integration-tests/smoke/chain_reader_and_codec_test.go @@ -12,6 +12,7 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" "github.com/smartcontractkit/chainlink-testing-framework/logging" "github.com/smartcontractkit/chainlink-testing-framework/utils/ptr" + "github.com/smartcontractkit/chainlink/v2/core/config/env" "github.com/smartcontractkit/chainlink/v2/core/services/chainlink" "github.com/smartcontractkit/chainlink/v2/core/utils" @@ -23,96 +24,116 @@ import ( ) func TestOCRv2BasicWithChainReaderAndCodec(t *testing.T) { - l := logging.GetTestLogger(t) - - env, err := test_env.NewCLTestEnvBuilder(). - WithTestInstance(t). - WithGeth(). - WithMockAdapter(). - WithCLNodeConfig(node.NewConfig(node.NewBaseConfig(), - node.WithOCR2(), - node.WithP2Pv2(), - node.WithTracing(), - func(c *chainlink.Config) { - c.Core.WebServer.HTTPMaxSize = ptr.Ptr(utils.FileSize(65536)) - }, - )). - WithCLNodes(6). - WithFunding(big.NewFloat(.1)). - WithStandardCleanup(). - WithLogStream(). - Build() - fmt.Println("Done starting") - - env.ParallelTransactions(true) - - nodeClients := env.ClCluster.NodeAPIs() - bootstrapNode, workerNodes := nodeClients[0], nodeClients[1:] - - linkToken, err := env.ContractDeployer.DeployLinkTokenContract() - require.NoError(t, err, "Deploying Link Token Contract shouldn't fail") - - err = actions.FundChainlinkNodesLocal(workerNodes, env.EVMClient, big.NewFloat(.05)) - require.NoError(t, err, "Error funding Chainlink nodes") - - // Gather transmitters - var transmitters []string - for _, node := range workerNodes { - addr, err := node.PrimaryEthAddress() - if err != nil { - require.NoError(t, fmt.Errorf("error getting node's primary ETH address: %w", err)) - } - transmitters = append(transmitters, addr) + t.Parallel() + + noMedianPlugin := map[string]string{string(env.MedianPluginCmd): ""} + medianPlugin := map[string]string{string(env.MedianPluginCmd): "chainlink-feeds"} + for _, test := range []struct { + name string + env map[string]string + chainReaderAndCodec bool + }{ + {"legacy", noMedianPlugin, false}, + {"legacy-chain-reader", noMedianPlugin, true}, + {"plugins", medianPlugin, false}, + {"plugins-chain-reader", medianPlugin, true}, + } { + test := test + t.Run(test.name, func(t *testing.T) { + t.Parallel() + + l := logging.GetTestLogger(t) + + env, err := test_env.NewCLTestEnvBuilder(). + WithTestInstance(t). + WithGeth(). + WithMockAdapter(). + WithCLNodeConfig(node.NewConfig(node.NewBaseConfig(), + node.WithOCR2(), + node.WithP2Pv2(), + node.WithTracing(), + func(c *chainlink.Config) { + c.Core.WebServer.HTTPMaxSize = ptr.Ptr(utils.FileSize(65536)) + }, + )). + WithCLNodes(6). + WithFunding(big.NewFloat(.1)). + WithStandardCleanup(). + WithLogStream(). + Build() + fmt.Println("Done starting") + + env.ParallelTransactions(true) + + nodeClients := env.ClCluster.NodeAPIs() + bootstrapNode, workerNodes := nodeClients[0], nodeClients[1:] + + linkToken, err := env.ContractDeployer.DeployLinkTokenContract() + require.NoError(t, err, "Deploying Link Token Contract shouldn't fail") + + err = actions.FundChainlinkNodesLocal(workerNodes, env.EVMClient, big.NewFloat(.05)) + require.NoError(t, err, "Error funding Chainlink nodes") + + // Gather transmitters + var transmitters []string + for _, node := range workerNodes { + addr, err := node.PrimaryEthAddress() + if err != nil { + require.NoError(t, fmt.Errorf("error getting node's primary ETH address: %w", err)) + } + transmitters = append(transmitters, addr) + } + + ocrOffchainOptions := contracts.DefaultOffChainAggregatorOptions() + aggregatorContracts, err := actions.DeployOCRv2Contracts(1, linkToken, env.ContractDeployer, transmitters, env.EVMClient, ocrOffchainOptions) + require.NoError(t, err, "Error deploying OCRv2 aggregator contracts") + + err = actions.CreateOCRv2JobsLocal(aggregatorContracts, bootstrapNode, workerNodes, env.MockAdapter, "ocr2", 5, env.EVMClient.GetChainID().Uint64(), false, true) + require.NoError(t, err, "Error creating OCRv2 jobs") + fmt.Println("Jobs done") + + ocrv2Config, err := actions.BuildMedianOCR2ConfigLocal(workerNodes, ocrOffchainOptions) + require.NoError(t, err) + require.NoError(t, err, "Error building OCRv2 config") + fmt.Println("built local") + + err = actions.ConfigureOCRv2AggregatorContracts(env.EVMClient, ocrv2Config, aggregatorContracts) + require.NoError(t, err, "Error configuring OCRv2 aggregator contracts") + fmt.Println("built agg") + + err = actions.StartNewOCR2Round(1, aggregatorContracts, env.EVMClient, time.Minute*5, l) + + require.NoError(t, err, "Error starting new OCR2 round") + fmt.Println("round done") + + roundData, err := aggregatorContracts[0].GetRound(tests.Context(t), big.NewInt(1)) + require.NoError(t, err, "Getting latest answer from OCR contract shouldn't fail") + fmt.Println("get latest") + + require.Equal(t, int64(5), roundData.Answer.Int64(), + "Expected latest answer from OCR contract to be 5 but got %d", + roundData.Answer.Int64(), + ) + fmt.Println("answer") + + err = env.MockAdapter.SetAdapterBasedIntValuePath("ocr2", []string{http.MethodGet, http.MethodPost}, 10) + require.NoError(t, err) + fmt.Println("adapter") + + err = actions.StartNewOCR2Round(2, aggregatorContracts, env.EVMClient, time.Minute*5, l) + require.NoError(t, err) + fmt.Println("new round 2") + + roundData, err = aggregatorContracts[0].GetRound(tests.Context(t), big.NewInt(2)) + require.NoError(t, err, "Error getting latest OCR answer") + fmt.Println("got answer 2") + + require.Equal(t, int64(10), roundData.Answer.Int64(), + "Expected latest answer from OCR contract to be 10 but got %d", + roundData.Answer.Int64(), + ) + fmt.Println("values equal") + require.Fail(t, "Capture logs") + }) } - - ocrOffchainOptions := contracts.DefaultOffChainAggregatorOptions() - aggregatorContracts, err := actions.DeployOCRv2Contracts(1, linkToken, env.ContractDeployer, transmitters, env.EVMClient, ocrOffchainOptions) - require.NoError(t, err, "Error deploying OCRv2 aggregator contracts") - - err = actions.CreateOCRv2JobsLocal(aggregatorContracts, bootstrapNode, workerNodes, env.MockAdapter, "ocr2", 5, env.EVMClient.GetChainID().Uint64(), false, true) - require.NoError(t, err, "Error creating OCRv2 jobs") - fmt.Println("Jobs done") - - ocrv2Config, err := actions.BuildMedianOCR2ConfigLocal(workerNodes, ocrOffchainOptions) - require.NoError(t, err) - require.NoError(t, err, "Error building OCRv2 config") - fmt.Println("built local") - - err = actions.ConfigureOCRv2AggregatorContracts(env.EVMClient, ocrv2Config, aggregatorContracts) - require.NoError(t, err, "Error configuring OCRv2 aggregator contracts") - fmt.Println("built agg") - - err = actions.StartNewOCR2Round(1, aggregatorContracts, env.EVMClient, time.Minute*5, l) - - require.NoError(t, err, "Error starting new OCR2 round") - fmt.Println("round done") - - roundData, err := aggregatorContracts[0].GetRound(tests.Context(t), big.NewInt(1)) - require.NoError(t, err, "Getting latest answer from OCR contract shouldn't fail") - fmt.Println("get latest") - - require.Equal(t, int64(5), roundData.Answer.Int64(), - "Expected latest answer from OCR contract to be 5 but got %d", - roundData.Answer.Int64(), - ) - fmt.Println("answer") - - err = env.MockAdapter.SetAdapterBasedIntValuePath("ocr2", []string{http.MethodGet, http.MethodPost}, 10) - require.NoError(t, err) - fmt.Println("adapter") - - err = actions.StartNewOCR2Round(2, aggregatorContracts, env.EVMClient, time.Minute*5, l) - require.NoError(t, err) - fmt.Println("new round 2") - - roundData, err = aggregatorContracts[0].GetRound(tests.Context(t), big.NewInt(2)) - require.NoError(t, err, "Error getting latest OCR answer") - fmt.Println("got answer 2") - - require.Equal(t, int64(10), roundData.Answer.Int64(), - "Expected latest answer from OCR contract to be 10 but got %d", - roundData.Answer.Int64(), - ) - fmt.Println("values equal") - require.Fail(t, "Capture logs") }