Skip to content

Commit

Permalink
refactor + support v2.3 benchmark test (#14052)
Browse files Browse the repository at this point in the history
* update feeds used in automation tests

* comment unused vars

* support v2.3 in benchmark test
  • Loading branch information
anirudhwarrier authored Aug 12, 2024
1 parent 518cc28 commit 2b86088
Show file tree
Hide file tree
Showing 9 changed files with 178 additions and 110 deletions.
2 changes: 1 addition & 1 deletion integration-tests/actions/automation_ocr_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ func deployRegistry(
wethToken contracts.WETHToken,
ethUSDFeed contracts.MockETHUSDFeed,
) contracts.KeeperRegistry {
ef, err := contracts.DeployMockETHLINKFeed(client, big.NewInt(2e18))
ef, err := contracts.DeployMockLINKETHFeed(client, big.NewInt(2e18))
require.NoError(t, err, "Deploying mock ETH-Link feed shouldn't fail")
gf, err := contracts.DeployMockGASFeed(client, big.NewInt(2e11))
require.NoError(t, err, "Deploying mock gas feed shouldn't fail")
Expand Down
67 changes: 46 additions & 21 deletions integration-tests/actions/automationv2/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ type AutomationTest struct {

LinkToken contracts.LinkToken
Transcoder contracts.UpkeepTranscoder
EthLinkFeed contracts.MockETHLINKFeed
EthUSDFeed contracts.MockETHUSDFeed
LINKETHFeed contracts.MockLINKETHFeed
ETHUSDFeed contracts.MockETHUSDFeed
LINKUSDFeed contracts.MockETHUSDFeed
WETHToken contracts.WETHToken
GasFeed contracts.MockGasFeed
Registry contracts.KeeperRegistry
Expand Down Expand Up @@ -192,31 +193,30 @@ func (a *AutomationTest) LoadTranscoder(address string) error {
return nil
}

func (a *AutomationTest) DeployEthLinkFeed() error {
ethLinkFeed, err := contracts.DeployMockETHLINKFeed(a.ChainClient, a.RegistrySettings.FallbackLinkPrice)
func (a *AutomationTest) DeployLinkEthFeed() error {
ethLinkFeed, err := contracts.DeployMockLINKETHFeed(a.ChainClient, a.RegistrySettings.FallbackLinkPrice)
if err != nil {
return err
}
a.EthLinkFeed = ethLinkFeed
a.LINKETHFeed = ethLinkFeed
return nil
}

func (a *AutomationTest) LoadEthLinkFeed(address string) error {
ethLinkFeed, err := contracts.LoadMockETHLINKFeed(a.ChainClient, common.HexToAddress(address))
func (a *AutomationTest) LoadLinkEthFeed(address string) error {
ethLinkFeed, err := contracts.LoadMockLINKETHFeed(a.ChainClient, common.HexToAddress(address))
if err != nil {
return err
}
a.EthLinkFeed = ethLinkFeed
a.LINKETHFeed = ethLinkFeed
return nil
}

func (a *AutomationTest) DeployEthUSDFeed() error {
// FallbackLinkPrice and FallbackETHPrice are the same
ethUSDFeed, err := contracts.DeployMockETHUSDFeed(a.ChainClient, a.RegistrySettings.FallbackLinkPrice)
if err != nil {
return err
}
a.EthUSDFeed = ethUSDFeed
a.ETHUSDFeed = ethUSDFeed
return nil
}

Expand All @@ -225,7 +225,25 @@ func (a *AutomationTest) LoadEthUSDFeed(address string) error {
if err != nil {
return err
}
a.EthUSDFeed = ethUSDFeed
a.ETHUSDFeed = ethUSDFeed
return nil
}

func (a *AutomationTest) DeployLinkUSDFeed() error {
linkUSDFeed, err := contracts.DeployMockETHUSDFeed(a.ChainClient, a.RegistrySettings.FallbackLinkPrice)
if err != nil {
return err
}
a.LINKUSDFeed = linkUSDFeed
return nil
}

func (a *AutomationTest) LoadLinkUSDFeed(address string) error {
linkUSDFeed, err := contracts.LoadMockETHUSDFeed(a.ChainClient, common.HexToAddress(address))
if err != nil {
return err
}
a.LINKUSDFeed = linkUSDFeed
return nil
}

Expand Down Expand Up @@ -269,13 +287,13 @@ func (a *AutomationTest) DeployRegistry() error {
registryOpts := &contracts.KeeperRegistryOpts{
RegistryVersion: a.RegistrySettings.RegistryVersion,
LinkAddr: a.LinkToken.Address(),
ETHFeedAddr: a.EthLinkFeed.Address(),
ETHFeedAddr: a.LINKETHFeed.Address(),
GasFeedAddr: a.GasFeed.Address(),
TranscoderAddr: a.Transcoder.Address(),
RegistrarAddr: utils.ZeroAddress.Hex(),
Settings: a.RegistrySettings,
LinkUSDFeedAddr: a.EthUSDFeed.Address(),
NativeUSDFeedAddr: a.EthUSDFeed.Address(),
LinkUSDFeedAddr: a.ETHUSDFeed.Address(),
NativeUSDFeedAddr: a.LINKUSDFeed.Address(),
WrappedNativeAddr: a.WETHToken.Address(),
}
registry, err := contracts.DeployKeeperRegistry(a.ChainClient, registryOpts)
Expand Down Expand Up @@ -563,15 +581,15 @@ func (a *AutomationTest) SetConfigOnRegistry() error {
{
GasFeePPB: 100,
FlatFeeMilliCents: big.NewInt(500),
PriceFeed: common.HexToAddress(a.EthUSDFeed.Address()), // ETH/USD feed and LINK/USD feed are the same
PriceFeed: common.HexToAddress(a.ETHUSDFeed.Address()),
Decimals: 18,
FallbackPrice: big.NewInt(1000),
MinSpend: big.NewInt(200),
},
{
GasFeePPB: 100,
FlatFeeMilliCents: big.NewInt(500),
PriceFeed: common.HexToAddress(a.EthUSDFeed.Address()), // ETH/USD feed and LINK/USD feed are the same
PriceFeed: common.HexToAddress(a.LINKUSDFeed.Address()),
Decimals: 18,
FallbackPrice: big.NewInt(1000),
MinSpend: big.NewInt(200),
Expand Down Expand Up @@ -853,14 +871,17 @@ func (a *AutomationTest) SetupAutomationDeployment(t *testing.T) {
err = a.DeployWETH()
require.NoError(t, err, "Error deploying weth token contract")

err = a.DeployEthLinkFeed()
require.NoError(t, err, "Error deploying eth link feed contract")
err = a.DeployLinkEthFeed()
require.NoError(t, err, "Error deploying link eth feed contract")
err = a.DeployGasFeed()
require.NoError(t, err, "Error deploying gas feed contract")

err = a.DeployEthUSDFeed()
require.NoError(t, err, "Error deploying eth usd feed contract")

err = a.DeployLinkUSDFeed()
require.NoError(t, err, "Error deploying link usd feed contract")

err = a.DeployTranscoder()
require.NoError(t, err, "Error deploying transcoder contract")

Expand All @@ -873,7 +894,7 @@ func (a *AutomationTest) SetupAutomationDeployment(t *testing.T) {
}

func (a *AutomationTest) LoadAutomationDeployment(t *testing.T, linkTokenAddress,
ethLinkFeedAddress, gasFeedAddress, transcoderAddress, registryAddress, registrarAddress string) {
linkEthFeedAddress, linkUsdFeedAddress, EthUsdFeedAddress, gasFeedAddress, transcoderAddress, registryAddress, registrarAddress string) {
l := logging.GetTestLogger(t)
err := a.CollectNodeDetails()
require.NoError(t, err, "Error collecting node details")
Expand All @@ -883,10 +904,14 @@ func (a *AutomationTest) LoadAutomationDeployment(t *testing.T, linkTokenAddress
err = a.LoadLINK(linkTokenAddress)
require.NoError(t, err, "Error loading link token contract")

err = a.LoadEthLinkFeed(ethLinkFeedAddress)
require.NoError(t, err, "Error loading eth link feed contract")
err = a.LoadLinkEthFeed(linkEthFeedAddress)
require.NoError(t, err, "Error loading link eth feed contract")
err = a.LoadEthGasFeed(gasFeedAddress)
require.NoError(t, err, "Error loading gas feed contract")
err = a.LoadEthUSDFeed(EthUsdFeedAddress)
require.NoError(t, err, "Error loading eth usd feed contract")
err = a.LoadLinkUSDFeed(linkUsdFeedAddress)
require.NoError(t, err, "Error loading link usd feed contract")
err = a.LoadTranscoder(transcoderAddress)
require.NoError(t, err, "Error loading transcoder contract")
err = a.LoadRegistry(registryAddress)
Expand Down
6 changes: 3 additions & 3 deletions integration-tests/actions/keeper_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func DeployKeeperContracts(
client *seth.Client,
linkFundsForEachUpkeep *big.Int,
) (contracts.KeeperRegistry, contracts.KeeperRegistrar, []contracts.KeeperConsumer, []*big.Int) {
ef, err := contracts.DeployMockETHLINKFeed(client, big.NewInt(2e18))
ef, err := contracts.DeployMockLINKETHFeed(client, big.NewInt(2e18))
require.NoError(t, err, "Deploying mock ETH-Link feed shouldn't fail")
gf, err := contracts.DeployMockGASFeed(client, big.NewInt(2e11))
require.NoError(t, err, "Deploying mock gas feed shouldn't fail")
Expand Down Expand Up @@ -136,7 +136,7 @@ func DeployPerformanceKeeperContracts(
checkGasToBurn, // How much gas should be burned on checkUpkeep() calls
performGasToBurn int64, // How much gas should be burned on performUpkeep() calls
) (contracts.KeeperRegistry, contracts.KeeperRegistrar, []contracts.KeeperConsumerPerformance, []*big.Int) {
ef, err := contracts.DeployMockETHLINKFeed(chainClient, big.NewInt(2e18))
ef, err := contracts.DeployMockLINKETHFeed(chainClient, big.NewInt(2e18))
require.NoError(t, err, "Deploying mock ETH-Link feed shouldn't fail")
gf, err := contracts.DeployMockGASFeed(chainClient, big.NewInt(2e11))
require.NoError(t, err, "Deploying mock gas feed shouldn't fail")
Expand Down Expand Up @@ -196,7 +196,7 @@ func DeployPerformDataCheckerContracts(
linkFundsForEachUpkeep *big.Int,
expectedData []byte,
) (contracts.KeeperRegistry, contracts.KeeperRegistrar, []contracts.KeeperPerformDataChecker, []*big.Int) {
ef, err := contracts.DeployMockETHLINKFeed(chainClient, big.NewInt(2e18))
ef, err := contracts.DeployMockLINKETHFeed(chainClient, big.NewInt(2e18))
require.NoError(t, err, "Deploying mock ETH-Link feed shouldn't fail")
gf, err := contracts.DeployMockGASFeed(chainClient, big.NewInt(2e11))
require.NoError(t, err, "Deploying mock gas feed shouldn't fail")
Expand Down
95 changes: 33 additions & 62 deletions integration-tests/benchmark/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@ import (
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink-testing-framework/blockchain"
ctf_config "github.com/smartcontractkit/chainlink-testing-framework/config"
env_client "github.com/smartcontractkit/chainlink-testing-framework/k8s/client"
ctfconfig "github.com/smartcontractkit/chainlink-testing-framework/config"
envclient "github.com/smartcontractkit/chainlink-testing-framework/k8s/client"
"github.com/smartcontractkit/chainlink-testing-framework/k8s/environment"
"github.com/smartcontractkit/chainlink-testing-framework/k8s/pkg/helm/chainlink"
"github.com/smartcontractkit/chainlink-testing-framework/k8s/pkg/helm/ethereum"
"github.com/smartcontractkit/chainlink-testing-framework/k8s/pkg/helm/reorg"
"github.com/smartcontractkit/chainlink-testing-framework/logging"
"github.com/smartcontractkit/chainlink-testing-framework/networks"
seth_utils "github.com/smartcontractkit/chainlink-testing-framework/utils/seth"
sethutils "github.com/smartcontractkit/chainlink-testing-framework/utils/seth"

"github.com/smartcontractkit/chainlink/integration-tests/actions"
"github.com/smartcontractkit/chainlink/integration-tests/contracts"
eth_contracts "github.com/smartcontractkit/chainlink/integration-tests/contracts/ethereum"
ethcontracts "github.com/smartcontractkit/chainlink/integration-tests/contracts/ethereum"
tc "github.com/smartcontractkit/chainlink/integration-tests/testconfig"
"github.com/smartcontractkit/chainlink/integration-tests/testsetups"
"github.com/smartcontractkit/chainlink/integration-tests/types"
)

var (
performanceChainlinkResources = map[string]interface{}{
chainlinkResources = map[string]interface{}{
"resources": map[string]interface{}{
"requests": map[string]interface{}{
"cpu": "1000m",
Expand All @@ -41,7 +41,7 @@ var (
},
},
}
performanceDbResources = map[string]interface{}{
dbResources = map[string]interface{}{
"resources": map[string]interface{}{
"requests": map[string]interface{}{
"cpu": "1000m",
Expand All @@ -55,33 +55,6 @@ var (
"stateful": true,
"capacity": "10Gi",
}

soakChainlinkResources = map[string]interface{}{
"resources": map[string]interface{}{
"requests": map[string]interface{}{
"cpu": "350m",
"memory": "1Gi",
},
"limits": map[string]interface{}{
"cpu": "350m",
"memory": "1Gi",
},
},
}
soakDbResources = map[string]interface{}{
"resources": map[string]interface{}{
"requests": map[string]interface{}{
"cpu": "250m",
"memory": "256Mi",
},
"limits": map[string]interface{}{
"cpu": "250m",
"memory": "256Mi",
},
},
"stateful": true,
"capacity": "10Gi",
}
)

type NetworkConfig struct {
Expand Down Expand Up @@ -115,9 +88,9 @@ func TestAutomationBenchmark(t *testing.T) {
benchmarkTestNetwork := getNetworkConfig(&config)

l.Info().Str("Namespace", testEnvironment.Cfg.Namespace).Msg("Connected to Keepers Benchmark Environment")
testNetwork := seth_utils.MustReplaceSimulatedNetworkUrlWithK8(l, benchmarkNetwork, *testEnvironment)
testNetwork := sethutils.MustReplaceSimulatedNetworkUrlWithK8(l, benchmarkNetwork, *testEnvironment)

chainClient, err := seth_utils.GetChainClientWithConfigFunction(&config, testNetwork, seth_utils.OneEphemeralKeysLiveTestnetAutoFixFn)
chainClient, err := sethutils.GetChainClientWithConfigFunction(&config, testNetwork, sethutils.OneEphemeralKeysLiveTestnetAutoFixFn)
require.NoError(t, err, "Error getting Seth client")

registryVersions := addRegistry(&config)
Expand Down Expand Up @@ -173,40 +146,42 @@ func TestAutomationBenchmark(t *testing.T) {
keeperBenchmarkTest.Run()
}

func addRegistry(config *tc.TestConfig) []eth_contracts.KeeperRegistryVersion {
func addRegistry(config *tc.TestConfig) []ethcontracts.KeeperRegistryVersion {
switch *config.Keeper.Common.RegistryToTest {
case "1_1":
return []eth_contracts.KeeperRegistryVersion{eth_contracts.RegistryVersion_1_1}
return []ethcontracts.KeeperRegistryVersion{ethcontracts.RegistryVersion_1_1}
case "1_2":
return []eth_contracts.KeeperRegistryVersion{eth_contracts.RegistryVersion_1_2}
return []ethcontracts.KeeperRegistryVersion{ethcontracts.RegistryVersion_1_2}
case "1_3":
return []eth_contracts.KeeperRegistryVersion{eth_contracts.RegistryVersion_1_3}
return []ethcontracts.KeeperRegistryVersion{ethcontracts.RegistryVersion_1_3}
case "2_0":
return []eth_contracts.KeeperRegistryVersion{eth_contracts.RegistryVersion_2_0}
return []ethcontracts.KeeperRegistryVersion{ethcontracts.RegistryVersion_2_0}
case "2_1":
return []eth_contracts.KeeperRegistryVersion{eth_contracts.RegistryVersion_2_1}
return []ethcontracts.KeeperRegistryVersion{ethcontracts.RegistryVersion_2_1}
case "2_2":
return []eth_contracts.KeeperRegistryVersion{eth_contracts.RegistryVersion_2_2}
return []ethcontracts.KeeperRegistryVersion{ethcontracts.RegistryVersion_2_2}
case "2_3":
return []ethcontracts.KeeperRegistryVersion{ethcontracts.RegistryVersion_2_3}
case "2_0-1_3":
return []eth_contracts.KeeperRegistryVersion{eth_contracts.RegistryVersion_2_0, eth_contracts.RegistryVersion_1_3}
return []ethcontracts.KeeperRegistryVersion{ethcontracts.RegistryVersion_2_0, ethcontracts.RegistryVersion_1_3}
case "2_1-2_0-1_3":
return []eth_contracts.KeeperRegistryVersion{eth_contracts.RegistryVersion_2_1,
eth_contracts.RegistryVersion_2_0, eth_contracts.RegistryVersion_1_3}
return []ethcontracts.KeeperRegistryVersion{ethcontracts.RegistryVersion_2_1,
ethcontracts.RegistryVersion_2_0, ethcontracts.RegistryVersion_1_3}
case "2_2-2_1":
return []eth_contracts.KeeperRegistryVersion{eth_contracts.RegistryVersion_2_2, eth_contracts.RegistryVersion_2_1}
return []ethcontracts.KeeperRegistryVersion{ethcontracts.RegistryVersion_2_2, ethcontracts.RegistryVersion_2_1}
case "2_0-Multiple":
return repeatRegistries(eth_contracts.RegistryVersion_2_0, *config.Keeper.Common.NumberOfRegistries)
return repeatRegistries(ethcontracts.RegistryVersion_2_0, *config.Keeper.Common.NumberOfRegistries)
case "2_1-Multiple":
return repeatRegistries(eth_contracts.RegistryVersion_2_1, *config.Keeper.Common.NumberOfRegistries)
return repeatRegistries(ethcontracts.RegistryVersion_2_1, *config.Keeper.Common.NumberOfRegistries)
case "2_2-Multiple":
return repeatRegistries(eth_contracts.RegistryVersion_2_2, *config.Keeper.Common.NumberOfRegistries)
return repeatRegistries(ethcontracts.RegistryVersion_2_2, *config.Keeper.Common.NumberOfRegistries)
default:
return []eth_contracts.KeeperRegistryVersion{eth_contracts.RegistryVersion_2_0}
return []ethcontracts.KeeperRegistryVersion{ethcontracts.RegistryVersion_2_0}
}
}

func repeatRegistries(registryVersion eth_contracts.KeeperRegistryVersion, numberOfRegistries int) []eth_contracts.KeeperRegistryVersion {
repeatedRegistries := make([]eth_contracts.KeeperRegistryVersion, 0)
func repeatRegistries(registryVersion ethcontracts.KeeperRegistryVersion, numberOfRegistries int) []ethcontracts.KeeperRegistryVersion {
repeatedRegistries := make([]ethcontracts.KeeperRegistryVersion, 0)
for i := 0; i < numberOfRegistries; i++ {
repeatedRegistries = append(repeatedRegistries, registryVersion)
}
Expand Down Expand Up @@ -316,12 +291,8 @@ func SetupAutomationBenchmarkEnv(t *testing.T, keeperTestConfig types.KeeperBenc
PreventPodEviction: true,
})

dbResources := performanceDbResources
chainlinkResources := performanceChainlinkResources
if strings.Contains(strings.ToLower(strings.Join(keeperTestConfig.GetConfigurationNames(), ",")), "soak") {
chainlinkResources = soakChainlinkResources
dbResources = soakDbResources
}
dbResources := dbResources
chainlinkResources := chainlinkResources

// Test can run on simulated, simulated-non-dev, testnets
if testNetwork.Name == networks.SimulatedEVMNonDev.Name {
Expand Down Expand Up @@ -389,10 +360,10 @@ func SetupAutomationBenchmarkEnv(t *testing.T, keeperTestConfig types.KeeperBenc
// for simulated-nod-dev each CL node gets its own RPC node
if testNetwork.Name == networks.SimulatedEVMNonDev.Name {
podName := fmt.Sprintf("%s-ethereum-geth:%d", testNetwork.Name, i)
txNodeInternalWs, err := testEnvironment.Fwd.FindPort(podName, "geth", "ws-rpc").As(env_client.RemoteConnection, env_client.WS)
txNodeInternalWs, err := testEnvironment.Fwd.FindPort(podName, "geth", "ws-rpc").As(envclient.RemoteConnection, envclient.WS)
require.NoError(t, err, "Error finding WS ports")
internalWsURLs = append(internalWsURLs, txNodeInternalWs)
txNodeInternalHttp, err := testEnvironment.Fwd.FindPort(podName, "geth", "http-rpc").As(env_client.RemoteConnection, env_client.HTTP)
txNodeInternalHttp, err := testEnvironment.Fwd.FindPort(podName, "geth", "http-rpc").As(envclient.RemoteConnection, envclient.HTTP)
require.NoError(t, err, "Error finding HTTP ports")
internalHttpURLs = append(internalHttpURLs, txNodeInternalHttp)
// for testnets with more than 1 RPC nodes
Expand All @@ -412,8 +383,8 @@ func SetupAutomationBenchmarkEnv(t *testing.T, keeperTestConfig types.KeeperBenc
testNetwork.URLs = []string{internalWsURLs[i]}

var overrideFn = func(_ interface{}, target interface{}) {
ctf_config.MustConfigOverrideChainlinkVersion(keeperTestConfig.GetChainlinkImageConfig(), target)
ctf_config.MightConfigOverridePyroscopeKey(keeperTestConfig.GetPyroscopeConfig(), target)
ctfconfig.MustConfigOverrideChainlinkVersion(keeperTestConfig.GetChainlinkImageConfig(), target)
ctfconfig.MightConfigOverridePyroscopeKey(keeperTestConfig.GetPyroscopeConfig(), target)
}

tomlConfig, err := actions.BuildTOMLNodeConfigForK8s(keeperTestConfig, testNetwork)
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/contracts/contract_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ type JobByInstance struct {
Instance string
}

type MockETHLINKFeed interface {
type MockLINKETHFeed interface {
Address() string
LatestRoundData() (*big.Int, error)
LatestRoundDataUpdatedAt() (*big.Int, error)
Expand Down
Loading

0 comments on commit 2b86088

Please sign in to comment.