Skip to content

Commit

Permalink
Ccip-4158 prereq Changeset (#15250)
Browse files Browse the repository at this point in the history
* changes

* changes

* add prerequisite changeset

* comments

* fix test

* more test fix

* go mod

* fix tests

* fix more tests

* fix

* optimize test run

* changes

* add parallel test

* review comments

* fixes

* another fix

* fix tests
  • Loading branch information
AnieeG authored Nov 15, 2024
1 parent bc41e65 commit 20b5655
Show file tree
Hide file tree
Showing 16 changed files with 769 additions and 357 deletions.
2 changes: 1 addition & 1 deletion .github/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ runner-test-matrix:
- PR E2E Core Tests
- Merge Queue E2E Core Tests
- Nightly E2E Tests
test_cmd: cd integration-tests/ && go test smoke/ccip_test.go -timeout 12m -test.parallel=1 -count=1 -json
test_cmd: cd integration-tests/ && go test smoke/ccip_test.go -timeout 12m -test.parallel=2 -count=1 -json
pyroscope_env: ci-smoke-ccipv1_6-evm-simulated
test_env_vars:
E2E_TEST_SELECTED_NETWORK: SIMULATED_1,SIMULATED_2
Expand Down
6 changes: 5 additions & 1 deletion deployment/ccip/add_lane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ func TestAddLane(t *testing.T) {

feeds := state.Chains[e.FeedChainSel].USDFeeds
tokenConfig := NewTestTokenConfig(feeds)
newAddresses := deployment.NewMemoryAddressBook()
err = DeployPrerequisiteChainContracts(e.Env, newAddresses, e.Env.AllChainSelectors())
require.NoError(t, err)
require.NoError(t, e.Env.ExistingAddresses.Merge(newAddresses))

// Set up CCIP contracts and a DON per chain.
newAddresses := deployment.NewMemoryAddressBook()
newAddresses = deployment.NewMemoryAddressBook()
err = DeployCCIPContracts(e.Env, newAddresses, DeployCCIPContractConfig{
HomeChainSel: e.HomeChainSel,
FeedChainSel: e.FeedChainSel,
Expand Down
21 changes: 13 additions & 8 deletions deployment/ccip/changeset/add_chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,13 @@ func TestAddChainInbound(t *testing.T) {
newChain := e.Env.AllChainSelectorsExcluding([]uint64{e.HomeChainSel})[0]
// We deploy to the rest.
initialDeploy := e.Env.AllChainSelectorsExcluding([]uint64{newChain})
newAddresses := deployment.NewMemoryAddressBook()
err = ccipdeployment.DeployPrerequisiteChainContracts(e.Env, newAddresses, initialDeploy)
require.NoError(t, err)
require.NoError(t, e.Env.ExistingAddresses.Merge(newAddresses))

tokenConfig := ccipdeployment.NewTestTokenConfig(state.Chains[e.FeedChainSel].USDFeeds)
newAddresses := deployment.NewMemoryAddressBook()
newAddresses = deployment.NewMemoryAddressBook()
err = ccipdeployment.DeployCCIPContracts(e.Env, newAddresses, ccipdeployment.DeployCCIPContractConfig{
HomeChainSel: e.HomeChainSel,
FeedChainSel: e.FeedChainSel,
Expand Down Expand Up @@ -68,15 +72,16 @@ func TestAddChainInbound(t *testing.T) {
require.NoError(t, err)

// Deploy contracts to new chain
newChainAddresses := deployment.NewMemoryAddressBook()
newAddresses = deployment.NewMemoryAddressBook()
err = ccipdeployment.DeployPrerequisiteChainContracts(e.Env, newAddresses, []uint64{newChain})
require.NoError(t, err)
require.NoError(t, e.Env.ExistingAddresses.Merge(newAddresses))
newAddresses = deployment.NewMemoryAddressBook()
err = ccipdeployment.DeployChainContracts(e.Env,
e.Env.Chains[newChain], newChainAddresses,
ccipdeployment.FeeTokenContracts{
LinkToken: state.Chains[newChain].LinkToken,
Weth9: state.Chains[newChain].Weth9,
}, ccipdeployment.NewTestMCMSConfig(t, e.Env), rmnHome)
e.Env.Chains[newChain], newAddresses,
ccipdeployment.NewTestMCMSConfig(t, e.Env), rmnHome)
require.NoError(t, err)
require.NoError(t, e.Env.ExistingAddresses.Merge(newChainAddresses))
require.NoError(t, e.Env.ExistingAddresses.Merge(newAddresses))
state, err = ccipdeployment.LoadOnchainState(e.Env)
require.NoError(t, err)

Expand Down
1 change: 0 additions & 1 deletion deployment/ccip/changeset/home_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ var _ deployment.ChangeSet[DeployHomeChainConfig] = DeployHomeChain

// DeployHomeChain is a separate changeset because it is a standalone deployment performed once in home chain for the entire CCIP deployment.
func DeployHomeChain(env deployment.Environment, cfg DeployHomeChainConfig) (deployment.ChangesetOutput, error) {

err := cfg.Validate()
if err != nil {
return deployment.ChangesetOutput{}, errors.Wrapf(deployment.ErrInvalidConfig, "%v", err)
Expand Down
16 changes: 10 additions & 6 deletions deployment/ccip/changeset/initial_deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"testing"

"github.com/ethereum/go-ethereum/common"
"github.com/smartcontractkit/chainlink/deployment"

ccdeploy "github.com/smartcontractkit/chainlink/deployment/ccip"

jobv1 "github.com/smartcontractkit/chainlink-protos/job-distributor/v1/job"

"github.com/smartcontractkit/chainlink/deployment"
ccdeploy "github.com/smartcontractkit/chainlink/deployment/ccip"

"github.com/smartcontractkit/chainlink-testing-framework/lib/utils/testcontext"

"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/router"
Expand All @@ -26,9 +26,13 @@ func TestInitialDeploy(t *testing.T) {

state, err := ccdeploy.LoadOnchainState(tenv.Env)
require.NoError(t, err)
require.NotNil(t, state.Chains[tenv.HomeChainSel].LinkToken)
output, err := DeployPrerequisites(e, DeployPrerequisiteConfig{
ChainSelectors: tenv.Env.AllChainSelectors(),
})
require.NoError(t, err)
require.NoError(t, tenv.Env.ExistingAddresses.Merge(output.AddressBook))

output, err := InitialDeploy(tenv.Env, ccdeploy.DeployCCIPContractConfig{
output, err = InitialDeploy(tenv.Env, ccdeploy.DeployCCIPContractConfig{
HomeChainSel: tenv.HomeChainSel,
FeedChainSel: tenv.FeedChainSel,
ChainsToDeploy: tenv.Env.AllChainSelectors(),
Expand All @@ -41,7 +45,7 @@ func TestInitialDeploy(t *testing.T) {
require.NoError(t, tenv.Env.ExistingAddresses.Merge(output.AddressBook))
state, err = ccdeploy.LoadOnchainState(e)
require.NoError(t, err)

require.NotNil(t, state.Chains[tenv.HomeChainSel].LinkToken)
// Ensure capreg logs are up to date.
ccdeploy.ReplayLogs(t, e.Offchain, tenv.ReplayBlocks)

Expand Down
58 changes: 58 additions & 0 deletions deployment/ccip/changeset/prerequisites.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package changeset

import (
"fmt"

"github.com/ethereum/go-ethereum/common"
"github.com/pkg/errors"
"github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/timelock"
chain_selectors "github.com/smartcontractkit/chain-selectors"

"github.com/smartcontractkit/chainlink/deployment"
ccipdeployment "github.com/smartcontractkit/chainlink/deployment/ccip"
)

var (
_ deployment.ChangeSet[DeployPrerequisiteConfig] = DeployPrerequisites
)

// DeployPrerequisites deploys the pre-requisite contracts for CCIP
// pre-requisite contracts are the contracts which can be reused from previous versions of CCIP
func DeployPrerequisites(env deployment.Environment, cfg DeployPrerequisiteConfig) (deployment.ChangesetOutput, error) {
err := cfg.Validate()
if err != nil {
return deployment.ChangesetOutput{}, errors.Wrapf(deployment.ErrInvalidConfig, "%v", err)
}
ab := deployment.NewMemoryAddressBook()
err = ccipdeployment.DeployPrerequisiteChainContracts(env, ab, cfg.ChainSelectors)
if err != nil {
env.Logger.Errorw("Failed to deploy prerequisite contracts", "err", err, "addressBook", ab)
return deployment.ChangesetOutput{}, fmt.Errorf("failed to deploy prerequisite contracts: %w", err)
}
return deployment.ChangesetOutput{
Proposals: []timelock.MCMSWithTimelockProposal{},
AddressBook: ab,
JobSpecs: nil,
}, nil
}

type DeployPrerequisiteConfig struct {
ChainSelectors []uint64
// TODO handle tokens and feeds in prerequisite config
Tokens map[ccipdeployment.TokenSymbol]common.Address
Feeds map[ccipdeployment.TokenSymbol]common.Address
}

func (c DeployPrerequisiteConfig) Validate() error {
for _, cs := range c.ChainSelectors {
if cs == 0 {
return fmt.Errorf("chain selector must be set")
}
_, err := chain_selectors.ChainIdFromSelector(cs)
if err != nil {
return fmt.Errorf("invalid chain selector: %d - %w", cs, err)
}

}
return nil
}
37 changes: 37 additions & 0 deletions deployment/ccip/changeset/prerequisites_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package changeset

import (
"testing"

"github.com/stretchr/testify/require"
"go.uber.org/zap/zapcore"

ccipdeployment "github.com/smartcontractkit/chainlink/deployment/ccip"
"github.com/smartcontractkit/chainlink/deployment/environment/memory"
"github.com/smartcontractkit/chainlink/v2/core/logger"
)

func TestDeployPrerequisites(t *testing.T) {
t.Parallel()
lggr := logger.TestLogger(t)
e := memory.NewMemoryEnvironment(t, lggr, zapcore.InfoLevel, memory.MemoryEnvironmentConfig{
Bootstraps: 1,
Chains: 2,
Nodes: 4,
})
newChain := e.AllChainSelectors()[0]
cfg := DeployPrerequisiteConfig{
ChainSelectors: []uint64{newChain},
}
output, err := DeployPrerequisites(e, cfg)
require.NoError(t, err)
err = e.ExistingAddresses.Merge(output.AddressBook)
require.NoError(t, err)
state, err := ccipdeployment.LoadOnchainState(e)
require.NoError(t, err)
require.NotNil(t, state.Chains[newChain].LinkToken)
require.NotNil(t, state.Chains[newChain].Weth9)
require.NotNil(t, state.Chains[newChain].TokenAdminRegistry)
require.NotNil(t, state.Chains[newChain].RegistryModule)
require.NotNil(t, state.Chains[newChain].Router)
}
68 changes: 68 additions & 0 deletions deployment/ccip/changeset/save_existing.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package changeset

import (
"fmt"

"github.com/ethereum/go-ethereum/common"
"github.com/pkg/errors"
"github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/timelock"
chain_selectors "github.com/smartcontractkit/chain-selectors"

"github.com/smartcontractkit/chainlink/deployment"
)

var (
_ deployment.ChangeSet[ExistingContractsConfig] = SaveExistingContracts
)

type Contract struct {
Address common.Address
TypeAndVersion deployment.TypeAndVersion
ChainSelector uint64
}

type ExistingContractsConfig struct {
ExistingContracts []Contract
}

func (cfg ExistingContractsConfig) Validate() error {
for _, ec := range cfg.ExistingContracts {
if ec.ChainSelector == 0 {
return fmt.Errorf("chain selectors must be set")
}
_, err := chain_selectors.ChainIdFromSelector(ec.ChainSelector)
if err != nil {
return fmt.Errorf("invalid chain selector: %d - %w", ec.ChainSelector, err)
}
if ec.Address == (common.Address{}) {
return fmt.Errorf("address must be set")
}
if ec.TypeAndVersion.Type == "" {
return fmt.Errorf("type must be set")
}
if val, err := ec.TypeAndVersion.Version.Value(); err != nil || val == "" {
return fmt.Errorf("version must be set")
}
}
return nil
}

func SaveExistingContracts(env deployment.Environment, cfg ExistingContractsConfig) (deployment.ChangesetOutput, error) {
err := cfg.Validate()
if err != nil {
return deployment.ChangesetOutput{}, errors.Wrapf(deployment.ErrInvalidConfig, "%v", err)
}
ab := deployment.NewMemoryAddressBook()
for _, ec := range cfg.ExistingContracts {
err = ab.Save(ec.ChainSelector, ec.Address.String(), ec.TypeAndVersion)
if err != nil {
env.Logger.Errorw("Failed to save existing contract", "err", err, "addressBook", ab)
return deployment.ChangesetOutput{}, fmt.Errorf("failed to save existing contract: %w", err)
}
}
return deployment.ChangesetOutput{
Proposals: []timelock.MCMSWithTimelockProposal{},
AddressBook: ab,
JobSpecs: nil,
}, nil
}
69 changes: 69 additions & 0 deletions deployment/ccip/changeset/save_existing_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package changeset

import (
"math/big"
"testing"

"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zapcore"

"github.com/smartcontractkit/chainlink/deployment"
ccipdeployment "github.com/smartcontractkit/chainlink/deployment/ccip"
"github.com/smartcontractkit/chainlink/deployment/environment/memory"
"github.com/smartcontractkit/chainlink/v2/core/logger"
)

func TestSaveExisting(t *testing.T) {
t.Parallel()
lggr := logger.TestLogger(t)
e := memory.NewMemoryEnvironment(t, lggr, zapcore.InfoLevel, memory.MemoryEnvironmentConfig{
Bootstraps: 1,
Chains: 2,
Nodes: 4,
})
chains := e.AllChainSelectors()
chain1 := chains[0]
chain2 := chains[1]
cfg := ExistingContractsConfig{
ExistingContracts: []Contract{
{
Address: common.BigToAddress(big.NewInt(1)),
TypeAndVersion: deployment.NewTypeAndVersion(ccipdeployment.LinkToken, deployment.Version1_0_0),
ChainSelector: chain1,
},
{
Address: common.BigToAddress(big.NewInt(2)),
TypeAndVersion: deployment.NewTypeAndVersion(ccipdeployment.WETH9, deployment.Version1_0_0),
ChainSelector: chain1,
},
{
Address: common.BigToAddress(big.NewInt(3)),
TypeAndVersion: deployment.NewTypeAndVersion(ccipdeployment.TokenAdminRegistry, deployment.Version1_5_0),
ChainSelector: chain1,
},
{
Address: common.BigToAddress(big.NewInt(4)),
TypeAndVersion: deployment.NewTypeAndVersion(ccipdeployment.RegistryModule, deployment.Version1_5_0),
ChainSelector: chain2,
},
{
Address: common.BigToAddress(big.NewInt(5)),
TypeAndVersion: deployment.NewTypeAndVersion(ccipdeployment.Router, deployment.Version1_2_0),
ChainSelector: chain2,
},
},
}

output, err := SaveExistingContracts(e, cfg)
require.NoError(t, err)
err = e.ExistingAddresses.Merge(output.AddressBook)
require.NoError(t, err)
state, err := ccipdeployment.LoadOnchainState(e)
require.NoError(t, err)
require.Equal(t, state.Chains[chain1].LinkToken.Address(), common.BigToAddress(big.NewInt(1)))
require.Equal(t, state.Chains[chain1].Weth9.Address(), common.BigToAddress(big.NewInt(2)))
require.Equal(t, state.Chains[chain1].TokenAdminRegistry.Address(), common.BigToAddress(big.NewInt(3)))
require.Equal(t, state.Chains[chain2].RegistryModule.Address(), common.BigToAddress(big.NewInt(4)))
require.Equal(t, state.Chains[chain2].Router.Address(), common.BigToAddress(big.NewInt(5)))
}
Loading

0 comments on commit 20b5655

Please sign in to comment.