diff --git a/deployment/ccip/changeset/cs_prerequisites.go b/deployment/ccip/changeset/cs_prerequisites.go index 1d0339b48c7..94535df4a0f 100644 --- a/deployment/ccip/changeset/cs_prerequisites.go +++ b/deployment/ccip/changeset/cs_prerequisites.go @@ -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") diff --git a/deployment/ccip/changeset/test_environment.go b/deployment/ccip/changeset/test_environment.go index 813e3509ee0..f9ec4bed242 100644 --- a/deployment/ccip/changeset/test_environment.go +++ b/deployment/ccip/changeset/test_environment.go @@ -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 @@ -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 @@ -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) } @@ -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 + 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) diff --git a/deployment/ccip/changeset/v1_5/e2e_test.go b/deployment/ccip/changeset/v1_5/e2e_test.go index 4a12fb4d03f..11bb566c641 100644 --- a/deployment/ccip/changeset/v1_5/e2e_test.go +++ b/deployment/ccip/changeset/v1_5/e2e_test.go @@ -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}) diff --git a/deployment/ccip/changeset/v1_5/test_helpers.go b/deployment/ccip/changeset/v1_5/test_helpers.go index ff123cc40a7..e1a03539a77 100644 --- a/deployment/ccip/changeset/v1_5/test_helpers.go +++ b/deployment/ccip/changeset/v1_5/test_helpers.go @@ -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" @@ -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 diff --git a/integration-tests/smoke/ccip/ccip_legacy_test.go b/integration-tests/smoke/ccip/ccip_legacy_test.go index b18957dbeee..2b5b6d77b58 100644 --- a/integration-tests/smoke/ccip/ccip_legacy_test.go +++ b/integration-tests/smoke/ccip/ccip_legacy_test.go @@ -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() diff --git a/integration-tests/testsetups/ccip/test_helpers.go b/integration-tests/testsetups/ccip/test_helpers.go index d1aaca94027..6725ac1df9b 100644 --- a/integration-tests/testsetups/ccip/test_helpers.go +++ b/integration-tests/testsetups/ccip/test_helpers.go @@ -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" @@ -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 @@ -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)