Skip to content

Commit

Permalink
chain specific evm configs through test input toml (#278)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnieeG authored Nov 10, 2023
1 parent 586d385 commit 0d3027a
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 101 deletions.
5 changes: 4 additions & 1 deletion integration-tests/ccip-tests/testconfig/ccip.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type CCIPTestConfig struct {
KeepEnvAlive *bool `toml:",omitempty"`
BiDirectionalLane *bool `toml:",omitempty"`
CommitAndExecuteOnSameDON *bool `toml:",omitempty"`
NumberOfCommitNodes int `toml:",omitempty"`
NoOfCommitNodes int `toml:",omitempty"`
MsgType string `toml:",omitempty"`
MulticallInOneTx *bool `toml:",omitempty"`
NoOfSendsInMulticall int `toml:",omitempty"`
Expand Down Expand Up @@ -47,6 +47,9 @@ func (c *CCIPTestConfig) ApplyOverrides(fromCfg *CCIPTestConfig) error {
if fromCfg.KeepEnvAlive != nil {
c.KeepEnvAlive = fromCfg.KeepEnvAlive
}
if fromCfg.NoOfCommitNodes > 0 && fromCfg.NoOfCommitNodes != c.NoOfCommitNodes {
c.NoOfCommitNodes = fromCfg.NoOfCommitNodes
}
if fromCfg.MsgType != "" {
c.MsgType = fromCfg.MsgType
}
Expand Down
31 changes: 23 additions & 8 deletions integration-tests/ccip-tests/testconfig/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,14 @@ func (c *Chainlink) Validate() error {
}

type Node struct {
Name string `toml:",omitempty"`
Image string `toml:",omitempty"`
Tag string `toml:",omitempty"`
NodeConfig string `toml:",omitempty"`
DBImage string `toml:",omitempty"`
DBTag string `toml:",omitempty"`
Name string `toml:",omitempty"`
Image string `toml:",omitempty"`
Tag string `toml:",omitempty"`
BaseConfigTOML string `toml:",omitempty"`
CommonChainConfigTOML string `toml:",omitempty"`
ChainConfigTOMLByChain map[string]string `toml:",omitempty"` // key is chainID
DBImage string `toml:",omitempty"`
DBTag string `toml:",omitempty"`
}

func (n *Node) ApplyOverrides(from *Node) {
Expand All @@ -298,7 +300,20 @@ func (n *Node) ApplyOverrides(from *Node) {
if from.DBTag != "" {
n.DBTag = from.DBTag
}
if from.NodeConfig != "" {
n.NodeConfig = from.NodeConfig
if from.BaseConfigTOML != "" {
n.BaseConfigTOML = from.BaseConfigTOML
}
if from.CommonChainConfigTOML != "" {
n.CommonChainConfigTOML = from.CommonChainConfigTOML
}
if from.ChainConfigTOMLByChain != nil {
if n.ChainConfigTOMLByChain == nil {
n.ChainConfigTOMLByChain = from.ChainConfigTOMLByChain
} else {
for chainID, toml := range from.ChainConfigTOMLByChain {
n.ChainConfigTOMLByChain[chainID] = toml
}
}

}
}
72 changes: 68 additions & 4 deletions integration-tests/ccip-tests/testconfig/tomls/default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ DBArgs = ['shared_buffers=1536MB', 'effective_cache_size=4096MB', 'work_mem=64MB
Name = 'node1'
DBImage = 'postgres'
DBTag = '13.12'
NodeConfig = """
BaseConfigTOML = """
[Feature]
LogPoller = true
CCIP = true
Expand Down Expand Up @@ -78,13 +78,77 @@ DeltaDial = '500ms'
DeltaReconcile = '5s'
"""

CommonChainConfigTOML = """
[GasEstimator]
PriceMax = '200 gwei'
LimitDefault = 6000000
FeeCapDefault = '200 gwei'
"""

[CCIP.Env.Chainlink.Common.ChainConfigTOMLByChain]
421613 = """
[GasEstimator]
PriceMax = '400 gwei'
LimitDefault = 100000000
FeeCapDefault = '200 gwei'
BumpThreshold = 60
BumpPercent = 20
BumpMin = '100 gwei'
"""

420 = """
[GasEstimator]
PriceMax = '150 gwei'
LimitDefault = 6000000
FeeCapDefault = '150 gwei'
BumpThreshold = 60
BumpPercent = 20
BumpMin = '100 gwei'
[GasEstimator.BlockHistory]
BlockHistorySize = 200
EIP1559FeeCapBufferBlocks = 0
"""

84531 = """
[GasEstimator]
PriceMax = '150 gwei'
LimitDefault = 6000000
FeeCapDefault = '150 gwei'
BumpThreshold = 60
BumpPercent = 20
BumpMin = '100 gwei'
[GasEstimator.BlockHistory]
BlockHistorySize = 200
EIP1559FeeCapBufferBlocks = 0
"""

43113 = """
[GasEstimator]
PriceMax = '200 gwei'
LimitDefault = 6000000
FeeCapDefault = '200 gwei'
BumpThreshold = 60
"""

11155111 = """
[GasEstimator]
PriceMax = '200 gwei'
LimitDefault = 6000000
FeeCapDefault = '200 gwei'
[GasEstimator.BlockHistory]
BlockHistorySize = 200
EIP1559FeeCapBufferBlocks = 0
"""

[CCIP.Groups]
[CCIP.Groups.smoke]
KeepEnvAlive = false
BiDirectionalLane = true
CommitAndExecuteOnSameDON = true
NumberOfCommitNodes = 5
NoOfCommitNodes = 5
MsgType = 'WithToken'
PhaseTimeout = '10m'
LocalCluster = true
Expand All @@ -103,7 +167,7 @@ NoOfSendsInMulticall = 5
KeepEnvAlive = false
BiDirectionalLane = true
CommitAndExecuteOnSameDON = true
NumberOfCommitNodes = 5
NoOfCommitNodes = 5
MsgType = 'WithToken'
PhaseTimeout = '50m'
TestDuration = '10m'
Expand All @@ -125,7 +189,7 @@ NoOfSendsInMulticall = 5
KeepEnvAlive = false
BiDirectionalLane = true
CommitAndExecuteOnSameDON = false
NumberOfCommitNodes = 5
NoOfCommitNodes = 5
MsgType = 'WithToken'
PhaseTimeout = '50m'
TestDuration = '10m'
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/ccip-tests/testsetups/ccip.go
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ func CCIPDefaultTestSetUp(
return setUpArgs.AddLanesForNetworkPair(
lggr, n.NetworkA, n.NetworkB,
chainByChainID[n.NetworkA.ChainID], chainByChainID[n.NetworkB.ChainID], transferAmounts,
inputs.TestGroupInput.NumberOfCommitNodes,
inputs.TestGroupInput.NoOfCommitNodes,
pointer.GetBool(inputs.TestGroupInput.CommitAndExecuteOnSameDON),
pointer.GetBool(inputs.TestGroupInput.BiDirectionalLane),
)
Expand Down
87 changes: 66 additions & 21 deletions integration-tests/ccip-tests/testsetups/test_env.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package testsetups

import (
"bytes"
"fmt"
"strconv"
"testing"
Expand All @@ -17,7 +18,9 @@ import (
"github.com/smartcontractkit/chainlink/integration-tests/ccip-tests/types/config/node"
"github.com/smartcontractkit/chainlink/integration-tests/docker/test_env"
integrationnodes "github.com/smartcontractkit/chainlink/integration-tests/types/config/node"
evmcfg "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml"
corechainlink "github.com/smartcontractkit/chainlink/v2/core/services/chainlink"
"github.com/smartcontractkit/chainlink/v2/core/utils/config"
)

func SetResourceProfile(cpu, mem string) map[string]interface{} {
Expand All @@ -33,6 +36,45 @@ func SetResourceProfile(cpu, mem string) map[string]interface{} {
}
}

func setNodeConfig(nets []blockchain.EVMNetwork, nodeConfig, commonChain string, configByChain map[string]string) (*corechainlink.Config, string, error) {
var tomlCfg *corechainlink.Config
var err error
var commonChainConfig *evmcfg.Chain
if commonChain != "" {
err = config.DecodeTOML(bytes.NewReader([]byte(commonChain)), &commonChainConfig)
if err != nil {
return nil, "", err
}
}
configByChainMap := make(map[int64]evmcfg.Chain)
if configByChain != nil {
for k, v := range configByChain {
var chain evmcfg.Chain
err = config.DecodeTOML(bytes.NewReader([]byte(v)), &chain)
if err != nil {
return nil, "", err
}
chainId, err := strconv.ParseInt(k, 10, 64)
if err != nil {
return nil, "", err
}
configByChainMap[chainId] = chain
}
}
if nodeConfig == "" {
tomlCfg = integrationnodes.NewConfig(
integrationnodes.NewBaseConfig(),
node.WithPrivateEVMs(nets, commonChainConfig, configByChainMap))
} else {
tomlCfg, err = node.NewConfigFromToml([]byte(nodeConfig), node.WithPrivateEVMs(nets, commonChainConfig, configByChainMap))
if err != nil {
return nil, "", err
}
}
tomlStr, err := tomlCfg.TOMLString()
return tomlCfg, tomlStr, err
}

func ChainlinkChart(
t *testing.T,
testInputs *CCIPTestConfig,
Expand Down Expand Up @@ -67,29 +109,24 @@ func ChainlinkChart(
}

require.NotNil(t, testInputs.EnvInput, "no env test input specified")
setNodeConfig := func(nodeConfig string) (string, error) {
var tomlCfg *corechainlink.Config
var err error
if nodeConfig == "" {
tomlCfg = integrationnodes.NewConfig(integrationnodes.NewBaseConfig(), node.WithPrivateEVMs(nets))
} else {
tomlCfg, err = node.NewConfigFromToml([]byte(nodeConfig), node.WithPrivateEVMs(nets))
if err != nil {
return "", err
}
}
return tomlCfg.TOMLString()
}

if len(testInputs.EnvInput.Chainlink.Nodes) > 0 {
var nodesMap []map[string]any
for _, clNode := range testInputs.EnvInput.Chainlink.Nodes {
nodeConfig := clNode.NodeConfig
nodeConfig := clNode.BaseConfigTOML
commonChainConfig := clNode.CommonChainConfigTOML
chainConfigByChain := clNode.ChainConfigTOMLByChain
if nodeConfig == "" {
nodeConfig = testInputs.EnvInput.Chainlink.Common.NodeConfig
nodeConfig = testInputs.EnvInput.Chainlink.Common.BaseConfigTOML
}
if commonChainConfig == "" {
commonChainConfig = testInputs.EnvInput.Chainlink.Common.CommonChainConfigTOML
}
if chainConfigByChain == nil {
chainConfigByChain = testInputs.EnvInput.Chainlink.Common.ChainConfigTOMLByChain
}

tomlStr, err := setNodeConfig(nodeConfig)
_, tomlStr, err := setNodeConfig(nets, nodeConfig, commonChainConfig, chainConfigByChain)
require.NoError(t, err)
nodesMap = append(nodesMap, map[string]any{
"name": clNode.Name,
Expand All @@ -112,7 +149,12 @@ func ChainlinkChart(
return chainlink.New(0, clProps)
}
clProps["replicas"] = pointer.GetInt(testInputs.EnvInput.Chainlink.NoOfNodes)
tomlStr, err := setNodeConfig(testInputs.EnvInput.Chainlink.Common.NodeConfig)
_, tomlStr, err := setNodeConfig(
nets,
testInputs.EnvInput.Chainlink.Common.BaseConfigTOML,
testInputs.EnvInput.Chainlink.Common.CommonChainConfigTOML,
testInputs.EnvInput.Chainlink.Common.ChainConfigTOMLByChain,
)
require.NoError(t, err)
clProps["toml"] = tomlStr
return chainlink.New(0, clProps)
Expand All @@ -138,16 +180,19 @@ func DeployLocalCluster(
}
}
}
configOpts := []integrationnodes.NodeConfigOpt{
node.WithPrivateEVMs(selectedNetworks),
}

// a func to start the CL nodes asynchronously
deployCL := func() error {
toml, err := node.NewConfigFromToml([]byte(testInputs.EnvInput.Chainlink.Common.NodeConfig), configOpts...)
toml, _, err := setNodeConfig(
selectedNetworks,
testInputs.EnvInput.Chainlink.Common.BaseConfigTOML,
testInputs.EnvInput.Chainlink.Common.CommonChainConfigTOML,
testInputs.EnvInput.Chainlink.Common.ChainConfigTOMLByChain,
)
if err != nil {
return err
}

noOfNodes := pointer.GetInt(testInputs.EnvInput.Chainlink.NoOfNodes)
return env.StartClCluster(toml, noOfNodes, "")
}
Expand Down
Loading

0 comments on commit 0d3027a

Please sign in to comment.