From a058fe7e6aab42b5e5c0b3c1722d7449d116f205 Mon Sep 17 00:00:00 2001 From: Bartek Tofel Date: Tue, 2 Jul 2024 18:20:18 +0200 Subject: [PATCH 1/8] working version --- integration-tests/actions/actions.go | 81 ++++++++++++------- integration-tests/chaos/ocr_chaos_test.go | 2 +- .../contracts/ethereum_contracts.go | 37 ++++++--- integration-tests/load/ocr/helper.go | 2 +- integration-tests/load/ocr/vu.go | 2 +- integration-tests/smoke/forwarder_ocr_test.go | 7 ++ .../smoke/forwarders_ocr2_test.go | 7 +- integration-tests/smoke/ocr2_test.go | 31 ++++--- integration-tests/smoke/ocr_test.go | 17 +++- integration-tests/testconfig/ocr/ocr.go | 57 ++++++++++++- integration-tests/testconfig/ocr2/ocr2.go | 12 ++- integration-tests/testconfig/testconfig.go | 5 ++ integration-tests/testsetups/ocr.go | 20 ++++- 13 files changed, 215 insertions(+), 65 deletions(-) diff --git a/integration-tests/actions/actions.go b/integration-tests/actions/actions.go index bdca411c1d8..cbdbf75fe0d 100644 --- a/integration-tests/actions/actions.go +++ b/integration-tests/actions/actions.go @@ -601,29 +601,41 @@ func TrackForwarder( Msg("Forwarder tracked") } -// DeployOCRv2Contracts deploys a number of OCRv2 contracts and configures them with defaults -func DeployOCRv2Contracts( +// SetupOCRv2Contracts deploys a number of OCRv2 contracts and configures them with defaults +func SetupOCRv2Contracts( l zerolog.Logger, seth *seth.Client, numberOfContracts int, linkTokenAddress common.Address, + ocrContractAddresses []common.Address, transmitters []string, ocrOptions contracts.OffchainOptions, ) ([]contracts.OffchainAggregatorV2, error) { var ocrInstances []contracts.OffchainAggregatorV2 - for contractCount := 0; contractCount < numberOfContracts; contractCount++ { - ocrInstance, err := contracts.DeployOffchainAggregatorV2( - l, - seth, - linkTokenAddress, - ocrOptions, - ) - if err != nil { - return nil, fmt.Errorf("OCRv2 instance deployment have failed: %w", err) + + if len(ocrContractAddresses) == 0 { + for contractCount := 0; contractCount < numberOfContracts; contractCount++ { + ocrInstance, err := contracts.DeployOffchainAggregatorV2( + l, + seth, + linkTokenAddress, + ocrOptions, + ) + if err != nil { + return nil, fmt.Errorf("OCRv2 instance deployment have failed: %w", err) + } + ocrInstances = append(ocrInstances, &ocrInstance) + if (contractCount+1)%ContractDeploymentInterval == 0 { // For large amounts of contract deployments, space things out some + time.Sleep(2 * time.Second) + } } - ocrInstances = append(ocrInstances, &ocrInstance) - if (contractCount+1)%ContractDeploymentInterval == 0 { // For large amounts of contract deployments, space things out some - time.Sleep(2 * time.Second) + } else { + for _, address := range ocrContractAddresses { + ocrInstance, err := contracts.LoadOffchainAggregatorV2(l, seth, address) + if err != nil { + return nil, fmt.Errorf("OCRv2 instance loading have failed: %w", err) + } + ocrInstances = append(ocrInstances, &ocrInstance) } } @@ -774,6 +786,7 @@ func DeployOCRContractsForwarderFlow( seth *seth.Client, numberOfContracts int, linkTokenContractAddress common.Address, + ocrContractAddresses []common.Address, workerNodes []contracts.ChainlinkNodeWithKeysAndAddress, forwarderAddresses []common.Address, ) ([]contracts.OffchainAggregator, error) { @@ -793,15 +806,16 @@ func DeployOCRContractsForwarderFlow( return forwarderAddresses, nil } - return deployAnyOCRv1Contracts(logger, seth, numberOfContracts, linkTokenContractAddress, workerNodes, transmitterPayeesFn, transmitterAddressesFn) + return setupAnyOCRv1Contracts(logger, seth, numberOfContracts, linkTokenContractAddress, ocrContractAddresses, workerNodes, transmitterPayeesFn, transmitterAddressesFn) } -// DeployOCRv1Contracts deploys and funds a certain number of offchain aggregator contracts -func DeployOCRv1Contracts( +// SetupOCRv1Contracts deploys and funds a certain number of offchain aggregator contracts +func SetupOCRv1Contracts( logger zerolog.Logger, seth *seth.Client, numberOfContracts int, linkTokenContractAddress common.Address, + ocrContractAddresses []common.Address, workerNodes []contracts.ChainlinkNodeWithKeysAndAddress, ) ([]contracts.OffchainAggregator, error) { transmitterPayeesFn := func() (transmitters []string, payees []string, err error) { @@ -834,28 +848,41 @@ func DeployOCRv1Contracts( return transmitterAddresses, nil } - return deployAnyOCRv1Contracts(logger, seth, numberOfContracts, linkTokenContractAddress, workerNodes, transmitterPayeesFn, transmitterAddressesFn) + return setupAnyOCRv1Contracts(logger, seth, numberOfContracts, linkTokenContractAddress, ocrContractAddresses, workerNodes, transmitterPayeesFn, transmitterAddressesFn) } -func deployAnyOCRv1Contracts( +func setupAnyOCRv1Contracts( logger zerolog.Logger, seth *seth.Client, numberOfContracts int, linkTokenContractAddress common.Address, + ocrContractAddresses []common.Address, workerNodes []contracts.ChainlinkNodeWithKeysAndAddress, getTransmitterAndPayeesFn func() ([]string, []string, error), getTransmitterAddressesFn func() ([]common.Address, error), ) ([]contracts.OffchainAggregator, error) { - // Deploy contracts var ocrInstances []contracts.OffchainAggregator - for contractCount := 0; contractCount < numberOfContracts; contractCount++ { - ocrInstance, err := contracts.DeployOffchainAggregator(logger, seth, linkTokenContractAddress, contracts.DefaultOffChainAggregatorOptions()) - if err != nil { - return nil, fmt.Errorf("OCR instance deployment have failed: %w", err) + + if len(ocrContractAddresses) == 0 { + // Deploy contracts + for contractCount := 0; contractCount < numberOfContracts; contractCount++ { + ocrInstance, err := contracts.DeployOffchainAggregator(logger, seth, linkTokenContractAddress, contracts.DefaultOffChainAggregatorOptions()) + if err != nil { + return nil, fmt.Errorf("OCR instance deployment have failed: %w", err) + } + ocrInstances = append(ocrInstances, &ocrInstance) + if (contractCount+1)%ContractDeploymentInterval == 0 { // For large amounts of contract deployments, space things out some + time.Sleep(2 * time.Second) + } } - ocrInstances = append(ocrInstances, &ocrInstance) - if (contractCount+1)%ContractDeploymentInterval == 0 { // For large amounts of contract deployments, space things out some - time.Sleep(2 * time.Second) + } else { + // Load contract wrappers + for _, address := range ocrContractAddresses { + ocrInstance, err := contracts.LoadOffchainAggregator(logger, seth, address) + if err != nil { + return nil, fmt.Errorf("OCR instance loading have failed: %w", err) + } + ocrInstances = append(ocrInstances, &ocrInstance) } } diff --git a/integration-tests/chaos/ocr_chaos_test.go b/integration-tests/chaos/ocr_chaos_test.go index 54a02cf64f3..ad8f2417c0e 100644 --- a/integration-tests/chaos/ocr_chaos_test.go +++ b/integration-tests/chaos/ocr_chaos_test.go @@ -187,7 +187,7 @@ func TestOCRChaos(t *testing.T) { err = actions.FundChainlinkNodesFromRootAddress(l, seth, contracts.ChainlinkK8sClientToChainlinkNodeWithKeysAndAddress(chainlinkNodes), big.NewFloat(10)) require.NoError(t, err) - ocrInstances, err := actions.DeployOCRv1Contracts(l, seth, 1, common.HexToAddress(linkContract.Address()), contracts.ChainlinkK8sClientToChainlinkNodeWithKeysAndAddress(workerNodes)) + ocrInstances, err := actions.SetupOCRv1Contracts(l, seth, 1, common.HexToAddress(linkContract.Address()), contracts.ChainlinkK8sClientToChainlinkNodeWithKeysAndAddress(workerNodes)) require.NoError(t, err) err = actions.CreateOCRJobs(ocrInstances, bootstrapNode, workerNodes, 5, ms, fmt.Sprint(seth.ChainID)) require.NoError(t, err) diff --git a/integration-tests/contracts/ethereum_contracts.go b/integration-tests/contracts/ethereum_contracts.go index ebe99da2d92..50497e58d85 100644 --- a/integration-tests/contracts/ethereum_contracts.go +++ b/integration-tests/contracts/ethereum_contracts.go @@ -359,10 +359,6 @@ func (o *EthereumOffchainAggregator) SetConfig( return err } - // fails with error setting OCR config for contract '0x0DCd1Bf9A1b36cE34237eEaFef220932846BCD82': both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified - // but we only have gasPrice set... It also fails with the same error when we enable EIP-1559 - // fails when we wait for it to be minted, inside the wrapper there's no error when we call it, so it must be something inside smart contract - // that's reverting it and maybe the error message is completely off _, err = o.client.Decode(o.ocr.SetConfig(o.client.NewTXOpts(), signers, transmitters, threshold, encodedConfigVersion, encodedConfig)) return err } @@ -608,14 +604,14 @@ func LoadOffChainAggregatorV2(l zerolog.Logger, seth *seth.Client, contractAddre } func DeployOffchainAggregatorV2(l zerolog.Logger, seth *seth.Client, linkTokenAddress common.Address, offchainOptions OffchainOptions) (EthereumOffchainAggregatorV2, error) { - oAbi, err := ocr2aggregator.OCR2AggregatorMetaData.GetAbi() + contractAbi, err := ocr2aggregator.OCR2AggregatorMetaData.GetAbi() if err != nil { - return EthereumOffchainAggregatorV2{}, fmt.Errorf("failed to get OffChain Aggregator ABI: %w", err) + return EthereumOffchainAggregatorV2{}, fmt.Errorf("failed to get OffChain Aggregator v2 ABI: %w", err) } - seth.ContractStore.AddABI("OffChainAggregatorV2", *oAbi) + seth.ContractStore.AddABI("OffChainAggregatorV2", *contractAbi) seth.ContractStore.AddBIN("OffChainAggregatorV2", common.FromHex(ocr2aggregator.OCR2AggregatorMetaData.Bin)) - ocrDeploymentData2, err := seth.DeployContract(seth.NewTXOpts(), "OffChainAggregatorV2", *oAbi, common.FromHex(ocr2aggregator.OCR2AggregatorMetaData.Bin), + ocrDeploymentData2, err := seth.DeployContract(seth.NewTXOpts(), "OffChainAggregatorV2", *contractAbi, common.FromHex(ocr2aggregator.OCR2AggregatorMetaData.Bin), linkTokenAddress, offchainOptions.MinimumAnswer, offchainOptions.MaximumAnswer, @@ -626,12 +622,12 @@ func DeployOffchainAggregatorV2(l zerolog.Logger, seth *seth.Client, linkTokenAd ) if err != nil { - return EthereumOffchainAggregatorV2{}, fmt.Errorf("OCR instance deployment have failed: %w", err) + return EthereumOffchainAggregatorV2{}, fmt.Errorf("OCRv2 instance deployment have failed: %w", err) } ocr2, err := ocr2aggregator.NewOCR2Aggregator(ocrDeploymentData2.Address, wrappers.MustNewWrappedContractBackend(nil, seth)) if err != nil { - return EthereumOffchainAggregatorV2{}, fmt.Errorf("failed to instantiate OCR instance: %w", err) + return EthereumOffchainAggregatorV2{}, fmt.Errorf("failed to instantiate OCRv2 instance: %w", err) } return EthereumOffchainAggregatorV2{ @@ -642,6 +638,27 @@ func DeployOffchainAggregatorV2(l zerolog.Logger, seth *seth.Client, linkTokenAd }, nil } +func LoadOffchainAggregatorV2(l zerolog.Logger, seth *seth.Client, address common.Address) (EthereumOffchainAggregatorV2, error) { + contractAbi, err := ocr2aggregator.OCR2AggregatorMetaData.GetAbi() + if err != nil { + return EthereumOffchainAggregatorV2{}, fmt.Errorf("failed to get OffChain Aggregator v2 ABI: %w", err) + } + seth.ContractStore.AddABI("OffChainAggregatorV2", *contractAbi) + seth.ContractStore.AddBIN("OffChainAggregatorV2", common.FromHex(ocr2aggregator.OCR2AggregatorMetaData.Bin)) + + ocr2, err := ocr2aggregator.NewOCR2Aggregator(address, seth.Client) + if err != nil { + return EthereumOffchainAggregatorV2{}, fmt.Errorf("failed to instantiate OCRv2 instance: %w", err) + } + + return EthereumOffchainAggregatorV2{ + client: seth, + contract: ocr2, + address: &address, + l: l, + }, nil +} + func (e *EthereumOffchainAggregatorV2) Address() string { return e.address.Hex() } diff --git a/integration-tests/load/ocr/helper.go b/integration-tests/load/ocr/helper.go index f95bf143bce..256bbf8f318 100644 --- a/integration-tests/load/ocr/helper.go +++ b/integration-tests/load/ocr/helper.go @@ -41,7 +41,7 @@ func SetupFeed( bootstrapNode *client.ChainlinkK8sClient, workerNodes []*client.ChainlinkK8sClient, ) ([]contracts.OffchainAggregator, error) { - ocrInstances, err := actions.DeployOCRv1Contracts(l, seth, 1, lta, contracts.ChainlinkK8sClientToChainlinkNodeWithKeysAndAddress(workerNodes)) + ocrInstances, err := actions.SetupOCRv1Contracts(l, seth, 1, lta, contracts.ChainlinkK8sClientToChainlinkNodeWithKeysAndAddress(workerNodes)) if err != nil { return nil, err } diff --git a/integration-tests/load/ocr/vu.go b/integration-tests/load/ocr/vu.go index 88f186c5ee1..baebd37e2a1 100644 --- a/integration-tests/load/ocr/vu.go +++ b/integration-tests/load/ocr/vu.go @@ -78,7 +78,7 @@ func (m *VU) Clone(_ *wasp.Generator) wasp.VirtualUser { } func (m *VU) Setup(_ *wasp.Generator) error { - ocrInstances, err := actions.DeployOCRv1Contracts(m.l, m.seth, 1, m.lta, contracts.ChainlinkK8sClientToChainlinkNodeWithKeysAndAddress(m.workerNodes)) + ocrInstances, err := actions.SetupOCRv1Contracts(m.l, m.seth, 1, m.lta, contracts.ChainlinkK8sClientToChainlinkNodeWithKeysAndAddress(m.workerNodes)) if err != nil { return err } diff --git a/integration-tests/smoke/forwarder_ocr_test.go b/integration-tests/smoke/forwarder_ocr_test.go index a249775dc6a..380ebdf0d73 100644 --- a/integration-tests/smoke/forwarder_ocr_test.go +++ b/integration-tests/smoke/forwarder_ocr_test.go @@ -81,11 +81,18 @@ func TestForwarderOCRBasic(t *testing.T) { require.NoError(t, err, "Accepting Authorize Receivers on Operator shouldn't fail") actions.TrackForwarder(t, sethClient, authorizedForwarders[i], workerNodes[i]) } + + var ocrInstanceAddresses []common.Address + for _, address := range config.OCR.Contracts.OffchainAggregatorAddresses { + ocrInstanceAddresses = append(ocrInstanceAddresses, common.HexToAddress(address)) + } + ocrInstances, err := actions.DeployOCRContractsForwarderFlow( l, sethClient, 1, common.HexToAddress(lt.Address()), + ocrInstanceAddresses, contracts.ChainlinkClientToChainlinkNodeWithKeysAndAddress(workerNodes), authorizedForwarders, ) diff --git a/integration-tests/smoke/forwarders_ocr2_test.go b/integration-tests/smoke/forwarders_ocr2_test.go index 863b36e4ede..200ace3b497 100644 --- a/integration-tests/smoke/forwarders_ocr2_test.go +++ b/integration-tests/smoke/forwarders_ocr2_test.go @@ -89,8 +89,13 @@ func TestForwarderOCR2Basic(t *testing.T) { transmitters = append(transmitters, forwarderCommonAddress.Hex()) } + var ocrInstanceAddresses []common.Address + for _, address := range config.OCR2.Contracts.OffchainAggregatorAddresses { + ocrInstanceAddresses = append(ocrInstanceAddresses, common.HexToAddress(address)) + } + ocrOffchainOptions := contracts.DefaultOffChainAggregatorOptions() - ocrInstances, err := actions.DeployOCRv2Contracts(l, sethClient, 1, common.HexToAddress(lt.Address()), transmitters, ocrOffchainOptions) + ocrInstances, err := actions.SetupOCRv2Contracts(l, sethClient, 1, common.HexToAddress(lt.Address()), ocrInstanceAddresses, transmitters, ocrOffchainOptions) require.NoError(t, err, "Error deploying OCRv2 contracts with forwarders") ocrv2Config, err := actions.BuildMedianOCR2ConfigLocal(workerNodes, ocrOffchainOptions) diff --git a/integration-tests/smoke/ocr2_test.go b/integration-tests/smoke/ocr2_test.go index 56a95c50bda..cdf26d7eb4c 100644 --- a/integration-tests/smoke/ocr2_test.go +++ b/integration-tests/smoke/ocr2_test.go @@ -46,12 +46,12 @@ func TestOCRv2Basic(t *testing.T) { t.Parallel() noMedianPlugin := map[string]string{string(env.MedianPlugin.Cmd): ""} - medianPlugin := map[string]string{string(env.MedianPlugin.Cmd): "chainlink-feeds"} + //medianPlugin := map[string]string{string(env.MedianPlugin.Cmd): "chainlink-feeds"} for _, test := range []ocr2test{ {"legacy", noMedianPlugin, false}, - {"legacy-chain-reader", noMedianPlugin, true}, - {"plugins", medianPlugin, false}, - {"plugins-chain-reader", medianPlugin, true}, + //{"legacy-chain-reader", noMedianPlugin, true}, + //{"plugins", medianPlugin, false}, + //{"plugins-chain-reader", medianPlugin, true}, } { test := test t.Run(test.name, func(t *testing.T) { @@ -102,11 +102,11 @@ func TestOCRv2JobReplacement(t *testing.T) { t.Parallel() l := logging.GetTestLogger(t) - env, aggregatorContracts, sethClient := prepareORCv2SmokeTestEnv(t, defaultTestData(), l, 5) - nodeClients := env.ClCluster.NodeAPIs() + testEnv, aggregatorContracts, sethClient := prepareORCv2SmokeTestEnv(t, defaultTestData(), l, 5) + nodeClients := testEnv.ClCluster.NodeAPIs() bootstrapNode, workerNodes := nodeClients[0], nodeClients[1:] - err := env.MockAdapter.SetAdapterBasedIntValuePath("ocr2", []string{http.MethodGet, http.MethodPost}, 10) + err := testEnv.MockAdapter.SetAdapterBasedIntValuePath("ocr2", []string{http.MethodGet, http.MethodPost}, 10) require.NoError(t, err) err = actions.WatchNewOCRRound(l, sethClient, 2, contracts.V2OffChainAgrregatorToOffChainAggregatorWithRounds(aggregatorContracts), time.Minute*5) require.NoError(t, err, "Error watching for new OCR2 round") @@ -124,7 +124,7 @@ func TestOCRv2JobReplacement(t *testing.T) { err = actions.DeleteBridges(nodeClients) require.NoError(t, err) - err = actions.CreateOCRv2JobsLocal(aggregatorContracts, bootstrapNode, workerNodes, env.MockAdapter, "ocr2", 15, uint64(sethClient.ChainID), false, false) + err = actions.CreateOCRv2JobsLocal(aggregatorContracts, bootstrapNode, workerNodes, testEnv.MockAdapter, "ocr2", 15, uint64(sethClient.ChainID), false, false) require.NoError(t, err, "Error creating OCRv2 jobs") err = actions.WatchNewOCRRound(l, sethClient, 3, contracts.V2OffChainAgrregatorToOffChainAggregatorWithRounds(aggregatorContracts), time.Minute*3) @@ -169,8 +169,12 @@ func prepareORCv2SmokeTestEnv(t *testing.T, testData ocr2test, l zerolog.Logger, nodeClients := testEnv.ClCluster.NodeAPIs() bootstrapNode, workerNodes := nodeClients[0], nodeClients[1:] - linkContract, err := contracts.DeployLinkTokenContract(l, sethClient) - require.NoError(t, err, "Error deploying link token contract") + var linkContract *contracts.EthereumLinkToken + if config.OCR2.Contracts != nil && config.OCR2.Contracts.UseExisting() { + linkContract, err = contracts.LoadLinkTokenContract(l, sethClient, common.HexToAddress(*config.OCR2.Contracts.LinkTokenAddress)) + } else { + linkContract, err = contracts.DeployLinkTokenContract(l, sethClient) + } err = actions.FundChainlinkNodesFromRootAddress(l, sethClient, contracts.ChainlinkClientToChainlinkNodeWithKeysAndAddress(workerNodes), big.NewFloat(*config.Common.ChainlinkNodeFunding)) require.NoError(t, err, "Error funding Chainlink nodes") @@ -190,8 +194,13 @@ func prepareORCv2SmokeTestEnv(t *testing.T, testData ocr2test, l zerolog.Logger, transmitters = append(transmitters, addr) } + var ocrInstanceAddresses []common.Address + for _, address := range config.OCR2.Contracts.OffchainAggregatorAddresses { + ocrInstanceAddresses = append(ocrInstanceAddresses, common.HexToAddress(address)) + } + ocrOffchainOptions := contracts.DefaultOffChainAggregatorOptions() - aggregatorContracts, err := actions.DeployOCRv2Contracts(l, sethClient, 1, common.HexToAddress(linkContract.Address()), transmitters, ocrOffchainOptions) + aggregatorContracts, err := actions.SetupOCRv2Contracts(l, sethClient, 1, common.HexToAddress(linkContract.Address()), ocrInstanceAddresses, transmitters, ocrOffchainOptions) require.NoError(t, err, "Error deploying OCRv2 aggregator contracts") err = actions.CreateOCRv2JobsLocal(aggregatorContracts, bootstrapNode, workerNodes, testEnv.MockAdapter, "ocr2", 5, uint64(sethClient.ChainID), false, testData.chainReaderAndCodec) diff --git a/integration-tests/smoke/ocr_test.go b/integration-tests/smoke/ocr_test.go index 67f8c44f8a1..ff841be14f8 100644 --- a/integration-tests/smoke/ocr_test.go +++ b/integration-tests/smoke/ocr_test.go @@ -115,10 +115,21 @@ func prepareORCv1SmokeTestEnv(t *testing.T, l zerolog.Logger, firstRoundResult i _ = actions.ReturnFundsFromNodes(l, sethClient, contracts.ChainlinkClientToChainlinkNodeWithKeysAndAddress(env.ClCluster.NodeAPIs())) }) - linkContract, err := contracts.DeployLinkTokenContract(l, sethClient) - require.NoError(t, err, "Error deploying link token contract") + var linkContract *contracts.EthereumLinkToken + if config.OCR.Contracts != nil && config.OCR.Contracts.UseExisting() { + linkContract, err = contracts.LoadLinkTokenContract(l, sethClient, common.HexToAddress(*config.OCR.Contracts.LinkTokenAddress)) + } else { + linkContract, err = contracts.DeployLinkTokenContract(l, sethClient) + } + + require.NoError(t, err, "Error loading/deploying link token contract") + + var ocrInstanceAddresses []common.Address + for _, address := range config.OCR.Contracts.OffchainAggregatorAddresses { + ocrInstanceAddresses = append(ocrInstanceAddresses, common.HexToAddress(address)) + } - ocrInstances, err := actions.DeployOCRv1Contracts(l, sethClient, 1, common.HexToAddress(linkContract.Address()), contracts.ChainlinkClientToChainlinkNodeWithKeysAndAddress(workerNodes)) + ocrInstances, err := actions.SetupOCRv1Contracts(l, sethClient, 1, common.HexToAddress(linkContract.Address()), ocrInstanceAddresses, contracts.ChainlinkClientToChainlinkNodeWithKeysAndAddress(workerNodes)) require.NoError(t, err, "Error deploying OCR contracts") err = actions.CreateOCRJobsLocal(ocrInstances, bootstrapNode, workerNodes, 5, env.MockAdapter, big.NewInt(sethClient.ChainID)) diff --git a/integration-tests/testconfig/ocr/ocr.go b/integration-tests/testconfig/ocr/ocr.go index f23d6473643..f8f0ebd027e 100644 --- a/integration-tests/testconfig/ocr/ocr.go +++ b/integration-tests/testconfig/ocr/ocr.go @@ -2,15 +2,18 @@ package ocr import ( "errors" + "fmt" + "github.com/ethereum/go-ethereum/common" "github.com/smartcontractkit/chainlink-testing-framework/blockchain" ) type Config struct { - Soak *SoakConfig `toml:"Soak"` - Load *Load `toml:"Load"` - Volume *Volume `toml:"Volume"` - Common *Common `toml:"Common"` + Soak *SoakConfig `toml:"Soak"` + Load *Load `toml:"Load"` + Volume *Volume `toml:"Volume"` + Common *Common `toml:"Common"` + Contracts *Contracts `toml:"Contracts"` } func (o *Config) Validate() error { @@ -29,6 +32,11 @@ func (o *Config) Validate() error { return err } } + if o.Contracts != nil { + if err := o.Contracts.Validate(); err != nil { + return err + } + } return nil } @@ -130,3 +138,44 @@ func (o *SoakConfig) Validate() error { } return nil } + +type Contracts struct { + Settings *ContractSettings `toml:"Settings"` + LinkTokenAddress *string `toml:"link_token"` + OffchainAggregatorAddresses []string `toml:"offchain_aggregators"` +} + +func (o *Contracts) Validate() error { + if o.LinkTokenAddress != nil && !common.IsHexAddress(*o.LinkTokenAddress) { + return errors.New("link_token must be a valid ethereum address") + } + if o.OffchainAggregatorAddresses != nil { + for _, address := range o.OffchainAggregatorAddresses { + if !common.IsHexAddress(address) { + return fmt.Errorf("offchain_aggregators must be valid ethereum addresses, but %s is not", address) + } + } + } + + return nil +} + +func (o *Contracts) UseExisting() bool { + if o.Settings != nil && o.Settings.UseExisting != nil { + return *o.Settings.UseExisting + } + return false +} + +func (o *Contracts) MustGetLinkTokenContractAddress() common.Address { + if o.LinkTokenAddress != nil { + return common.HexToAddress(*o.LinkTokenAddress) + } + + panic("link token address must be set") +} + +type ContractSettings struct { + UseExisting *bool `toml:"use_existing"` + Configure *bool `toml:"configure"` +} diff --git a/integration-tests/testconfig/ocr2/ocr2.go b/integration-tests/testconfig/ocr2/ocr2.go index 73c9cd10056..4b46d599c18 100644 --- a/integration-tests/testconfig/ocr2/ocr2.go +++ b/integration-tests/testconfig/ocr2/ocr2.go @@ -4,11 +4,14 @@ import ( "errors" "github.com/smartcontractkit/chainlink-testing-framework/blockchain" + + "github.com/smartcontractkit/chainlink/integration-tests/testconfig/ocr" ) type Config struct { - Soak *SoakConfig `toml:"Soak"` - Common *Common `toml:"Common"` + Soak *SoakConfig `toml:"Soak"` + Common *Common `toml:"Common"` + Contracts *ocr.Contracts `toml:"Contracts"` } func (o *Config) Validate() error { @@ -22,6 +25,11 @@ func (o *Config) Validate() error { return err } } + if o.Contracts != nil { + if err := o.Contracts.Validate(); err != nil { + return err + } + } return nil } diff --git a/integration-tests/testconfig/testconfig.go b/integration-tests/testconfig/testconfig.go index 95cb368a2a4..5ee9f6121d8 100644 --- a/integration-tests/testconfig/testconfig.go +++ b/integration-tests/testconfig/testconfig.go @@ -4,6 +4,7 @@ import ( "embed" "encoding/base64" "fmt" + "github.com/ethereum/go-ethereum/common" "math/big" "os" "slices" @@ -69,6 +70,10 @@ type Ocr2TestConfig interface { GetOCR2Config() *ocr_config.Config } +type LinkTokenContractConfig interface { + MustGetLinkTokenContractAddress() common.Address +} + type TestConfig struct { ctf_config.TestConfig diff --git a/integration-tests/testsetups/ocr.go b/integration-tests/testsetups/ocr.go index 45c334bf69d..d5f047c266a 100644 --- a/integration-tests/testsetups/ocr.go +++ b/integration-tests/testsetups/ocr.go @@ -280,8 +280,13 @@ func (o *OCRSoakTest) Setup(ocrTestConfig tt.OcrTestConfig) { o.mockServer, err = ctf_client.ConnectMockServer(o.testEnvironment) require.NoError(o.t, err, "Creating mockserver clients shouldn't fail") - linkContract, err := contracts.DeployLinkTokenContract(o.log, sethClient) - require.NoError(o.t, err, "Error deploying LINK contract") + var linkContract *contracts.EthereumLinkToken + if ocrTestConfig.GetActiveOCRConfig().Contracts != nil && ocrTestConfig.GetActiveOCRConfig().Contracts.UseExisting() { + linkContract, err = contracts.LoadLinkTokenContract(o.log, sethClient, common.HexToAddress(*ocrTestConfig.GetActiveOCRConfig().Contracts.LinkTokenAddress)) + } else { + linkContract, err = contracts.DeployLinkTokenContract(o.log, sethClient) + } + require.NoError(o.t, err, "Error loading/deploying LINK contract") // Fund Chainlink nodes, excluding the bootstrap node o.log.Info().Float64("ETH amount per node", *o.Config.Common.ChainlinkNodeFunding).Msg("Funding Chainlink nodes") @@ -289,6 +294,10 @@ func (o *OCRSoakTest) Setup(ocrTestConfig tt.OcrTestConfig) { require.NoError(o.t, err, "Error funding Chainlink nodes") var forwarders []common.Address + var ocrInstanceAddresses []common.Address + for _, address := range ocrTestConfig.GetActiveOCRConfig().Contracts.OffchainAggregatorAddresses { + ocrInstanceAddresses = append(ocrInstanceAddresses, common.HexToAddress(address)) + } if o.OperatorForwarderFlow { var operators []common.Address @@ -312,16 +321,18 @@ func (o *OCRSoakTest) Setup(ocrTestConfig tt.OcrTestConfig) { o.seth, *o.Config.GetActiveOCRConfig().Soak.NumberOfContracts, common.HexToAddress(linkContract.Address()), + ocrInstanceAddresses, contracts.ChainlinkK8sClientToChainlinkNodeWithKeysAndAddress(o.workerNodes), forwarders, ) require.NoError(o.t, err, "Error deploying OCR Forwarder contracts") } else { - o.ocrV1Instances, err = actions.DeployOCRv1Contracts( + o.ocrV1Instances, err = actions.SetupOCRv1Contracts( o.log, sethClient, *o.Config.GetActiveOCRConfig().Soak.NumberOfContracts, common.HexToAddress(linkContract.Address()), + ocrInstanceAddresses, contracts.ChainlinkK8sClientToChainlinkNodeWithKeysAndAddress(o.workerNodes), ) require.NoError(o.t, err) @@ -342,11 +353,12 @@ func (o *OCRSoakTest) Setup(ocrTestConfig tt.OcrTestConfig) { } ocrOffchainOptions := contracts.DefaultOffChainAggregatorOptions() - o.ocrV2Instances, err = actions.DeployOCRv2Contracts( + o.ocrV2Instances, err = actions.SetupOCRv2Contracts( o.log, o.seth, *ocrTestConfig.GetActiveOCRConfig().Soak.NumberOfContracts, common.HexToAddress(linkContract.Address()), + ocrInstanceAddresses, transmitters, ocrOffchainOptions, ) From 8851ee30bffd41828d03be79870ddf2a30302a4a Mon Sep 17 00:00:00 2001 From: Bartek Tofel Date: Tue, 2 Jul 2024 20:19:36 +0200 Subject: [PATCH 2/8] unify the config a bit, make it possible to use also pre-configured contracts --- integration-tests/actions/actions.go | 37 +++-- integration-tests/actions/contracts.go | 20 +++ integration-tests/smoke/forwarder_ocr_test.go | 11 +- .../smoke/forwarders_ocr2_test.go | 13 +- integration-tests/smoke/ocr2_test.go | 27 ++-- integration-tests/smoke/ocr_test.go | 19 +-- .../testconfig/forwarder_ocr/example.toml | 10 +- .../forwarder_ocr/forwarder_ocr.toml | 7 +- .../testconfig/forwarder_ocr2/example.toml | 22 +-- .../forwarder_ocr2/forwarder_ocr2.toml | 7 +- integration-tests/testconfig/ocr/example.toml | 7 +- integration-tests/testconfig/ocr/ocr.go | 150 +++++++++++++++--- integration-tests/testconfig/ocr/ocr.toml | 5 +- .../testconfig/ocr2/example.toml | 7 +- integration-tests/testconfig/ocr2/ocr2.go | 37 +---- integration-tests/testconfig/ocr2/ocr2.toml | 5 +- integration-tests/testconfig/testconfig.go | 3 +- integration-tests/testsetups/ocr.go | 9 +- 18 files changed, 247 insertions(+), 149 deletions(-) create mode 100644 integration-tests/actions/contracts.go diff --git a/integration-tests/actions/actions.go b/integration-tests/actions/actions.go index cbdbf75fe0d..2ba3b7a9302 100644 --- a/integration-tests/actions/actions.go +++ b/integration-tests/actions/actions.go @@ -5,6 +5,7 @@ import ( "context" "crypto/ecdsa" "fmt" + "github.com/smartcontractkit/chainlink/integration-tests/testconfig/ocr" "math/big" "strings" "sync" @@ -605,16 +606,15 @@ func TrackForwarder( func SetupOCRv2Contracts( l zerolog.Logger, seth *seth.Client, - numberOfContracts int, + ocrContractsConfig ocr.OffChainAggregatorsConfig, linkTokenAddress common.Address, - ocrContractAddresses []common.Address, transmitters []string, ocrOptions contracts.OffchainOptions, ) ([]contracts.OffchainAggregatorV2, error) { var ocrInstances []contracts.OffchainAggregatorV2 - if len(ocrContractAddresses) == 0 { - for contractCount := 0; contractCount < numberOfContracts; contractCount++ { + if !ocrContractsConfig.UseExistingOffChainAggregatorsContracts() { + for contractCount := 0; contractCount < ocrContractsConfig.GetNumberOfContractsToDeploy(); contractCount++ { ocrInstance, err := contracts.DeployOffchainAggregatorV2( l, seth, @@ -630,13 +630,17 @@ func SetupOCRv2Contracts( } } } else { - for _, address := range ocrContractAddresses { + for _, address := range ocrContractsConfig.GetOffChainAggregatorsContractsAddresses() { ocrInstance, err := contracts.LoadOffchainAggregatorV2(l, seth, address) if err != nil { return nil, fmt.Errorf("OCRv2 instance loading have failed: %w", err) } ocrInstances = append(ocrInstances, &ocrInstance) } + + if !ocrContractsConfig.ConfigureExistingOffChainAggregatorsContracts() { + return ocrInstances, nil + } } // Gather address payees @@ -784,9 +788,8 @@ func StartNewRound( func DeployOCRContractsForwarderFlow( logger zerolog.Logger, seth *seth.Client, - numberOfContracts int, + ocrContractsConfig ocr.OffChainAggregatorsConfig, linkTokenContractAddress common.Address, - ocrContractAddresses []common.Address, workerNodes []contracts.ChainlinkNodeWithKeysAndAddress, forwarderAddresses []common.Address, ) ([]contracts.OffchainAggregator, error) { @@ -806,16 +809,15 @@ func DeployOCRContractsForwarderFlow( return forwarderAddresses, nil } - return setupAnyOCRv1Contracts(logger, seth, numberOfContracts, linkTokenContractAddress, ocrContractAddresses, workerNodes, transmitterPayeesFn, transmitterAddressesFn) + return setupAnyOCRv1Contracts(logger, seth, ocrContractsConfig, linkTokenContractAddress, workerNodes, transmitterPayeesFn, transmitterAddressesFn) } // SetupOCRv1Contracts deploys and funds a certain number of offchain aggregator contracts func SetupOCRv1Contracts( logger zerolog.Logger, seth *seth.Client, - numberOfContracts int, + ocrContractsConfig ocr.OffChainAggregatorsConfig, linkTokenContractAddress common.Address, - ocrContractAddresses []common.Address, workerNodes []contracts.ChainlinkNodeWithKeysAndAddress, ) ([]contracts.OffchainAggregator, error) { transmitterPayeesFn := func() (transmitters []string, payees []string, err error) { @@ -848,24 +850,23 @@ func SetupOCRv1Contracts( return transmitterAddresses, nil } - return setupAnyOCRv1Contracts(logger, seth, numberOfContracts, linkTokenContractAddress, ocrContractAddresses, workerNodes, transmitterPayeesFn, transmitterAddressesFn) + return setupAnyOCRv1Contracts(logger, seth, ocrContractsConfig, linkTokenContractAddress, workerNodes, transmitterPayeesFn, transmitterAddressesFn) } func setupAnyOCRv1Contracts( logger zerolog.Logger, seth *seth.Client, - numberOfContracts int, + ocrContractsConfig ocr.OffChainAggregatorsConfig, linkTokenContractAddress common.Address, - ocrContractAddresses []common.Address, workerNodes []contracts.ChainlinkNodeWithKeysAndAddress, getTransmitterAndPayeesFn func() ([]string, []string, error), getTransmitterAddressesFn func() ([]common.Address, error), ) ([]contracts.OffchainAggregator, error) { var ocrInstances []contracts.OffchainAggregator - if len(ocrContractAddresses) == 0 { + if !ocrContractsConfig.UseExistingOffChainAggregatorsContracts() { // Deploy contracts - for contractCount := 0; contractCount < numberOfContracts; contractCount++ { + for contractCount := 0; contractCount < ocrContractsConfig.GetNumberOfContractsToDeploy(); contractCount++ { ocrInstance, err := contracts.DeployOffchainAggregator(logger, seth, linkTokenContractAddress, contracts.DefaultOffChainAggregatorOptions()) if err != nil { return nil, fmt.Errorf("OCR instance deployment have failed: %w", err) @@ -877,13 +878,17 @@ func setupAnyOCRv1Contracts( } } else { // Load contract wrappers - for _, address := range ocrContractAddresses { + for _, address := range ocrContractsConfig.GetOffChainAggregatorsContractsAddresses() { ocrInstance, err := contracts.LoadOffchainAggregator(logger, seth, address) if err != nil { return nil, fmt.Errorf("OCR instance loading have failed: %w", err) } ocrInstances = append(ocrInstances, &ocrInstance) } + + if !ocrContractsConfig.ConfigureExistingOffChainAggregatorsContracts() { + return ocrInstances, nil + } } // Gather transmitter and address payees diff --git a/integration-tests/actions/contracts.go b/integration-tests/actions/contracts.go new file mode 100644 index 00000000000..5b2d9a4bfb0 --- /dev/null +++ b/integration-tests/actions/contracts.go @@ -0,0 +1,20 @@ +package actions + +import ( + "github.com/rs/zerolog" + "github.com/smartcontractkit/chainlink/integration-tests/contracts" + tc "github.com/smartcontractkit/chainlink/integration-tests/testconfig" + "github.com/smartcontractkit/seth" +) + +func GetLinkTokenContract(l zerolog.Logger, sethClient *seth.Client, configWithLinkToken tc.LinkTokenContractConfig) (*contracts.EthereumLinkToken, error) { + if configWithLinkToken.UseExistingLinkTokenContract() { + linkAddress, err := configWithLinkToken.GetLinkTokenContractAddress() + if err != nil { + return nil, err + } + + return contracts.LoadLinkTokenContract(l, sethClient, linkAddress) + } + return contracts.DeployLinkTokenContract(l, sethClient) +} diff --git a/integration-tests/smoke/forwarder_ocr_test.go b/integration-tests/smoke/forwarder_ocr_test.go index 380ebdf0d73..5f083b0b823 100644 --- a/integration-tests/smoke/forwarder_ocr_test.go +++ b/integration-tests/smoke/forwarder_ocr_test.go @@ -60,8 +60,8 @@ func TestForwarderOCRBasic(t *testing.T) { _ = actions.ReturnFundsFromNodes(l, sethClient, contracts.ChainlinkClientToChainlinkNodeWithKeysAndAddress(env.ClCluster.NodeAPIs())) }) - lt, err := contracts.DeployLinkTokenContract(l, sethClient) - require.NoError(t, err, "Deploying Link Token Contract shouldn't fail") + linkContract, err := actions.GetLinkTokenContract(l, sethClient, config.OCR) + require.NoError(t, err, "Error loading/deploying link token contract") fundingAmount := big.NewFloat(.05) l.Info().Str("ETH amount per node", fundingAmount.String()).Msg("Funding Chainlink nodes") @@ -69,7 +69,7 @@ func TestForwarderOCRBasic(t *testing.T) { require.NoError(t, err, "Error funding Chainlink nodes") operators, authorizedForwarders, _ := actions.DeployForwarderContracts( - t, sethClient, common.HexToAddress(lt.Address()), len(workerNodes), + t, sethClient, common.HexToAddress(linkContract.Address()), len(workerNodes), ) require.Equal(t, len(workerNodes), len(operators), "Number of operators should match number of worker nodes") @@ -90,9 +90,8 @@ func TestForwarderOCRBasic(t *testing.T) { ocrInstances, err := actions.DeployOCRContractsForwarderFlow( l, sethClient, - 1, - common.HexToAddress(lt.Address()), - ocrInstanceAddresses, + config.OCR, + common.HexToAddress(linkContract.Address()), contracts.ChainlinkClientToChainlinkNodeWithKeysAndAddress(workerNodes), authorizedForwarders, ) diff --git a/integration-tests/smoke/forwarders_ocr2_test.go b/integration-tests/smoke/forwarders_ocr2_test.go index 200ace3b497..e9fea7c5926 100644 --- a/integration-tests/smoke/forwarders_ocr2_test.go +++ b/integration-tests/smoke/forwarders_ocr2_test.go @@ -61,8 +61,8 @@ func TestForwarderOCR2Basic(t *testing.T) { _ = actions.ReturnFundsFromNodes(l, sethClient, contracts.ChainlinkClientToChainlinkNodeWithKeysAndAddress(env.ClCluster.NodeAPIs())) }) - lt, err := contracts.DeployLinkTokenContract(l, sethClient) - require.NoError(t, err, "Deploying Link Token Contract shouldn't fail") + linkContract, err := actions.GetLinkTokenContract(l, sethClient, config.OCR2) + require.NoError(t, err, "Error loading/deploying link token contract") fundingAmount := big.NewFloat(.05) l.Info().Str("ETH amount per node", fundingAmount.String()).Msg("Funding Chainlink nodes") @@ -70,7 +70,7 @@ func TestForwarderOCR2Basic(t *testing.T) { require.NoError(t, err, "Error funding Chainlink nodes") operators, authorizedForwarders, _ := actions.DeployForwarderContracts( - t, sethClient, common.HexToAddress(lt.Address()), len(workerNodes), + t, sethClient, common.HexToAddress(linkContract.Address()), len(workerNodes), ) require.Equal(t, len(workerNodes), len(operators), "Number of operators should match number of worker nodes") @@ -89,13 +89,8 @@ func TestForwarderOCR2Basic(t *testing.T) { transmitters = append(transmitters, forwarderCommonAddress.Hex()) } - var ocrInstanceAddresses []common.Address - for _, address := range config.OCR2.Contracts.OffchainAggregatorAddresses { - ocrInstanceAddresses = append(ocrInstanceAddresses, common.HexToAddress(address)) - } - ocrOffchainOptions := contracts.DefaultOffChainAggregatorOptions() - ocrInstances, err := actions.SetupOCRv2Contracts(l, sethClient, 1, common.HexToAddress(lt.Address()), ocrInstanceAddresses, transmitters, ocrOffchainOptions) + ocrInstances, err := actions.SetupOCRv2Contracts(l, sethClient, config.OCR2, common.HexToAddress(linkContract.Address()), transmitters, ocrOffchainOptions) require.NoError(t, err, "Error deploying OCRv2 contracts with forwarders") ocrv2Config, err := actions.BuildMedianOCR2ConfigLocal(workerNodes, ocrOffchainOptions) diff --git a/integration-tests/smoke/ocr2_test.go b/integration-tests/smoke/ocr2_test.go index cdf26d7eb4c..579e0429724 100644 --- a/integration-tests/smoke/ocr2_test.go +++ b/integration-tests/smoke/ocr2_test.go @@ -169,12 +169,8 @@ func prepareORCv2SmokeTestEnv(t *testing.T, testData ocr2test, l zerolog.Logger, nodeClients := testEnv.ClCluster.NodeAPIs() bootstrapNode, workerNodes := nodeClients[0], nodeClients[1:] - var linkContract *contracts.EthereumLinkToken - if config.OCR2.Contracts != nil && config.OCR2.Contracts.UseExisting() { - linkContract, err = contracts.LoadLinkTokenContract(l, sethClient, common.HexToAddress(*config.OCR2.Contracts.LinkTokenAddress)) - } else { - linkContract, err = contracts.DeployLinkTokenContract(l, sethClient) - } + linkContract, err := actions.GetLinkTokenContract(l, sethClient, config.OCR2) + require.NoError(t, err, "Error loading/deploying link token contract") err = actions.FundChainlinkNodesFromRootAddress(l, sethClient, contracts.ChainlinkClientToChainlinkNodeWithKeysAndAddress(workerNodes), big.NewFloat(*config.Common.ChainlinkNodeFunding)) require.NoError(t, err, "Error funding Chainlink nodes") @@ -194,23 +190,20 @@ func prepareORCv2SmokeTestEnv(t *testing.T, testData ocr2test, l zerolog.Logger, transmitters = append(transmitters, addr) } - var ocrInstanceAddresses []common.Address - for _, address := range config.OCR2.Contracts.OffchainAggregatorAddresses { - ocrInstanceAddresses = append(ocrInstanceAddresses, common.HexToAddress(address)) - } - - ocrOffchainOptions := contracts.DefaultOffChainAggregatorOptions() - aggregatorContracts, err := actions.SetupOCRv2Contracts(l, sethClient, 1, common.HexToAddress(linkContract.Address()), ocrInstanceAddresses, transmitters, ocrOffchainOptions) + ocrOffChainOptions := contracts.DefaultOffChainAggregatorOptions() + aggregatorContracts, err := actions.SetupOCRv2Contracts(l, sethClient, config.OCR2, common.HexToAddress(linkContract.Address()), transmitters, ocrOffChainOptions) require.NoError(t, err, "Error deploying OCRv2 aggregator contracts") err = actions.CreateOCRv2JobsLocal(aggregatorContracts, bootstrapNode, workerNodes, testEnv.MockAdapter, "ocr2", 5, uint64(sethClient.ChainID), false, testData.chainReaderAndCodec) require.NoError(t, err, "Error creating OCRv2 jobs") - ocrv2Config, err := actions.BuildMedianOCR2ConfigLocal(workerNodes, ocrOffchainOptions) - require.NoError(t, err, "Error building OCRv2 config") + if config.OCR2.UseExistingOffChainAggregatorsContracts() && !config.OCR2.ConfigureExistingOffChainAggregatorsContracts() { + ocrV2Config, err := actions.BuildMedianOCR2ConfigLocal(workerNodes, ocrOffChainOptions) + require.NoError(t, err, "Error building OCRv2 config") - err = actions.ConfigureOCRv2AggregatorContracts(ocrv2Config, aggregatorContracts) - require.NoError(t, err, "Error configuring OCRv2 aggregator contracts") + err = actions.ConfigureOCRv2AggregatorContracts(ocrV2Config, aggregatorContracts) + require.NoError(t, err, "Error configuring OCRv2 aggregator contracts") + } assertCorrectNodeConfiguration(t, l, clNodeCount, testData, testEnv) diff --git a/integration-tests/smoke/ocr_test.go b/integration-tests/smoke/ocr_test.go index ff841be14f8..697b2fe361d 100644 --- a/integration-tests/smoke/ocr_test.go +++ b/integration-tests/smoke/ocr_test.go @@ -81,9 +81,7 @@ func TestOCRJobReplacement(t *testing.T) { func prepareORCv1SmokeTestEnv(t *testing.T, l zerolog.Logger, firstRoundResult int64) (*test_env.CLClusterTestEnv, []contracts.OffchainAggregator, *seth.Client) { config, err := tc.GetConfig([]string{"Smoke"}, tc.OCR) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err, "Error getting config") network, err := actions.EthereumNetworkConfigFromConfig(l, &config) require.NoError(t, err, "Error building ethereum network config") @@ -115,21 +113,10 @@ func prepareORCv1SmokeTestEnv(t *testing.T, l zerolog.Logger, firstRoundResult i _ = actions.ReturnFundsFromNodes(l, sethClient, contracts.ChainlinkClientToChainlinkNodeWithKeysAndAddress(env.ClCluster.NodeAPIs())) }) - var linkContract *contracts.EthereumLinkToken - if config.OCR.Contracts != nil && config.OCR.Contracts.UseExisting() { - linkContract, err = contracts.LoadLinkTokenContract(l, sethClient, common.HexToAddress(*config.OCR.Contracts.LinkTokenAddress)) - } else { - linkContract, err = contracts.DeployLinkTokenContract(l, sethClient) - } - + linkContract, err := actions.GetLinkTokenContract(l, sethClient, config.OCR) require.NoError(t, err, "Error loading/deploying link token contract") - var ocrInstanceAddresses []common.Address - for _, address := range config.OCR.Contracts.OffchainAggregatorAddresses { - ocrInstanceAddresses = append(ocrInstanceAddresses, common.HexToAddress(address)) - } - - ocrInstances, err := actions.SetupOCRv1Contracts(l, sethClient, 1, common.HexToAddress(linkContract.Address()), ocrInstanceAddresses, contracts.ChainlinkClientToChainlinkNodeWithKeysAndAddress(workerNodes)) + ocrInstances, err := actions.SetupOCRv1Contracts(l, sethClient, config.OCR, common.HexToAddress(linkContract.Address()), contracts.ChainlinkClientToChainlinkNodeWithKeysAndAddress(workerNodes)) require.NoError(t, err, "Error deploying OCR contracts") err = actions.CreateOCRJobsLocal(ocrInstances, bootstrapNode, workerNodes, 5, env.MockAdapter, big.NewInt(sethClient.ChainID)) diff --git a/integration-tests/testconfig/forwarder_ocr/example.toml b/integration-tests/testconfig/forwarder_ocr/example.toml index 0b762299af1..75143d7b77f 100644 --- a/integration-tests/testconfig/forwarder_ocr/example.toml +++ b/integration-tests/testconfig/forwarder_ocr/example.toml @@ -31,7 +31,7 @@ bearer_token_secret="bearer_token" base_url="http://grafana.url" # url of your grafana dashboard (prefix and suffix "/" are stirpped), example: /d/ad61652-2712-1722/my-dashboard dashboard_url="/d/your-dashboard" -# Grafana dashboard uid to annotate. Find it in Dashboard Settings -> JSON Model +# Grafana dashboard uid to annotate. Find it in Dashboard Settings -> JSON Model dashboard_uid="dashboard-uid-to-annotate" bearer_token_secret="my-awesome-token" @@ -143,6 +143,9 @@ BumpPercent = 20 BumpMin = '100 gwei' """ +[OCR.Common] +number_of_contracts=1 + # load test specific configuration [Load.OCR] [Load.OCR.Common] @@ -162,9 +165,8 @@ chainlink_node_funding = 100 [Soak.OCR] [Soak.OCR.Common] +number_of_contracts=2 test_duration="15m" [Soak.OCR.Soak] -ocr_version="1" -number_of_contracts=2 -time_between_rounds="1m" \ No newline at end of file +time_between_rounds="1m" diff --git a/integration-tests/testconfig/forwarder_ocr/forwarder_ocr.toml b/integration-tests/testconfig/forwarder_ocr/forwarder_ocr.toml index 344736cf90e..c60f17afec5 100644 --- a/integration-tests/testconfig/forwarder_ocr/forwarder_ocr.toml +++ b/integration-tests/testconfig/forwarder_ocr/forwarder_ocr.toml @@ -66,7 +66,10 @@ MinContractPayment = 0 [Transactions] ForwardersEnabled = true - """ +""" + +[OCR.Common] +number_of_contracts=1 # load test specific configuration [Load.OCR] @@ -101,10 +104,10 @@ chainlink_node_funding = 0.5 [Soak.OCR] [Soak.OCR.Common] +number_of_contracts=2 test_duration="15m" [Soak.OCR.Soak] -number_of_contracts=2 time_between_rounds="1m" diff --git a/integration-tests/testconfig/forwarder_ocr2/example.toml b/integration-tests/testconfig/forwarder_ocr2/example.toml index b3bc45d270c..4941c49a983 100644 --- a/integration-tests/testconfig/forwarder_ocr2/example.toml +++ b/integration-tests/testconfig/forwarder_ocr2/example.toml @@ -31,7 +31,7 @@ bearer_token_secret="bearer_token" base_url="http://grafana.url" # url of your grafana dashboard (prefix and suffix "/" are stirpped), example: /d/ad61652-2712-1722/my-dashboard dashboard_url="/d/your-dashboard" -# Grafana dashboard uid to annotate. Find it in Dashboard Settings -> JSON Model +# Grafana dashboard uid to annotate. Find it in Dashboard Settings -> JSON Model dashboard_uid="dashboard-uid-to-annotate" bearer_token_secret="my-awesome-token" @@ -143,12 +143,15 @@ BumpPercent = 20 BumpMin = '100 gwei' """ +[OCR2.Common] +number_of_contracts=1 + # load test specific configuration -[Load.OCR] -[Load.OCR.Common] +[Load.OCR2] +[Load.OCR2.Common] eth_funds = 3 -[Load.OCR.Load] +[Load.OCR2.Load] test_duration = "3m" rate_limit_unit_duration = "1m" rate = 3 @@ -160,11 +163,10 @@ ea_change_interval = "5s" [Soak.Common] chainlink_node_funding = 100 -[Soak.OCR] -[Soak.OCR.Common] +[Soak.OCR2] +[Soak.OCR2.Common] +number_of_contracts=2 test_duration="15m" -[Soak.OCR.Soak] -ocr_version="1" -number_of_contracts=2 -time_between_rounds="1m" \ No newline at end of file +[Soak.OCR2.Soak] +time_between_rounds="1m" diff --git a/integration-tests/testconfig/forwarder_ocr2/forwarder_ocr2.toml b/integration-tests/testconfig/forwarder_ocr2/forwarder_ocr2.toml index c7f0084c726..72c6198bc53 100644 --- a/integration-tests/testconfig/forwarder_ocr2/forwarder_ocr2.toml +++ b/integration-tests/testconfig/forwarder_ocr2/forwarder_ocr2.toml @@ -62,7 +62,10 @@ MinContractPayment = 0 [Transactions] ForwardersEnabled = true - """ +""" + +[OCR2.Common] +number_of_contracts=1 # load test specific configuration [Load.OCR2.Common] @@ -94,10 +97,10 @@ ea_change_interval = "5s" chainlink_node_funding = 1 [Soak.OCR2.Common] +number_of_contracts=2 test_duration="15m" [Soak.OCR2.Soak] -number_of_contracts=2 time_between_rounds="1m" diff --git a/integration-tests/testconfig/ocr/example.toml b/integration-tests/testconfig/ocr/example.toml index 92262241dff..26f0dd5a84e 100644 --- a/integration-tests/testconfig/ocr/example.toml +++ b/integration-tests/testconfig/ocr/example.toml @@ -31,7 +31,7 @@ bearer_token_secret="bearer_token" base_url="http://grafana.url" # url of your grafana dashboard (prefix and suffix "/" are stirpped), example: /d/ad61652-2712-1722/my-dashboard dashboard_url="/d/your-dashboard" -# Grafana dashboard uid to annotate. Find it in Dashboard Settings -> JSON Model +# Grafana dashboard uid to annotate. Find it in Dashboard Settings -> JSON Model dashboard_uid="dashboard-uid-to-annotate" bearer_token_secret="my-awesome-token" @@ -142,6 +142,9 @@ BumpPercent = 20 BumpMin = '100 gwei' """ +[OCR.Common] +number_of_contracts=1 + # load test specific configuration [Load.OCR] [Load.OCR.Common] @@ -161,8 +164,8 @@ chainlink_node_funding = 100 [Soak.OCR] [Soak.OCR.Common] +number_of_contracts=2 test_duration="15m" [Soak.OCR.Soak] -number_of_contracts=2 time_between_rounds="1m" diff --git a/integration-tests/testconfig/ocr/ocr.go b/integration-tests/testconfig/ocr/ocr.go index f8f0ebd027e..d7dbaa8da1a 100644 --- a/integration-tests/testconfig/ocr/ocr.go +++ b/integration-tests/testconfig/ocr/ocr.go @@ -41,11 +41,15 @@ func (o *Config) Validate() error { } type Common struct { - ETHFunds *int `toml:"eth_funds"` - TestDuration *blockchain.StrDuration `toml:"test_duration"` + NumberOfContracts *int `toml:"number_of_contracts"` + ETHFunds *int `toml:"eth_funds"` + TestDuration *blockchain.StrDuration `toml:"test_duration"` } func (o *Common) Validate() error { + if o.NumberOfContracts != nil && *o.NumberOfContracts < 1 { + return errors.New("when number_of_contracts is set, it must be greater than 0") + } if o.ETHFunds != nil && *o.ETHFunds < 0 { return errors.New("eth_funds must be set and cannot be negative") } @@ -125,14 +129,10 @@ func (o *Volume) Validate() error { } type SoakConfig struct { - NumberOfContracts *int `toml:"number_of_contracts"` TimeBetweenRounds *blockchain.StrDuration `toml:"time_between_rounds"` } func (o *SoakConfig) Validate() error { - if o.NumberOfContracts == nil || *o.NumberOfContracts <= 1 { - return errors.New("number_of_contracts must be set and be greater than 1") - } if o.TimeBetweenRounds == nil || o.TimeBetweenRounds.Duration == 0 { return errors.New("time_between_rounds must be set and be a positive integer") } @@ -140,9 +140,10 @@ func (o *SoakConfig) Validate() error { } type Contracts struct { - Settings *ContractSettings `toml:"Settings"` - LinkTokenAddress *string `toml:"link_token"` - OffchainAggregatorAddresses []string `toml:"offchain_aggregators"` + ShouldBeUsed *bool `toml:"use"` + LinkTokenAddress *string `toml:"link_token"` + OffchainAggregatorAddresses []string `toml:"offchain_aggregators"` + Settings map[string]ContractSetting `toml:"Settings"` } func (o *Contracts) Validate() error { @@ -150,32 +151,143 @@ func (o *Contracts) Validate() error { return errors.New("link_token must be a valid ethereum address") } if o.OffchainAggregatorAddresses != nil { + allEnabled := make(map[bool]int) + allConfigure := make(map[bool]int) for _, address := range o.OffchainAggregatorAddresses { if !common.IsHexAddress(address) { return fmt.Errorf("offchain_aggregators must be valid ethereum addresses, but %s is not", address) } + + if v, ok := o.Settings[address]; ok { + if v.ShouldBeUsed != nil { + allEnabled[*v.ShouldBeUsed]++ + } else { + allEnabled[true]++ + } + if v.Configure != nil { + allConfigure[*v.Configure]++ + } else { + allConfigure[true]++ + } + } + } + + if allEnabled[true] > 0 && allEnabled[false] > 0 { + return errors.New("either all or none offchain_aggregators must be used") + } + + if allConfigure[true] > 0 && allConfigure[false] > 0 { + return errors.New("either all or none offchain_aggregators must be configured") } } return nil } -func (o *Contracts) UseExisting() bool { - if o.Settings != nil && o.Settings.UseExisting != nil { - return *o.Settings.UseExisting +func (o *Config) UseExistingContracts() bool { + if o.Contracts == nil { + return false + } + + if o.Contracts.ShouldBeUsed != nil { + return *o.Contracts.ShouldBeUsed } return false } -func (o *Contracts) MustGetLinkTokenContractAddress() common.Address { - if o.LinkTokenAddress != nil { - return common.HexToAddress(*o.LinkTokenAddress) +func (o *Config) GetLinkTokenContractAddress() (common.Address, error) { + if o.Contracts != nil && o.Contracts.LinkTokenAddress != nil { + return common.HexToAddress(*o.Contracts.LinkTokenAddress), nil + } + + return common.Address{}, errors.New("link token address must be set") +} + +func (o *Config) UseExistingLinkTokenContract() bool { + if !o.UseExistingContracts() { + return false + } + + if o.Contracts.LinkTokenAddress == nil { + return false + } + + if len(o.Contracts.Settings) == 0 { + return true } - panic("link token address must be set") + if v, ok := o.Contracts.Settings[*o.Contracts.LinkTokenAddress]; ok { + return v.ShouldBeUsed != nil && *v.ShouldBeUsed + } + + return true +} + +type ContractSetting struct { + ShouldBeUsed *bool `toml:"use"` + Configure *bool `toml:"configure"` +} + +type OffChainAggregatorsConfig interface { + GetOffChainAggregatorsContractsAddresses() []common.Address + UseExistingOffChainAggregatorsContracts() bool + ConfigureExistingOffChainAggregatorsContracts() bool + GetNumberOfContractsToDeploy() int } -type ContractSettings struct { - UseExisting *bool `toml:"use_existing"` - Configure *bool `toml:"configure"` +func (o *Config) UseExistingOffChainAggregatorsContracts() bool { + if !o.UseExistingContracts() { + return false + } + + if len(o.Contracts.OffchainAggregatorAddresses) == 0 { + return false + } + + if len(o.Contracts.Settings) == 0 { + return true + } + + for _, address := range o.Contracts.OffchainAggregatorAddresses { + if v, ok := o.Contracts.Settings[address]; ok { + return v.ShouldBeUsed != nil && *v.ShouldBeUsed + } + } + + return true +} + +func (o *Config) GetOffChainAggregatorsContractsAddresses() []common.Address { + var ocrInstanceAddresses []common.Address + if !o.UseExistingOffChainAggregatorsContracts() { + return ocrInstanceAddresses + } + + for _, address := range o.Contracts.OffchainAggregatorAddresses { + ocrInstanceAddresses = append(ocrInstanceAddresses, common.HexToAddress(address)) + } + return ocrInstanceAddresses +} + +func (o *Config) ConfigureExistingOffChainAggregatorsContracts() bool { + if !o.UseExistingOffChainAggregatorsContracts() { + return true + } + + for _, address := range o.Contracts.OffchainAggregatorAddresses { + for maybeOcrAddress, setting := range o.Contracts.Settings { + if maybeOcrAddress == address { + return setting.Configure != nil && *setting.Configure + } + } + } + + return true +} + +func (o *Config) GetNumberOfContractsToDeploy() int { + if o.Soak != nil && o.Common.NumberOfContracts != nil { + return *o.Common.NumberOfContracts + } + return 0 } diff --git a/integration-tests/testconfig/ocr/ocr.toml b/integration-tests/testconfig/ocr/ocr.toml index ac0249334da..723aa4911df 100644 --- a/integration-tests/testconfig/ocr/ocr.toml +++ b/integration-tests/testconfig/ocr/ocr.toml @@ -43,6 +43,9 @@ Enabled = true ListenAddresses = ['0.0.0.0:6690'] """ +[OCR.Common] +number_of_contracts=1 + # load test specific configuration [Load.OCR] [Load.OCR.Common] @@ -77,9 +80,9 @@ chainlink_node_funding = 0.5 [Soak.OCR] [Soak.OCR.Common] test_duration="15m" +number_of_contracts=2 [Soak.OCR.Soak] -number_of_contracts=2 time_between_rounds="1m" # Soak test configuration with Geth reorg below finality with FinalityTagEnabled=false diff --git a/integration-tests/testconfig/ocr2/example.toml b/integration-tests/testconfig/ocr2/example.toml index 36e3105f219..624c3b77752 100644 --- a/integration-tests/testconfig/ocr2/example.toml +++ b/integration-tests/testconfig/ocr2/example.toml @@ -31,7 +31,7 @@ bearer_token_secret="bearer_token" base_url="http://grafana.url" # url of your grafana dashboard (prefix and suffix "/" are stirpped), example: /d/ad61652-2712-1722/my-dashboard dashboard_url="/d/your-dashboard" -# Grafana dashboard uid to annotate. Find it in Dashboard Settings -> JSON Model +# Grafana dashboard uid to annotate. Find it in Dashboard Settings -> JSON Model dashboard_uid="dashboard-uid-to-annotate" bearer_token_secret="my-awesome-token" @@ -142,6 +142,9 @@ BumpPercent = 20 BumpMin = '100 gwei' """ +[OCR2.Common] +number_of_contracts=1 + # load test specific configuration [Load.OCR2] [Load.OCR2.Common] @@ -161,8 +164,8 @@ chainlink_node_funding = 100 [Soak.OCR2] [Soak.OCR.Common] +number_of_contracts=2 test_duration="15m" [Soak.OCR2.Soak] -number_of_contracts=2 time_between_rounds="1m" diff --git a/integration-tests/testconfig/ocr2/ocr2.go b/integration-tests/testconfig/ocr2/ocr2.go index 4b46d599c18..60169e944fa 100644 --- a/integration-tests/testconfig/ocr2/ocr2.go +++ b/integration-tests/testconfig/ocr2/ocr2.go @@ -1,17 +1,13 @@ package ocr2 import ( - "errors" - - "github.com/smartcontractkit/chainlink-testing-framework/blockchain" - "github.com/smartcontractkit/chainlink/integration-tests/testconfig/ocr" ) type Config struct { - Soak *SoakConfig `toml:"Soak"` - Common *Common `toml:"Common"` - Contracts *ocr.Contracts `toml:"Contracts"` + Soak *ocr.SoakConfig `toml:"Soak"` + Common *ocr.Common `toml:"Common"` + Contracts *ocr.Contracts `toml:"Contracts"` } func (o *Config) Validate() error { @@ -32,30 +28,3 @@ func (o *Config) Validate() error { } return nil } - -type Common struct { - ETHFunds *int `toml:"eth_funds"` - TestDuration *blockchain.StrDuration `toml:"test_duration"` -} - -func (o *Common) Validate() error { - if o.ETHFunds != nil && *o.ETHFunds < 0 { - return errors.New("eth_funds must be set and cannot be negative") - } - return nil -} - -type SoakConfig struct { - NumberOfContracts *int `toml:"number_of_contracts"` - TimeBetweenRounds *blockchain.StrDuration `toml:"time_between_rounds"` -} - -func (o *SoakConfig) Validate() error { - if o.NumberOfContracts == nil || *o.NumberOfContracts <= 1 { - return errors.New("number_of_contracts must be set and be greater than 1") - } - if o.TimeBetweenRounds == nil || o.TimeBetweenRounds.Duration == 0 { - return errors.New("time_between_rounds must be set and be a positive integer") - } - return nil -} diff --git a/integration-tests/testconfig/ocr2/ocr2.toml b/integration-tests/testconfig/ocr2/ocr2.toml index ad195913bd0..62d92574ea8 100644 --- a/integration-tests/testconfig/ocr2/ocr2.toml +++ b/integration-tests/testconfig/ocr2/ocr2.toml @@ -43,6 +43,9 @@ Enabled = true ListenAddresses = ['0.0.0.0:6690'] """ +[OCR2.Common] +number_of_contracts=1 + # load test specific configuration [Load.OCR2] [Load.OCR2.Common] @@ -76,8 +79,8 @@ chainlink_node_funding = 0.5 [Soak.OCR2] [Soak.OCR2.Common] +number_of_contracts=2 test_duration="15m" [Soak.OCR2.Soak] -number_of_contracts=2 time_between_rounds="1m" diff --git a/integration-tests/testconfig/testconfig.go b/integration-tests/testconfig/testconfig.go index 5ee9f6121d8..c7178f70a19 100644 --- a/integration-tests/testconfig/testconfig.go +++ b/integration-tests/testconfig/testconfig.go @@ -71,7 +71,8 @@ type Ocr2TestConfig interface { } type LinkTokenContractConfig interface { - MustGetLinkTokenContractAddress() common.Address + GetLinkTokenContractAddress() (common.Address, error) + UseExistingLinkTokenContract() bool } type TestConfig struct { diff --git a/integration-tests/testsetups/ocr.go b/integration-tests/testsetups/ocr.go index d5f047c266a..b98f5808670 100644 --- a/integration-tests/testsetups/ocr.go +++ b/integration-tests/testsetups/ocr.go @@ -280,13 +280,8 @@ func (o *OCRSoakTest) Setup(ocrTestConfig tt.OcrTestConfig) { o.mockServer, err = ctf_client.ConnectMockServer(o.testEnvironment) require.NoError(o.t, err, "Creating mockserver clients shouldn't fail") - var linkContract *contracts.EthereumLinkToken - if ocrTestConfig.GetActiveOCRConfig().Contracts != nil && ocrTestConfig.GetActiveOCRConfig().Contracts.UseExisting() { - linkContract, err = contracts.LoadLinkTokenContract(o.log, sethClient, common.HexToAddress(*ocrTestConfig.GetActiveOCRConfig().Contracts.LinkTokenAddress)) - } else { - linkContract, err = contracts.DeployLinkTokenContract(o.log, sethClient) - } - require.NoError(o.t, err, "Error loading/deploying LINK contract") + linkContract, err := actions.GetLinkTokenContract(o.log, sethClient, ocrTestConfig.GetActiveOCRConfig().Contracts) + require.NoError(o.t, err, "Error loading/deploying link token contract") // Fund Chainlink nodes, excluding the bootstrap node o.log.Info().Float64("ETH amount per node", *o.Config.Common.ChainlinkNodeFunding).Msg("Funding Chainlink nodes") From 7b17467e2ecdd097df5a0caad2aed7c272594917 Mon Sep 17 00:00:00 2001 From: Bartek Tofel Date: Wed, 3 Jul 2024 11:02:56 +0200 Subject: [PATCH 3/8] use Seth's contract loader --- integration-tests/actions/actions.go | 39 +++++------ integration-tests/actions/contracts.go | 3 +- integration-tests/chaos/ocr_chaos_test.go | 4 +- .../contracts/ethereum_contracts.go | 64 +++++-------------- integration-tests/load/ocr/helper.go | 5 +- integration-tests/load/ocr/ocr_test.go | 4 +- integration-tests/load/ocr/vu.go | 9 ++- integration-tests/smoke/forwarder_ocr_test.go | 5 -- integration-tests/testconfig/ocr/ocr.go | 1 + integration-tests/testconfig/testconfig.go | 5 +- integration-tests/testsetups/ocr.go | 39 +++++------ 11 files changed, 66 insertions(+), 112 deletions(-) diff --git a/integration-tests/actions/actions.go b/integration-tests/actions/actions.go index 7657793bce9..b6bab22faef 100644 --- a/integration-tests/actions/actions.go +++ b/integration-tests/actions/actions.go @@ -12,41 +12,34 @@ import ( "testing" "time" - "github.com/pelletier/go-toml/v2" - geth "github.com/ethereum/go-ethereum" + "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + gethtypes "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/rpc" + "github.com/google/uuid" + "github.com/pelletier/go-toml/v2" + "github.com/pkg/errors" + "github.com/rs/zerolog" + "github.com/smartcontractkit/seth" + "github.com/test-go/testify/require" "go.uber.org/zap/zapcore" "github.com/smartcontractkit/chainlink-testing-framework/blockchain" + ctfconfig "github.com/smartcontractkit/chainlink-testing-framework/config" "github.com/smartcontractkit/chainlink-testing-framework/k8s/environment" "github.com/smartcontractkit/chainlink-testing-framework/logging" "github.com/smartcontractkit/chainlink-testing-framework/testreporters" "github.com/smartcontractkit/chainlink-testing-framework/utils/conversions" - "github.com/smartcontractkit/chainlink/integration-tests/contracts" - "github.com/smartcontractkit/chainlink/integration-tests/testconfig/ocr" - ethContracts "github.com/smartcontractkit/chainlink/integration-tests/contracts/ethereum" - - "github.com/ethereum/go-ethereum/accounts/abi" - - "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/crypto" - - "github.com/rs/zerolog" - - "github.com/ethereum/go-ethereum/common" - "github.com/google/uuid" - "github.com/smartcontractkit/seth" - - gethtypes "github.com/ethereum/go-ethereum/core/types" - "github.com/pkg/errors" - "github.com/test-go/testify/require" - - ctfconfig "github.com/smartcontractkit/chainlink-testing-framework/config" "github.com/smartcontractkit/chainlink-testing-framework/utils/testcontext" "github.com/smartcontractkit/chainlink/integration-tests/client" + "github.com/smartcontractkit/chainlink/integration-tests/contracts" + ethContracts "github.com/smartcontractkit/chainlink/integration-tests/contracts/ethereum" + "github.com/smartcontractkit/chainlink/integration-tests/testconfig/ocr" "github.com/smartcontractkit/chainlink/integration-tests/types/config/node" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/link_token_interface" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/operator_factory" @@ -879,7 +872,7 @@ func setupAnyOCRv1Contracts( } else { // Load contract wrappers for _, address := range ocrContractsConfig.GetOffChainAggregatorsContractsAddresses() { - ocrInstance, err := contracts.LoadOffchainAggregator(logger, seth, address) + ocrInstance, err := contracts.LoadOffChainAggregator(logger, seth, address) if err != nil { return nil, fmt.Errorf("OCR instance loading have failed: %w", err) } diff --git a/integration-tests/actions/contracts.go b/integration-tests/actions/contracts.go index 5b2d9a4bfb0..b8f47e14fa9 100644 --- a/integration-tests/actions/contracts.go +++ b/integration-tests/actions/contracts.go @@ -2,9 +2,10 @@ package actions import ( "github.com/rs/zerolog" + "github.com/smartcontractkit/seth" + "github.com/smartcontractkit/chainlink/integration-tests/contracts" tc "github.com/smartcontractkit/chainlink/integration-tests/testconfig" - "github.com/smartcontractkit/seth" ) func GetLinkTokenContract(l zerolog.Logger, sethClient *seth.Client, configWithLinkToken tc.LinkTokenContractConfig) (*contracts.EthereumLinkToken, error) { diff --git a/integration-tests/chaos/ocr_chaos_test.go b/integration-tests/chaos/ocr_chaos_test.go index ad8f2417c0e..9451224b259 100644 --- a/integration-tests/chaos/ocr_chaos_test.go +++ b/integration-tests/chaos/ocr_chaos_test.go @@ -181,13 +181,13 @@ func TestOCRChaos(t *testing.T) { ms, err := ctfClient.ConnectMockServer(testEnvironment) require.NoError(t, err, "Creating mockserver clients shouldn't fail") - linkContract, err := contracts.DeployLinkTokenContract(l, seth) + linkContract, err := actions.GetLinkTokenContract(l, seth, config.OCR) require.NoError(t, err, "Error deploying link token contract") err = actions.FundChainlinkNodesFromRootAddress(l, seth, contracts.ChainlinkK8sClientToChainlinkNodeWithKeysAndAddress(chainlinkNodes), big.NewFloat(10)) require.NoError(t, err) - ocrInstances, err := actions.SetupOCRv1Contracts(l, seth, 1, common.HexToAddress(linkContract.Address()), contracts.ChainlinkK8sClientToChainlinkNodeWithKeysAndAddress(workerNodes)) + ocrInstances, err := actions.SetupOCRv1Contracts(l, seth, config.OCR, common.HexToAddress(linkContract.Address()), contracts.ChainlinkK8sClientToChainlinkNodeWithKeysAndAddress(workerNodes)) require.NoError(t, err) err = actions.CreateOCRJobs(ocrInstances, bootstrapNode, workerNodes, 5, ms, fmt.Sprint(seth.ChainID)) require.NoError(t, err) diff --git a/integration-tests/contracts/ethereum_contracts.go b/integration-tests/contracts/ethereum_contracts.go index 50497e58d85..c15aae97504 100644 --- a/integration-tests/contracts/ethereum_contracts.go +++ b/integration-tests/contracts/ethereum_contracts.go @@ -206,22 +206,17 @@ type EthereumOffchainAggregator struct { l zerolog.Logger } -func LoadOffchainAggregator(l zerolog.Logger, seth *seth.Client, contractAddress common.Address) (EthereumOffchainAggregator, error) { - abi, err := offchainaggregator.OffchainAggregatorMetaData.GetAbi() - if err != nil { - return EthereumOffchainAggregator{}, fmt.Errorf("failed to get OffChain Aggregator ABI: %w", err) - } - seth.ContractStore.AddABI("OffChainAggregator", *abi) - seth.ContractStore.AddBIN("OffChainAggregator", common.FromHex(offchainaggregator.OffchainAggregatorMetaData.Bin)) +func LoadOffChainAggregator(l zerolog.Logger, sethClient *seth.Client, contractAddress common.Address) (EthereumOffchainAggregator, error) { + loader := seth.NewContractLoader[offchainaggregator.OffchainAggregator](sethClient) + instance, err := loader.LoadContract("LinkToken", contractAddress, offchainaggregator.OffchainAggregatorMetaData.GetAbi, offchainaggregator.NewOffchainAggregator) - ocr, err := offchainaggregator.NewOffchainAggregator(contractAddress, wrappers.MustNewWrappedContractBackend(nil, seth)) if err != nil { - return EthereumOffchainAggregator{}, fmt.Errorf("failed to instantiate OCR instance: %w", err) + return EthereumOffchainAggregator{}, fmt.Errorf("failed to instantiate OCR v2 instance: %w", err) } return EthereumOffchainAggregator{ - client: seth, - ocr: ocr, + client: sethClient, + ocr: instance, address: &contractAddress, l: l, }, nil @@ -582,23 +577,23 @@ type EthereumOffchainAggregatorV2 struct { l zerolog.Logger } -func LoadOffChainAggregatorV2(l zerolog.Logger, seth *seth.Client, contractAddress common.Address) (EthereumOffchainAggregatorV2, error) { - oAbi, err := ocr2aggregator.OCR2AggregatorMetaData.GetAbi() +func LoadOffchainAggregatorV2(l zerolog.Logger, seth *seth.Client, address common.Address) (EthereumOffchainAggregatorV2, error) { + contractAbi, err := ocr2aggregator.OCR2AggregatorMetaData.GetAbi() if err != nil { - return EthereumOffchainAggregatorV2{}, fmt.Errorf("failed to get OffChain Aggregator ABI: %w", err) + return EthereumOffchainAggregatorV2{}, fmt.Errorf("failed to get OffChain Aggregator v2 ABI: %w", err) } - seth.ContractStore.AddABI("OffChainAggregatorV2", *oAbi) + seth.ContractStore.AddABI("OffChainAggregatorV2", *contractAbi) seth.ContractStore.AddBIN("OffChainAggregatorV2", common.FromHex(ocr2aggregator.OCR2AggregatorMetaData.Bin)) - ocr2, err := ocr2aggregator.NewOCR2Aggregator(contractAddress, seth.Client) + ocr2, err := ocr2aggregator.NewOCR2Aggregator(address, seth.Client) if err != nil { - return EthereumOffchainAggregatorV2{}, fmt.Errorf("failed to instantiate OCR instance: %w", err) + return EthereumOffchainAggregatorV2{}, fmt.Errorf("failed to instantiate OCRv2 instance: %w", err) } return EthereumOffchainAggregatorV2{ client: seth, contract: ocr2, - address: &contractAddress, + address: &address, l: l, }, nil } @@ -638,27 +633,6 @@ func DeployOffchainAggregatorV2(l zerolog.Logger, seth *seth.Client, linkTokenAd }, nil } -func LoadOffchainAggregatorV2(l zerolog.Logger, seth *seth.Client, address common.Address) (EthereumOffchainAggregatorV2, error) { - contractAbi, err := ocr2aggregator.OCR2AggregatorMetaData.GetAbi() - if err != nil { - return EthereumOffchainAggregatorV2{}, fmt.Errorf("failed to get OffChain Aggregator v2 ABI: %w", err) - } - seth.ContractStore.AddABI("OffChainAggregatorV2", *contractAbi) - seth.ContractStore.AddBIN("OffChainAggregatorV2", common.FromHex(ocr2aggregator.OCR2AggregatorMetaData.Bin)) - - ocr2, err := ocr2aggregator.NewOCR2Aggregator(address, seth.Client) - if err != nil { - return EthereumOffchainAggregatorV2{}, fmt.Errorf("failed to instantiate OCRv2 instance: %w", err) - } - - return EthereumOffchainAggregatorV2{ - client: seth, - contract: ocr2, - address: &address, - l: l, - }, nil -} - func (e *EthereumOffchainAggregatorV2) Address() string { return e.address.Hex() } @@ -791,22 +765,16 @@ func DeployLinkTokenContract(l zerolog.Logger, client *seth.Client) (*EthereumLi } func LoadLinkTokenContract(l zerolog.Logger, client *seth.Client, address common.Address) (*EthereumLinkToken, error) { - abi, err := link_token_interface.LinkTokenMetaData.GetAbi() - if err != nil { - return &EthereumLinkToken{}, fmt.Errorf("failed to get LinkToken ABI: %w", err) - } - - client.ContractStore.AddABI("LinkToken", *abi) - client.ContractStore.AddBIN("LinkToken", common.FromHex(link_token_interface.LinkTokenMetaData.Bin)) + loader := seth.NewContractLoader[link_token_interface.LinkToken](client) + instance, err := loader.LoadContract("LinkToken", address, link_token_interface.LinkTokenMetaData.GetAbi, link_token_interface.NewLinkToken) - linkToken, err := link_token_interface.NewLinkToken(address, wrappers.MustNewWrappedContractBackend(nil, client)) if err != nil { return &EthereumLinkToken{}, fmt.Errorf("failed to instantiate LinkToken instance: %w", err) } return &EthereumLinkToken{ client: client, - instance: linkToken, + instance: instance, address: address, l: l, }, nil diff --git a/integration-tests/load/ocr/helper.go b/integration-tests/load/ocr/helper.go index 256bbf8f318..5fc43ee49f0 100644 --- a/integration-tests/load/ocr/helper.go +++ b/integration-tests/load/ocr/helper.go @@ -8,13 +8,13 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/rs/zerolog" - "github.com/smartcontractkit/seth" client2 "github.com/smartcontractkit/chainlink-testing-framework/client" "github.com/smartcontractkit/chainlink/integration-tests/actions" "github.com/smartcontractkit/chainlink/integration-tests/client" "github.com/smartcontractkit/chainlink/integration-tests/contracts" + tc "github.com/smartcontractkit/chainlink/integration-tests/testconfig" ) func SetupCluster( @@ -36,12 +36,13 @@ func SetupCluster( func SetupFeed( l zerolog.Logger, seth *seth.Client, + config *tc.TestConfig, lta common.Address, msClient *client2.MockserverClient, bootstrapNode *client.ChainlinkK8sClient, workerNodes []*client.ChainlinkK8sClient, ) ([]contracts.OffchainAggregator, error) { - ocrInstances, err := actions.SetupOCRv1Contracts(l, seth, 1, lta, contracts.ChainlinkK8sClientToChainlinkNodeWithKeysAndAddress(workerNodes)) + ocrInstances, err := actions.SetupOCRv1Contracts(l, seth, config.OCR, lta, contracts.ChainlinkK8sClientToChainlinkNodeWithKeysAndAddress(workerNodes)) if err != nil { return nil, err } diff --git a/integration-tests/load/ocr/ocr_test.go b/integration-tests/load/ocr/ocr_test.go index db90f67b3c6..966cff6e49d 100644 --- a/integration-tests/load/ocr/ocr_test.go +++ b/integration-tests/load/ocr/ocr_test.go @@ -36,7 +36,7 @@ func TestOCRLoad(t *testing.T) { lta, err := SetupCluster(l, seth, workerNodes) require.NoError(t, err) - ocrInstances, err := SetupFeed(l, seth, lta, msClient, bootstrapNode, workerNodes) + ocrInstances, err := SetupFeed(l, seth, &config, lta, msClient, bootstrapNode, workerNodes) require.NoError(t, err) cfg := config.OCR @@ -83,7 +83,7 @@ func TestOCRVolume(t *testing.T) { LoadType: wasp.VU, CallTimeout: cfg.Volume.VerificationTimeout.Duration, Schedule: wasp.Plain(*cfg.Volume.Rate, cfg.Volume.TestDuration.Duration), - VU: NewVU(l, seth, *cfg.Volume.VURequestsPerUnit, cfg.Volume.RateLimitUnitDuration.Duration, lta, bootstrapNode, workerNodes, msClient), + VU: NewVU(l, seth, cfg, *cfg.Volume.VURequestsPerUnit, cfg.Volume.RateLimitUnitDuration.Duration, lta, bootstrapNode, workerNodes, msClient), Labels: CommonTestLabels, LokiConfig: wasp.NewLokiConfig(cfgl.Endpoint, cfgl.TenantId, cfgl.BasicAuth, cfgl.BearerToken), })) diff --git a/integration-tests/load/ocr/vu.go b/integration-tests/load/ocr/vu.go index baebd37e2a1..f5393857365 100644 --- a/integration-tests/load/ocr/vu.go +++ b/integration-tests/load/ocr/vu.go @@ -8,9 +8,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/rs/zerolog" - "github.com/smartcontractkit/seth" - "github.com/smartcontractkit/wasp" "go.uber.org/ratelimit" @@ -19,6 +17,7 @@ import ( "github.com/smartcontractkit/chainlink/integration-tests/actions" "github.com/smartcontractkit/chainlink/integration-tests/client" "github.com/smartcontractkit/chainlink/integration-tests/contracts" + "github.com/smartcontractkit/chainlink/integration-tests/testconfig/ocr" ) // VU is a virtual user for the OCR load test @@ -36,11 +35,13 @@ type VU struct { msClient *client2.MockserverClient l zerolog.Logger ocrInstances []contracts.OffchainAggregator + config ocr.OffChainAggregatorsConfig } func NewVU( l zerolog.Logger, seth *seth.Client, + config ocr.OffChainAggregatorsConfig, rate int, rateUnit time.Duration, lta common.Address, @@ -59,6 +60,7 @@ func NewVU( msClient: msClient, bootstrapNode: bootstrapNode, workerNodes: workerNodes, + config: config, } } @@ -74,11 +76,12 @@ func (m *VU) Clone(_ *wasp.Generator) wasp.VirtualUser { msClient: m.msClient, bootstrapNode: m.bootstrapNode, workerNodes: m.workerNodes, + config: m.config, } } func (m *VU) Setup(_ *wasp.Generator) error { - ocrInstances, err := actions.SetupOCRv1Contracts(m.l, m.seth, 1, m.lta, contracts.ChainlinkK8sClientToChainlinkNodeWithKeysAndAddress(m.workerNodes)) + ocrInstances, err := actions.SetupOCRv1Contracts(m.l, m.seth, m.config, m.lta, contracts.ChainlinkK8sClientToChainlinkNodeWithKeysAndAddress(m.workerNodes)) if err != nil { return err } diff --git a/integration-tests/smoke/forwarder_ocr_test.go b/integration-tests/smoke/forwarder_ocr_test.go index 5f083b0b823..ee615c65d88 100644 --- a/integration-tests/smoke/forwarder_ocr_test.go +++ b/integration-tests/smoke/forwarder_ocr_test.go @@ -82,11 +82,6 @@ func TestForwarderOCRBasic(t *testing.T) { actions.TrackForwarder(t, sethClient, authorizedForwarders[i], workerNodes[i]) } - var ocrInstanceAddresses []common.Address - for _, address := range config.OCR.Contracts.OffchainAggregatorAddresses { - ocrInstanceAddresses = append(ocrInstanceAddresses, common.HexToAddress(address)) - } - ocrInstances, err := actions.DeployOCRContractsForwarderFlow( l, sethClient, diff --git a/integration-tests/testconfig/ocr/ocr.go b/integration-tests/testconfig/ocr/ocr.go index d7dbaa8da1a..4f21f55abba 100644 --- a/integration-tests/testconfig/ocr/ocr.go +++ b/integration-tests/testconfig/ocr/ocr.go @@ -3,6 +3,7 @@ package ocr import ( "errors" "fmt" + "github.com/ethereum/go-ethereum/common" "github.com/smartcontractkit/chainlink-testing-framework/blockchain" diff --git a/integration-tests/testconfig/testconfig.go b/integration-tests/testconfig/testconfig.go index c7178f70a19..6e7ef069137 100644 --- a/integration-tests/testconfig/testconfig.go +++ b/integration-tests/testconfig/testconfig.go @@ -4,21 +4,20 @@ import ( "embed" "encoding/base64" "fmt" - "github.com/ethereum/go-ethereum/common" "math/big" "os" "slices" "strings" "github.com/barkimedes/go-deepcopy" + "github.com/ethereum/go-ethereum/common" "github.com/google/uuid" "github.com/pelletier/go-toml/v2" "github.com/pkg/errors" + "github.com/smartcontractkit/seth" "golang.org/x/text/cases" "golang.org/x/text/language" - "github.com/smartcontractkit/seth" - ctf_config "github.com/smartcontractkit/chainlink-testing-framework/config" k8s_config "github.com/smartcontractkit/chainlink-testing-framework/k8s/config" "github.com/smartcontractkit/chainlink-testing-framework/logging" diff --git a/integration-tests/testsetups/ocr.go b/integration-tests/testsetups/ocr.go index b98f5808670..c6f062cf8e1 100644 --- a/integration-tests/testsetups/ocr.go +++ b/integration-tests/testsetups/ocr.go @@ -280,7 +280,7 @@ func (o *OCRSoakTest) Setup(ocrTestConfig tt.OcrTestConfig) { o.mockServer, err = ctf_client.ConnectMockServer(o.testEnvironment) require.NoError(o.t, err, "Creating mockserver clients shouldn't fail") - linkContract, err := actions.GetLinkTokenContract(o.log, sethClient, ocrTestConfig.GetActiveOCRConfig().Contracts) + linkContract, err := actions.GetLinkTokenContract(o.log, sethClient, ocrTestConfig.GetActiveOCRConfig()) require.NoError(o.t, err, "Error loading/deploying link token contract") // Fund Chainlink nodes, excluding the bootstrap node @@ -289,11 +289,6 @@ func (o *OCRSoakTest) Setup(ocrTestConfig tt.OcrTestConfig) { require.NoError(o.t, err, "Error funding Chainlink nodes") var forwarders []common.Address - var ocrInstanceAddresses []common.Address - for _, address := range ocrTestConfig.GetActiveOCRConfig().Contracts.OffchainAggregatorAddresses { - ocrInstanceAddresses = append(ocrInstanceAddresses, common.HexToAddress(address)) - } - if o.OperatorForwarderFlow { var operators []common.Address operators, forwarders, _ = actions.DeployForwarderContracts( @@ -314,9 +309,8 @@ func (o *OCRSoakTest) Setup(ocrTestConfig tt.OcrTestConfig) { o.ocrV1Instances, err = actions.DeployOCRContractsForwarderFlow( o.log, o.seth, - *o.Config.GetActiveOCRConfig().Soak.NumberOfContracts, + o.Config.GetActiveOCRConfig(), common.HexToAddress(linkContract.Address()), - ocrInstanceAddresses, contracts.ChainlinkK8sClientToChainlinkNodeWithKeysAndAddress(o.workerNodes), forwarders, ) @@ -325,9 +319,8 @@ func (o *OCRSoakTest) Setup(ocrTestConfig tt.OcrTestConfig) { o.ocrV1Instances, err = actions.SetupOCRv1Contracts( o.log, sethClient, - *o.Config.GetActiveOCRConfig().Soak.NumberOfContracts, + o.Config.GetActiveOCRConfig(), common.HexToAddress(linkContract.Address()), - ocrInstanceAddresses, contracts.ChainlinkK8sClientToChainlinkNodeWithKeysAndAddress(o.workerNodes), ) require.NoError(o.t, err) @@ -351,9 +344,8 @@ func (o *OCRSoakTest) Setup(ocrTestConfig tt.OcrTestConfig) { o.ocrV2Instances, err = actions.SetupOCRv2Contracts( o.log, o.seth, - *ocrTestConfig.GetActiveOCRConfig().Soak.NumberOfContracts, + ocrTestConfig.GetActiveOCRConfig(), common.HexToAddress(linkContract.Address()), - ocrInstanceAddresses, transmitters, ocrOffchainOptions, ) @@ -405,7 +397,7 @@ func (o *OCRSoakTest) Run() { o.log.Info(). Str("Test Duration", o.Config.GetActiveOCRConfig().Common.TestDuration.Duration.Truncate(time.Second).String()). - Int("Number of OCR Contracts", *config.GetActiveOCRConfig().Soak.NumberOfContracts). + Int("Number of OCR Contracts", *config.GetActiveOCRConfig().Common.NumberOfContracts). Str("OCR Version", o.OCRVersion). Msg("Starting OCR Soak Test") @@ -536,7 +528,7 @@ func (o *OCRSoakTest) LoadState() error { if testState.OCRVersion == "1" { o.ocrV1Instances = make([]contracts.OffchainAggregator, len(testState.OCRContractAddresses)) for i, addr := range testState.OCRContractAddresses { - instance, err := contracts.LoadOffchainAggregator(o.log, o.seth, common.HexToAddress(addr)) + instance, err := contracts.LoadOffChainAggregator(o.log, o.seth, common.HexToAddress(addr)) if err != nil { return fmt.Errorf("failed to instantiate OCR instance: %w", err) } @@ -545,7 +537,7 @@ func (o *OCRSoakTest) LoadState() error { } else if testState.OCRVersion == "2" { o.ocrV2Instances = make([]contracts.OffchainAggregatorV2, len(testState.OCRContractAddresses)) for i, addr := range testState.OCRContractAddresses { - instance, err := contracts.LoadOffChainAggregatorV2(o.log, o.seth, common.HexToAddress(addr)) + instance, err := contracts.LoadOffchainAggregatorV2(o.log, o.seth, common.HexToAddress(addr)) if err != nil { return err } @@ -571,7 +563,7 @@ func (o *OCRSoakTest) Resume() { Str("Time Left", o.timeLeft.String()). Msg("Resuming OCR Soak Test") - ocrAddresses := make([]common.Address, *o.Config.GetActiveOCRConfig().Soak.NumberOfContracts) + ocrAddresses := make([]common.Address, *o.Config.GetActiveOCRConfig().Common.NumberOfContracts) if o.OCRVersion == "1" { for i, ocrInstance := range o.ocrV1Instances { @@ -1031,12 +1023,12 @@ func (o *OCRSoakTest) collectEvents() error { // ensureValues ensures that all values needed to run the test are present func (o *OCRSoakTest) ensureInputValues() error { - ocrConfig := o.Config.GetActiveOCRConfig().Soak + ocrConfig := o.Config.GetActiveOCRConfig() if o.OCRVersion != "1" && o.OCRVersion != "2" { return fmt.Errorf("OCR version must be 1 or 2, found %s", o.OCRVersion) } - if ocrConfig.NumberOfContracts != nil && *ocrConfig.NumberOfContracts <= 0 { - return fmt.Errorf("number of OCR contracts must be set and greater than 0, found %d", ocrConfig.NumberOfContracts) + if ocrConfig.Common.NumberOfContracts != nil && *ocrConfig.Common.NumberOfContracts <= 0 { + return fmt.Errorf("number of OCR contracts must be set and greater than 0, found %d", ocrConfig.Common.NumberOfContracts) } if o.Config.Common.ChainlinkNodeFunding != nil && *o.Config.Common.ChainlinkNodeFunding <= 0 { return fmt.Errorf("chainlink node funding must be greater than 0, found %f", *o.Config.Common.ChainlinkNodeFunding) @@ -1044,11 +1036,12 @@ func (o *OCRSoakTest) ensureInputValues() error { if o.Config.GetActiveOCRConfig().Common.TestDuration != nil && o.Config.GetActiveOCRConfig().Common.TestDuration.Duration <= time.Minute { return fmt.Errorf("test duration must be greater than 1 minute, found %s", o.Config.GetActiveOCRConfig().Common.TestDuration) } - if ocrConfig.TimeBetweenRounds != nil && ocrConfig.TimeBetweenRounds.Duration >= time.Hour { - return fmt.Errorf("time between rounds must be less than 1 hour, found %s", ocrConfig.TimeBetweenRounds) + soakConfig := ocrConfig.Soak + if soakConfig.TimeBetweenRounds != nil && soakConfig.TimeBetweenRounds.Duration >= time.Hour { + return fmt.Errorf("time between rounds must be less than 1 hour, found %s", soakConfig.TimeBetweenRounds) } - if ocrConfig.TimeBetweenRounds != nil && ocrConfig.TimeBetweenRounds.Duration < time.Second*30 { - return fmt.Errorf("time between rounds must be greater or equal to 30 seconds, found %s", ocrConfig.TimeBetweenRounds) + if soakConfig.TimeBetweenRounds != nil && soakConfig.TimeBetweenRounds.Duration < time.Second*30 { + return fmt.Errorf("time between rounds must be greater or equal to 30 seconds, found %s", soakConfig.TimeBetweenRounds) } return nil From 416fd2341ca808a5ddd2a9749f573673290f2ef7 Mon Sep 17 00:00:00 2001 From: Bartek Tofel Date: Thu, 4 Jul 2024 11:03:46 +0200 Subject: [PATCH 4/8] fix getting number of contracts to deploy from config --- integration-tests/testconfig/ocr/ocr.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration-tests/testconfig/ocr/ocr.go b/integration-tests/testconfig/ocr/ocr.go index 4f21f55abba..e2ce6379440 100644 --- a/integration-tests/testconfig/ocr/ocr.go +++ b/integration-tests/testconfig/ocr/ocr.go @@ -287,7 +287,7 @@ func (o *Config) ConfigureExistingOffChainAggregatorsContracts() bool { } func (o *Config) GetNumberOfContractsToDeploy() int { - if o.Soak != nil && o.Common.NumberOfContracts != nil { + if o.Common != nil && o.Common.NumberOfContracts != nil { return *o.Common.NumberOfContracts } return 0 From 81c7d9b3838b7c7095b483650e907bf7e1e38251 Mon Sep 17 00:00:00 2001 From: Bartek Tofel Date: Thu, 4 Jul 2024 11:39:06 +0200 Subject: [PATCH 5/8] fix configuration logic in ocrv2 smoke/soak tests --- integration-tests/smoke/ocr2_test.go | 2 +- integration-tests/testsetups/ocr.go | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/integration-tests/smoke/ocr2_test.go b/integration-tests/smoke/ocr2_test.go index 579e0429724..41e294d00e0 100644 --- a/integration-tests/smoke/ocr2_test.go +++ b/integration-tests/smoke/ocr2_test.go @@ -197,7 +197,7 @@ func prepareORCv2SmokeTestEnv(t *testing.T, testData ocr2test, l zerolog.Logger, err = actions.CreateOCRv2JobsLocal(aggregatorContracts, bootstrapNode, workerNodes, testEnv.MockAdapter, "ocr2", 5, uint64(sethClient.ChainID), false, testData.chainReaderAndCodec) require.NoError(t, err, "Error creating OCRv2 jobs") - if config.OCR2.UseExistingOffChainAggregatorsContracts() && !config.OCR2.ConfigureExistingOffChainAggregatorsContracts() { + if !config.OCR2.UseExistingOffChainAggregatorsContracts() || (config.OCR2.UseExistingOffChainAggregatorsContracts() && config.OCR2.ConfigureExistingOffChainAggregatorsContracts()) { ocrV2Config, err := actions.BuildMedianOCR2ConfigLocal(workerNodes, ocrOffChainOptions) require.NoError(t, err, "Error building OCRv2 config") diff --git a/integration-tests/testsetups/ocr.go b/integration-tests/testsetups/ocr.go index c6f062cf8e1..e3c84d4f8ff 100644 --- a/integration-tests/testsetups/ocr.go +++ b/integration-tests/testsetups/ocr.go @@ -350,10 +350,12 @@ func (o *OCRSoakTest) Setup(ocrTestConfig tt.OcrTestConfig) { ocrOffchainOptions, ) require.NoError(o.t, err, "Error deploying OCRv2 contracts") - contractConfig, err := actions.BuildMedianOCR2Config(o.workerNodes, ocrOffchainOptions) - require.NoError(o.t, err, "Error building median config") - err = actions.ConfigureOCRv2AggregatorContracts(contractConfig, o.ocrV2Instances) - require.NoError(o.t, err, "Error configuring OCRv2 aggregator contracts") + if !ocrTestConfig.GetActiveOCRConfig().UseExistingOffChainAggregatorsContracts() || (ocrTestConfig.GetActiveOCRConfig().UseExistingOffChainAggregatorsContracts() && ocrTestConfig.GetActiveOCRConfig().ConfigureExistingOffChainAggregatorsContracts()) { + contractConfig, err := actions.BuildMedianOCR2Config(o.workerNodes, ocrOffchainOptions) + require.NoError(o.t, err, "Error building median config") + err = actions.ConfigureOCRv2AggregatorContracts(contractConfig, o.ocrV2Instances) + require.NoError(o.t, err, "Error configuring OCRv2 aggregator contracts") + } } if o.OCRVersion == "1" { From dcaff0674c0169a56debfa2f70fbd4621a132bad Mon Sep 17 00:00:00 2001 From: Bartek Tofel Date: Thu, 4 Jul 2024 12:47:41 +0200 Subject: [PATCH 6/8] uncomment ocr2 plugins --- integration-tests/smoke/ocr2_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/integration-tests/smoke/ocr2_test.go b/integration-tests/smoke/ocr2_test.go index 41e294d00e0..46d166cefa3 100644 --- a/integration-tests/smoke/ocr2_test.go +++ b/integration-tests/smoke/ocr2_test.go @@ -46,12 +46,12 @@ func TestOCRv2Basic(t *testing.T) { t.Parallel() noMedianPlugin := map[string]string{string(env.MedianPlugin.Cmd): ""} - //medianPlugin := map[string]string{string(env.MedianPlugin.Cmd): "chainlink-feeds"} + medianPlugin := map[string]string{string(env.MedianPlugin.Cmd): "chainlink-feeds"} for _, test := range []ocr2test{ {"legacy", noMedianPlugin, false}, - //{"legacy-chain-reader", noMedianPlugin, true}, - //{"plugins", medianPlugin, false}, - //{"plugins-chain-reader", medianPlugin, true}, + {"legacy-chain-reader", noMedianPlugin, true}, + {"plugins", medianPlugin, false}, + {"plugins-chain-reader", medianPlugin, true}, } { test := test t.Run(test.name, func(t *testing.T) { From 1eb94b2852d49534d48917b17b38af58cd1205ee Mon Sep 17 00:00:00 2001 From: Bartek Tofel Date: Fri, 30 Aug 2024 18:51:31 +0200 Subject: [PATCH 7/8] rename some methods, add contract-related information to readme --- integration-tests/actions/actions.go | 16 +++- integration-tests/actions/contracts.go | 8 +- integration-tests/actions/ocr_helpers.go | 2 +- integration-tests/chaos/ocr_chaos_test.go | 2 +- integration-tests/crib/ocr_test.go | 10 +-- integration-tests/smoke/forwarder_ocr_test.go | 2 +- .../smoke/forwarders_ocr2_test.go | 2 +- integration-tests/smoke/ocr2_test.go | 2 +- integration-tests/smoke/ocr_test.go | 2 +- integration-tests/testconfig/README.md | 90 +++++++++++++++++++ integration-tests/testconfig/ocr/ocr.go | 28 +++--- integration-tests/testconfig/testconfig.go | 2 +- integration-tests/testsetups/ocr.go | 2 +- 13 files changed, 134 insertions(+), 34 deletions(-) diff --git a/integration-tests/actions/actions.go b/integration-tests/actions/actions.go index 48a7822a506..05aa4d00451 100644 --- a/integration-tests/actions/actions.go +++ b/integration-tests/actions/actions.go @@ -621,8 +621,12 @@ func SetupOCRv2Contracts( ) ([]contracts.OffchainAggregatorV2, error) { var ocrInstances []contracts.OffchainAggregatorV2 + if ocrContractsConfig == nil { + return nil, fmt.Errorf("you need to pass non-nil OffChainAggregatorsConfig to setup OCR contracts") + } + if !ocrContractsConfig.UseExistingOffChainAggregatorsContracts() { - for contractCount := 0; contractCount < ocrContractsConfig.GetNumberOfContractsToDeploy(); contractCount++ { + for contractCount := 0; contractCount < ocrContractsConfig.NumberOfContractsToDeploy(); contractCount++ { ocrInstance, err := contracts.DeployOffchainAggregatorV2( l, seth, @@ -638,7 +642,7 @@ func SetupOCRv2Contracts( } } } else { - for _, address := range ocrContractsConfig.GetOffChainAggregatorsContractsAddresses() { + for _, address := range ocrContractsConfig.OffChainAggregatorsContractsAddresses() { ocrInstance, err := contracts.LoadOffchainAggregatorV2(l, seth, address) if err != nil { return nil, fmt.Errorf("OCRv2 instance loading have failed: %w", err) @@ -872,9 +876,13 @@ func setupAnyOCRv1Contracts( ) ([]contracts.OffchainAggregator, error) { var ocrInstances []contracts.OffchainAggregator + if ocrContractsConfig == nil { + return nil, fmt.Errorf("you need to pass non-nil OffChainAggregatorsConfig to setup OCR contracts") + } + if !ocrContractsConfig.UseExistingOffChainAggregatorsContracts() { // Deploy contracts - for contractCount := 0; contractCount < ocrContractsConfig.GetNumberOfContractsToDeploy(); contractCount++ { + for contractCount := 0; contractCount < ocrContractsConfig.NumberOfContractsToDeploy(); contractCount++ { ocrInstance, err := contracts.DeployOffchainAggregator(logger, seth, linkTokenContractAddress, contracts.DefaultOffChainAggregatorOptions()) if err != nil { return nil, fmt.Errorf("OCR instance deployment have failed: %w", err) @@ -886,7 +894,7 @@ func setupAnyOCRv1Contracts( } } else { // Load contract wrappers - for _, address := range ocrContractsConfig.GetOffChainAggregatorsContractsAddresses() { + for _, address := range ocrContractsConfig.OffChainAggregatorsContractsAddresses() { ocrInstance, err := contracts.LoadOffChainAggregator(logger, seth, address) if err != nil { return nil, fmt.Errorf("OCR instance loading have failed: %w", err) diff --git a/integration-tests/actions/contracts.go b/integration-tests/actions/contracts.go index c40ae8bb3db..1a50c4d7ba9 100644 --- a/integration-tests/actions/contracts.go +++ b/integration-tests/actions/contracts.go @@ -9,10 +9,10 @@ import ( tc "github.com/smartcontractkit/chainlink/integration-tests/testconfig" ) -// GetLinkTokenContract returns a link token contract instance. Depending on test configuration, it either deploys a new one or uses an existing one. -func GetLinkTokenContract(l zerolog.Logger, sethClient *seth.Client, configWithLinkToken tc.LinkTokenContractConfig) (*contracts.EthereumLinkToken, error) { - if configWithLinkToken.UseExistingLinkTokenContract() { - linkAddress, err := configWithLinkToken.GetLinkTokenContractAddress() +// LinkTokenContract returns a link token contract instance. Depending on test configuration, it either deploys a new one or uses an existing one. +func LinkTokenContract(l zerolog.Logger, sethClient *seth.Client, configWithLinkToken tc.LinkTokenContractConfig) (*contracts.EthereumLinkToken, error) { + if configWithLinkToken != nil && configWithLinkToken.UseExistingLinkTokenContract() { + linkAddress, err := configWithLinkToken.LinkTokenContractAddress() if err != nil { return nil, err } diff --git a/integration-tests/actions/ocr_helpers.go b/integration-tests/actions/ocr_helpers.go index 58d537928e4..e83ff998924 100644 --- a/integration-tests/actions/ocr_helpers.go +++ b/integration-tests/actions/ocr_helpers.go @@ -238,7 +238,7 @@ func SetupOCRv1Cluster( if err != nil { return common.Address{}, err } - linkContract, err := GetLinkTokenContract(l, seth, configWithLinkToken) + linkContract, err := LinkTokenContract(l, seth, configWithLinkToken) if err != nil { return common.Address{}, err } diff --git a/integration-tests/chaos/ocr_chaos_test.go b/integration-tests/chaos/ocr_chaos_test.go index 9d3b994d50a..4a1bb01c4b6 100644 --- a/integration-tests/chaos/ocr_chaos_test.go +++ b/integration-tests/chaos/ocr_chaos_test.go @@ -179,7 +179,7 @@ func TestOCRChaos(t *testing.T) { }) ms := ctfClient.ConnectMockServer(testEnvironment) - linkContract, err := actions.GetLinkTokenContract(l, seth, config.OCR) + linkContract, err := actions.LinkTokenContract(l, seth, config.OCR) require.NoError(t, err, "Error deploying link token contract") err = actions.FundChainlinkNodesFromRootAddress(l, seth, contracts.ChainlinkK8sClientToChainlinkNodeWithKeysAndAddress(chainlinkNodes), big.NewFloat(10)) diff --git a/integration-tests/crib/ocr_test.go b/integration-tests/crib/ocr_test.go index 6d1565a0ee3..4f9928ad8ad 100644 --- a/integration-tests/crib/ocr_test.go +++ b/integration-tests/crib/ocr_test.go @@ -6,19 +6,17 @@ import ( "testing" "time" - "github.com/smartcontractkit/chainlink-testing-framework/utils/ptr" - ocr_config "github.com/smartcontractkit/chainlink/integration-tests/testconfig/ocr" + "github.com/stretchr/testify/require" "github.com/smartcontractkit/chainlink-testing-framework/client" "github.com/smartcontractkit/chainlink-testing-framework/havoc" - - "github.com/stretchr/testify/require" + "github.com/smartcontractkit/chainlink-testing-framework/logging" + "github.com/smartcontractkit/chainlink-testing-framework/utils/ptr" "github.com/smartcontractkit/chainlink/integration-tests/actions" "github.com/smartcontractkit/chainlink/integration-tests/contracts" tc "github.com/smartcontractkit/chainlink/integration-tests/testconfig" - - "github.com/smartcontractkit/chainlink-testing-framework/logging" + ocr_config "github.com/smartcontractkit/chainlink/integration-tests/testconfig/ocr" ) // TestCRIBChaos an example of how we can run chaos tests with havoc and core CRIB diff --git a/integration-tests/smoke/forwarder_ocr_test.go b/integration-tests/smoke/forwarder_ocr_test.go index 71319aa0cff..abc0967d864 100644 --- a/integration-tests/smoke/forwarder_ocr_test.go +++ b/integration-tests/smoke/forwarder_ocr_test.go @@ -60,7 +60,7 @@ func TestForwarderOCRBasic(t *testing.T) { _ = actions.ReturnFundsFromNodes(l, sethClient, contracts.ChainlinkClientToChainlinkNodeWithKeysAndAddress(env.ClCluster.NodeAPIs())) }) - linkContract, err := actions.GetLinkTokenContract(l, sethClient, config.OCR) + linkContract, err := actions.LinkTokenContract(l, sethClient, config.OCR) require.NoError(t, err, "Error loading/deploying link token contract") fundingAmount := big.NewFloat(.05) diff --git a/integration-tests/smoke/forwarders_ocr2_test.go b/integration-tests/smoke/forwarders_ocr2_test.go index b687ce03800..1d08bc06635 100644 --- a/integration-tests/smoke/forwarders_ocr2_test.go +++ b/integration-tests/smoke/forwarders_ocr2_test.go @@ -61,7 +61,7 @@ func TestForwarderOCR2Basic(t *testing.T) { _ = actions.ReturnFundsFromNodes(l, sethClient, contracts.ChainlinkClientToChainlinkNodeWithKeysAndAddress(env.ClCluster.NodeAPIs())) }) - linkContract, err := actions.GetLinkTokenContract(l, sethClient, config.OCR2) + linkContract, err := actions.LinkTokenContract(l, sethClient, config.OCR2) require.NoError(t, err, "Error loading/deploying link token contract") fundingAmount := big.NewFloat(.05) diff --git a/integration-tests/smoke/ocr2_test.go b/integration-tests/smoke/ocr2_test.go index f26616b8413..93edcc87121 100644 --- a/integration-tests/smoke/ocr2_test.go +++ b/integration-tests/smoke/ocr2_test.go @@ -170,7 +170,7 @@ func prepareORCv2SmokeTestEnv(t *testing.T, testData ocr2test, l zerolog.Logger, nodeClients := testEnv.ClCluster.NodeAPIs() bootstrapNode, workerNodes := nodeClients[0], nodeClients[1:] - linkContract, err := actions.GetLinkTokenContract(l, sethClient, config.OCR2) + linkContract, err := actions.LinkTokenContract(l, sethClient, config.OCR2) require.NoError(t, err, "Error loading/deploying link token contract") err = actions.FundChainlinkNodesFromRootAddress(l, sethClient, contracts.ChainlinkClientToChainlinkNodeWithKeysAndAddress(workerNodes), big.NewFloat(*config.Common.ChainlinkNodeFunding)) diff --git a/integration-tests/smoke/ocr_test.go b/integration-tests/smoke/ocr_test.go index dc07cf01cfb..c433b960f5a 100644 --- a/integration-tests/smoke/ocr_test.go +++ b/integration-tests/smoke/ocr_test.go @@ -113,7 +113,7 @@ func prepareORCv1SmokeTestEnv(t *testing.T, l zerolog.Logger, firstRoundResult i _ = actions.ReturnFundsFromNodes(l, sethClient, contracts.ChainlinkClientToChainlinkNodeWithKeysAndAddress(env.ClCluster.NodeAPIs())) }) - linkContract, err := actions.GetLinkTokenContract(l, sethClient, config.OCR) + linkContract, err := actions.LinkTokenContract(l, sethClient, config.OCR) require.NoError(t, err, "Error loading/deploying link token contract") ocrInstances, err := actions.SetupOCRv1Contracts(l, sethClient, config.OCR, common.HexToAddress(linkContract.Address()), contracts.ChainlinkClientToChainlinkNodeWithKeysAndAddress(workerNodes)) diff --git a/integration-tests/testconfig/README.md b/integration-tests/testconfig/README.md index 9055cff2cba..7b73d960eb9 100644 --- a/integration-tests/testconfig/README.md +++ b/integration-tests/testconfig/README.md @@ -186,6 +186,96 @@ BumpMin = '100 gwei' For more examples see `example.toml` in product TOML configs like `testconfig/automation/example.toml`. If either ChainConfigTOMLByChainID or CommonChainConfigTOML is defined, it will override any defaults that Chainlink Node might have for the given network. Part of the configuration that defines blockchain node URLs is always dynamically generated based on the EVMNetwork configuration. Currently, all networks are treated as EVM networks. There's no way to provide Solana, Starknet, Cosmos or Aptos configuration yet. +### OCR tests contract config +In order to allow running OCR soak/load/smoke tests with already deployed contracts, we have provided an experimental feature for providing addresses of LINK token and OCR contracts in the TOML config. Additionally, user can choose, whether existing OCR contracts should be configured or not. +If no contract addresses are provided, the tests will deploy new contracts. + +The feature is highly configurable and it possible to use existing LINK token contract, but deploy new OCR contracts or vice versa. Both OCRv1 and OCRv2 contracts are supported. + +To use existing LINK and OCRv1 contracts, provide the following configuration in the TOML file: +```toml +[OCR.Contracts] +link_token = "0x88d1239894D9582f5849E5b5a964da9e5730f1E6" +offchain_aggregators = ["0xc1ce3815d6e7f3705265c2577F1342344752A5Eb"] +``` + +For OCRv2, provide the following configuration: +```toml +[OCR2.Contracts] +link_token = "0x88d1239894D9582f5849E5b5a964da9e5730f1E6" +offchain_aggregators = ["0xc1ce3815d6e7f3705265c2577F1342344752A5Eb"] +``` + +If you want to disable them, you can set `use = false` or remove the addresses from the configuration. + +If you want to use existing OCRv1 contract, without configuring it, you can set `configure = false` in the configuration: +```toml +[OCR.Contracts] +link_token = "0x88d1239894D9582f5849E5b5a964da9e5730f1E6" +offchain_aggregators = ["0xc1ce3815d6e7f3705265c2577F1342344752A5Eb"] + +# notice that this address needs to match the one in offchain_aggregators +[OCR.Contracts.Settings."0xc1ce3815d6e7f3705265c2577F1342344752A5Eb"] +configure = false +``` + +Be aware that using multiple existing OCR contracts, but configuring only some of them is not supported. This is not a valid configuration: +```toml +[OCR.Contracts] +link_token = "0x88d1239894D9582f5849E5b5a964da9e5730f1E6" +offchain_aggregators = ["0xc1ce3815d6e7f3705265c2577F1342344752A5Eb", "0x2f4FA21fCd917C448C160caafEC874032F404c08"] + +# notice that this address needs to match the one in offchain_aggregators +[OCR.Contracts.Settings."0xc1ce3815d6e7f3705265c2577F1342344752A5Eb"] +configure = false + +# if setting for a given address is not present, we assume it should be used and configured +# so in this case "0x2f4FA21fCd917C448C160caafEC874032F404c08" will be evaluated as configure = true, +# but "0xc1ce3815d6e7f3705265c2577F1342344752A5Eb" is set to configure = false. +# this will fail configuration validation +``` + +This, more explicit version is also invalid: +```toml +[OCR.Contracts] +link_token = "0x88d1239894D9582f5849E5b5a964da9e5730f1E6" +offchain_aggregators = ["0xc1ce3815d6e7f3705265c2577F1342344752A5Eb", "0x2f4FA21fCd917C448C160caafEC874032F404c08"] + +# notice that this address needs to match the one in offchain_aggregators +[OCR.Contracts.Settings."0xc1ce3815d6e7f3705265c2577F1342344752A5Eb"] +configure = false + +[OCR.Contracts.Settings."0x2f4FA21fCd917C448C160caafEC874032F404c08"] +configure = true +``` + +Similarly, this one is also invalid: +```toml +[OCR.Contracts] +link_token = "0x88d1239894D9582f5849E5b5a964da9e5730f1E6" +offchain_aggregators = ["0xc1ce3815d6e7f3705265c2577F1342344752A5Eb", "0x2f4FA21fCd917C448C160caafEC874032F404c08"] + +# notice that this address needs to match the one in offchain_aggregators +[OCR.Contracts.Settings."0xc1ce3815d6e7f3705265c2577F1342344752A5Eb"] +use = false + +[OCR.Contracts.Settings."0x2f4FA21fCd917C448C160caafEC874032F404c08"] +use = true +``` + +There are no settings available for LINK token contract. + +Last, but not least, when deploying new OCR contracts you need to provide their number. For example: +```toml +# for OCRv1 +[OCR.Common] +number_of_contracts=2 + +# for OCRv2 +[OCR2.Common] +number_of_contracts=2 +``` + ### Setting env vars for Chainlink Node To set env vars for Chainlink Node use `WithCLNodeOptions()` and `WithNodeEnvVars()` when building a test environment. Example: diff --git a/integration-tests/testconfig/ocr/ocr.go b/integration-tests/testconfig/ocr/ocr.go index e2ce6379440..066c3aed2ca 100644 --- a/integration-tests/testconfig/ocr/ocr.go +++ b/integration-tests/testconfig/ocr/ocr.go @@ -140,10 +140,11 @@ func (o *SoakConfig) Validate() error { return nil } +// For more information on the configuration of contracts, see https://smartcontract-it.atlassian.net/wiki/spaces/TT/pages/828407894/Contracts+addresses+in+TOML+convention type Contracts struct { ShouldBeUsed *bool `toml:"use"` LinkTokenAddress *string `toml:"link_token"` - OffchainAggregatorAddresses []string `toml:"offchain_aggregators"` + OffChainAggregatorAddresses []string `toml:"offchain_aggregators"` Settings map[string]ContractSetting `toml:"Settings"` } @@ -151,10 +152,10 @@ func (o *Contracts) Validate() error { if o.LinkTokenAddress != nil && !common.IsHexAddress(*o.LinkTokenAddress) { return errors.New("link_token must be a valid ethereum address") } - if o.OffchainAggregatorAddresses != nil { + if o.OffChainAggregatorAddresses != nil { allEnabled := make(map[bool]int) allConfigure := make(map[bool]int) - for _, address := range o.OffchainAggregatorAddresses { + for _, address := range o.OffChainAggregatorAddresses { if !common.IsHexAddress(address) { return fmt.Errorf("offchain_aggregators must be valid ethereum addresses, but %s is not", address) } @@ -193,10 +194,11 @@ func (o *Config) UseExistingContracts() bool { if o.Contracts.ShouldBeUsed != nil { return *o.Contracts.ShouldBeUsed } + return false } -func (o *Config) GetLinkTokenContractAddress() (common.Address, error) { +func (o *Config) LinkTokenContractAddress() (common.Address, error) { if o.Contracts != nil && o.Contracts.LinkTokenAddress != nil { return common.HexToAddress(*o.Contracts.LinkTokenAddress), nil } @@ -230,10 +232,10 @@ type ContractSetting struct { } type OffChainAggregatorsConfig interface { - GetOffChainAggregatorsContractsAddresses() []common.Address + OffChainAggregatorsContractsAddresses() []common.Address UseExistingOffChainAggregatorsContracts() bool ConfigureExistingOffChainAggregatorsContracts() bool - GetNumberOfContractsToDeploy() int + NumberOfContractsToDeploy() int } func (o *Config) UseExistingOffChainAggregatorsContracts() bool { @@ -241,7 +243,7 @@ func (o *Config) UseExistingOffChainAggregatorsContracts() bool { return false } - if len(o.Contracts.OffchainAggregatorAddresses) == 0 { + if len(o.Contracts.OffChainAggregatorAddresses) == 0 { return false } @@ -249,7 +251,7 @@ func (o *Config) UseExistingOffChainAggregatorsContracts() bool { return true } - for _, address := range o.Contracts.OffchainAggregatorAddresses { + for _, address := range o.Contracts.OffChainAggregatorAddresses { if v, ok := o.Contracts.Settings[address]; ok { return v.ShouldBeUsed != nil && *v.ShouldBeUsed } @@ -258,15 +260,16 @@ func (o *Config) UseExistingOffChainAggregatorsContracts() bool { return true } -func (o *Config) GetOffChainAggregatorsContractsAddresses() []common.Address { +func (o *Config) OffChainAggregatorsContractsAddresses() []common.Address { var ocrInstanceAddresses []common.Address if !o.UseExistingOffChainAggregatorsContracts() { return ocrInstanceAddresses } - for _, address := range o.Contracts.OffchainAggregatorAddresses { + for _, address := range o.Contracts.OffChainAggregatorAddresses { ocrInstanceAddresses = append(ocrInstanceAddresses, common.HexToAddress(address)) } + return ocrInstanceAddresses } @@ -275,7 +278,7 @@ func (o *Config) ConfigureExistingOffChainAggregatorsContracts() bool { return true } - for _, address := range o.Contracts.OffchainAggregatorAddresses { + for _, address := range o.Contracts.OffChainAggregatorAddresses { for maybeOcrAddress, setting := range o.Contracts.Settings { if maybeOcrAddress == address { return setting.Configure != nil && *setting.Configure @@ -286,9 +289,10 @@ func (o *Config) ConfigureExistingOffChainAggregatorsContracts() bool { return true } -func (o *Config) GetNumberOfContractsToDeploy() int { +func (o *Config) NumberOfContractsToDeploy() int { if o.Common != nil && o.Common.NumberOfContracts != nil { return *o.Common.NumberOfContracts } + return 0 } diff --git a/integration-tests/testconfig/testconfig.go b/integration-tests/testconfig/testconfig.go index 8500016deab..8b39fec5502 100644 --- a/integration-tests/testconfig/testconfig.go +++ b/integration-tests/testconfig/testconfig.go @@ -74,7 +74,7 @@ type Ocr2TestConfig interface { } type LinkTokenContractConfig interface { - GetLinkTokenContractAddress() (common.Address, error) + LinkTokenContractAddress() (common.Address, error) UseExistingLinkTokenContract() bool } diff --git a/integration-tests/testsetups/ocr.go b/integration-tests/testsetups/ocr.go index c99ac6fc7ad..3eb2fc53b28 100644 --- a/integration-tests/testsetups/ocr.go +++ b/integration-tests/testsetups/ocr.go @@ -281,7 +281,7 @@ func (o *OCRSoakTest) Setup(ocrTestConfig tt.OcrTestConfig) { o.mockServer = ctf_client.ConnectMockServer(o.testEnvironment) require.NoError(o.t, err, "Creating mockserver clients shouldn't fail") - linkContract, err := actions.GetLinkTokenContract(o.log, sethClient, ocrTestConfig.GetActiveOCRConfig()) + linkContract, err := actions.LinkTokenContract(o.log, sethClient, ocrTestConfig.GetActiveOCRConfig()) require.NoError(o.t, err, "Error loading/deploying link token contract") // Fund Chainlink nodes, excluding the bootstrap node From 87f10b911e9df0d922648ace6117d8ac18aa1c81 Mon Sep 17 00:00:00 2001 From: Bartek Tofel Date: Thu, 19 Sep 2024 16:50:12 +0200 Subject: [PATCH 8/8] fix lints --- integration-tests/load/ocr/vu.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/integration-tests/load/ocr/vu.go b/integration-tests/load/ocr/vu.go index 113e02b98c0..c337e338a82 100644 --- a/integration-tests/load/ocr/vu.go +++ b/integration-tests/load/ocr/vu.go @@ -10,9 +10,9 @@ import ( "github.com/rs/zerolog" "go.uber.org/ratelimit" - "github.com/smartcontractkit/chainlink-testing-framework/wasp" - "github.com/smartcontractkit/chainlink-testing-framework/seth" client2 "github.com/smartcontractkit/chainlink-testing-framework/lib/client" + "github.com/smartcontractkit/chainlink-testing-framework/seth" + "github.com/smartcontractkit/chainlink-testing-framework/wasp" "github.com/smartcontractkit/chainlink/integration-tests/actions" "github.com/smartcontractkit/chainlink/integration-tests/client"