Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
AnieeG committed Dec 19, 2024
1 parent 514aefc commit cd17fe1
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 97 deletions.
2 changes: 1 addition & 1 deletion deployment/ccip/changeset/cs_prerequisites.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func WithMultiCall3Enabled() PrerequisiteOpt {
}
}

func WithLegacyDeployment(cfg LegacyDeploymentConfig) PrerequisiteOpt {
func WithLegacyDeploymentEnabled(cfg LegacyDeploymentConfig) PrerequisiteOpt {
return func(o *DeployPrerequisiteContractsOpts) {
if cfg.PriceRegStalenessThreshold == 0 {
panic("PriceRegStalenessThreshold must be set")
Expand Down
63 changes: 63 additions & 0 deletions deployment/ccip/changeset/test_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type TestConfigs struct {
CreateJob bool
// TODO: This should be CreateContracts so the booleans make sense?
CreateJobAndContracts bool
LegacyDeployment bool
Chains int // only used in memory mode, for docker mode, this is determined by the integration-test config toml input
ChainIDs []uint64 // only used in memory mode, for docker mode, this is determined by the integration-test config toml input
NumOfUsersPerChain int // only used in memory mode, for docker mode, this is determined by the integration-test config toml input
Expand Down Expand Up @@ -105,6 +106,12 @@ func WithMultiCall3() TestOps {
}
}

func WithLegacyDeployment() TestOps {
return func(testCfg *TestConfigs) {
testCfg.LegacyDeployment = true
}
}

func WithChainIds(chainIDs []uint64) TestOps {
return func(testCfg *TestConfigs) {
testCfg.ChainIDs = chainIDs
Expand Down Expand Up @@ -298,6 +305,9 @@ func NewMemoryEnvironment(t *testing.T, opts ...TestOps) DeployedEnv {
}
require.NoError(t, testCfg.Validate(), "invalid test config")
env := &MemoryEnvironment{}
if testCfg.LegacyDeployment {
return NewLegacyEnvironment(t, testCfg, env)
}
if testCfg.CreateJobAndContracts {
return NewEnvironmentWithJobsAndContracts(t, testCfg, env)
}
Expand All @@ -307,6 +317,59 @@ func NewMemoryEnvironment(t *testing.T, opts ...TestOps) DeployedEnv {
return NewEnvironment(t, testCfg, env)
}

func NewLegacyEnvironment(t *testing.T, tc *TestConfigs, tEnv TestEnvironment) DeployedEnv {
var err error
tEnv.StartChains(t, tc)
e := tEnv.DeployedEnvironment()
require.NotEmpty(t, e.Env.Chains)
tEnv.StartNodes(t, tc, deployment.CapabilityRegistryConfig{})
e = tEnv.DeployedEnvironment()
allChains := e.Env.AllChainSelectors()

mcmsCfg := make(map[uint64]commontypes.MCMSWithTimelockConfig)
for _, c := range e.Env.AllChainSelectors() {
mcmsCfg[c] = proposalutils.SingleGroupTimelockConfig(t)
}
var prereqCfg []DeployPrerequisiteConfigPerChain

Check failure on line 333 in deployment/ccip/changeset/test_environment.go

View workflow job for this annotation

GitHub Actions / GolangCI Lint (deployment)

Consider pre-allocating `prereqCfg` (prealloc)
for _, chain := range allChains {
var opts []PrerequisiteOpt
if tc != nil {
if tc.IsUSDC {
opts = append(opts, WithUSDCEnabled())
}
if tc.IsMultiCall3 {
opts = append(opts, WithMultiCall3Enabled())
}
}
opts = append(opts, WithLegacyDeploymentEnabled(LegacyDeploymentConfig{
PriceRegStalenessThreshold: 60 * 60 * 24 * 14, // two weeks
}))
prereqCfg = append(prereqCfg, DeployPrerequisiteConfigPerChain{
ChainSelector: chain,
Opts: opts,
})
}

e.Env, err = commonchangeset.ApplyChangesets(t, e.Env, nil, []commonchangeset.ChangesetApplication{
{
Changeset: commonchangeset.WrapChangeSet(commonchangeset.DeployLinkToken),
Config: allChains,
},
{
Changeset: commonchangeset.WrapChangeSet(DeployPrerequisites),
Config: DeployPrerequisiteConfig{
Configs: prereqCfg,
},
},
{
Changeset: commonchangeset.WrapChangeSet(commonchangeset.DeployMCMSWithTimelock),
Config: mcmsCfg,
},
})
require.NoError(t, err)
return e
}

func NewEnvironment(t *testing.T, tc *TestConfigs, tEnv TestEnvironment) DeployedEnv {
lggr := logger.Test(t)
tEnv.StartChains(t, tc)
Expand Down
7 changes: 6 additions & 1 deletion deployment/ccip/changeset/v1_5/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ import (
)

// This test only works if the destination chain id is 1337
// Otherwise it shows error for offchain and onchain config digest mismatch
func TestE2ELegacy(t *testing.T) {
e := NewMemoryEnvironment(t, changeset.WithChains(3), changeset.WithChainIds([]uint64{chainselectors.GETH_TESTNET.EvmChainID}))
e := changeset.NewMemoryEnvironment(
t,
changeset.WithLegacyDeployment(),
changeset.WithChains(3),
changeset.WithChainIds([]uint64{chainselectors.GETH_TESTNET.EvmChainID}))
state, err := changeset.LoadOnchainState(e.Env)
require.NoError(t, err)
allChains := e.Env.AllChainSelectorsExcluding([]uint64{chainselectors.GETH_TESTNET.Selector})
Expand Down
73 changes: 3 additions & 70 deletions deployment/ccip/changeset/v1_5/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
chain_selectors "github.com/smartcontractkit/chain-selectors"
"github.com/smartcontractkit/chainlink-common/pkg/config"
cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccip"
"github.com/smartcontractkit/libocr/offchainreporting2plus/confighelper"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink-common/pkg/config"
cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccip"

"github.com/smartcontractkit/chainlink/deployment"
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset"
commonchangeset "github.com/smartcontractkit/chainlink/deployment/common/changeset"
"github.com/smartcontractkit/chainlink/deployment/common/proposalutils"
commontypes "github.com/smartcontractkit/chainlink/deployment/common/types"
"github.com/smartcontractkit/chainlink/deployment/environment/memory"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/commit_store"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/evm_2_evm_offramp"
Expand All @@ -31,72 +30,6 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/testhelpers"
)

// NewMemoryEnvironment creates an in-memory environment based on the testconfig requested
// This environment currently only works when destination chain is 1337
// Otherwise it shows error for offchain and onchain config digest mismatch
func NewMemoryEnvironment(t *testing.T, opts ...changeset.TestOps) changeset.DeployedEnv {
testCfg := changeset.DefaultTestConfigs()
for _, opt := range opts {
opt(testCfg)
}
require.NoError(t, testCfg.Validate(), "invalid test config")
env := &changeset.MemoryEnvironment{}
return NewEnvironment(t, testCfg, env)
}

func NewEnvironment(t *testing.T, tc *changeset.TestConfigs, tEnv changeset.TestEnvironment) changeset.DeployedEnv {
var err error
tEnv.StartChains(t, tc)
e := tEnv.DeployedEnvironment()
require.NotEmpty(t, e.Env.Chains)
tEnv.StartNodes(t, tc, deployment.CapabilityRegistryConfig{})
e = tEnv.DeployedEnvironment()
allChains := e.Env.AllChainSelectors()

mcmsCfg := make(map[uint64]commontypes.MCMSWithTimelockConfig)
for _, c := range e.Env.AllChainSelectors() {
mcmsCfg[c] = proposalutils.SingleGroupTimelockConfig(t)
}
var prereqCfg []changeset.DeployPrerequisiteConfigPerChain
for _, chain := range allChains {
var opts []changeset.PrerequisiteOpt
if tc != nil {
if tc.IsUSDC {
opts = append(opts, changeset.WithUSDCEnabled())
}
if tc.IsMultiCall3 {
opts = append(opts, changeset.WithMultiCall3Enabled())
}
}
opts = append(opts, changeset.WithLegacyDeployment(changeset.LegacyDeploymentConfig{
PriceRegStalenessThreshold: 60 * 60 * 24 * 14, // two weeks
}))
prereqCfg = append(prereqCfg, changeset.DeployPrerequisiteConfigPerChain{
ChainSelector: chain,
Opts: opts,
})
}

e.Env, err = commonchangeset.ApplyChangesets(t, e.Env, nil, []commonchangeset.ChangesetApplication{
{
Changeset: commonchangeset.WrapChangeSet(commonchangeset.DeployLinkToken),
Config: allChains,
},
{
Changeset: commonchangeset.WrapChangeSet(changeset.DeployPrerequisites),
Config: changeset.DeployPrerequisiteConfig{
Configs: prereqCfg,
},
},
{
Changeset: commonchangeset.WrapChangeSet(commonchangeset.DeployMCMSWithTimelock),
Config: mcmsCfg,
},
})
require.NoError(t, err)
return e
}

func AddLanes(t *testing.T, e deployment.Environment, state changeset.CCIPOnChainState, pairs []changeset.SourceDestPair) deployment.Environment {
addLanesCfg, commitOCR2Configs, execOCR2Configs, jobspecs := LaneConfigsForChains(t, e, state, pairs)
var err error
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/smoke/ccip/ccip_legacy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

// This test does not run in CI, it is only written as an example of how to write a test for the legacy CCIP
func TestE2ELegacy(t *testing.T) {
e := testsetups.NewIntegrationLegacyEnvironment(t)
e, _ := testsetups.NewIntegrationEnvironment(t, changeset.WithLegacyDeployment())
state, err := changeset.LoadOnchainState(e.Env)
require.NoError(t, err)
allChains := e.Env.AllChainSelectors()
Expand Down
29 changes: 5 additions & 24 deletions integration-tests/testsetups/ccip/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (

"github.com/smartcontractkit/chainlink/deployment"
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset"
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset/v1_5"
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"
Expand Down Expand Up @@ -138,29 +137,6 @@ func (l *DeployedLocalDevEnvironment) RestartChainlinkNodes(t *testing.T) error
return errGrp.Wait()
}

func NewIntegrationLegacyEnvironment(t *testing.T, opts ...changeset.TestOps) changeset.DeployedEnv {
testCfg := changeset.DefaultTestConfigs()
for _, opt := range opts {
opt(testCfg)
}
// check for EnvType env var
testCfg.MustSetEnvTypeOrDefault(t)
require.NoError(t, testCfg.Validate(), "invalid test config")
switch testCfg.Type {
case changeset.Memory:
memEnv := v1_5.NewMemoryEnvironment(t, opts...)
return memEnv
case changeset.Docker:
dockerEnv := &DeployedLocalDevEnvironment{}
deployedEnv := v1_5.NewEnvironment(t, testCfg, dockerEnv)
require.NotNil(t, dockerEnv.testEnv, "empty docker environment")
return deployedEnv
default:
require.Failf(t, "Type %s not supported in integration tests choose between %s and %s", string(testCfg.Type), changeset.Memory, changeset.Docker)
}
return changeset.DeployedEnv{}
}

// NewIntegrationEnvironment creates a new integration test environment based on the provided test config
// It can create a memory environment or a docker environment based on env var CCIP_V16_TEST_ENV
// By default, it creates a memory environment if env var CCIP_V16_TEST_ENV is not set
Expand All @@ -181,6 +157,11 @@ func NewIntegrationEnvironment(t *testing.T, opts ...changeset.TestOps) (changes
return memEnv, devenv.RMNCluster{}
case changeset.Docker:
dockerEnv := &DeployedLocalDevEnvironment{}
if testCfg.LegacyDeployment {
deployedEnv := changeset.NewLegacyEnvironment(t, testCfg, dockerEnv)
require.NotNil(t, dockerEnv.testEnv, "empty docker environment")
return deployedEnv, devenv.RMNCluster{}
}
if testCfg.RMNEnabled {
deployedEnv := changeset.NewEnvironmentWithJobsAndContracts(t, testCfg, dockerEnv)
l := logging.GetTestLogger(t)
Expand Down

0 comments on commit cd17fe1

Please sign in to comment.