Skip to content

Commit

Permalink
Improvement in naming changesets (#15943)
Browse files Browse the repository at this point in the history
* remove deployCCIPContracts

* deprecate existing add lane

* making OCR input more user friendly

* rename changesets

* fix lint errors

* fix

* further rename

* populate addresses from state for 1.5

* move test related methods to test package

* updates

* more fix

* create new package for test

* another move

* more fixes

* fix lint

* fix file path

* fix file path

* go mod tidy

* review comments
  • Loading branch information
AnieeG authored Jan 16, 2025
1 parent 47a0c42 commit ac3a55f
Show file tree
Hide file tree
Showing 56 changed files with 1,404 additions and 1,278 deletions.
6 changes: 3 additions & 3 deletions .github/integration-in-memory-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ runner-test-matrix:
- PR Integration CCIP Tests
test_cmd: cd integration-tests/smoke/ccip && go test ccip_batching_test.go -timeout 12m -test.parallel=2 -count=1 -json

- id: contracts/ccipreader_test.go:*
path: integration-tests/contracts/ccipreader_test.go
- id: smoke/ccip/ccip_reader_test.go:*
path: integration-tests/smoke/ccip/ccip_reader_test.go
test_env_type: in-memory
runs_on: ubuntu-latest
triggers:
- PR Integration CCIP Tests
test_cmd: cd integration-tests/contracts && go test ccipreader_test.go -timeout 5m -test.parallel=1 -count=1 -json
test_cmd: cd integration-tests/smoke/ccip && go test ccip_reader_test.go -timeout 5m -test.parallel=1 -count=1 -json

- id: smoke/ccip/ccip_usdc_test.go:*
path: integration-tests/smoke/ccip/ccip_usdc_test.go
Expand Down
90 changes: 8 additions & 82 deletions deployment/ccip/changeset/accept_ownership_test.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package changeset
package changeset_test

import (
"testing"

"github.com/ethereum/go-ethereum/common"

"github.com/stretchr/testify/require"
"golang.org/x/exp/maps"

"github.com/smartcontractkit/chainlink/deployment/ccip/changeset"
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset/testhelpers"
commonchangeset "github.com/smartcontractkit/chainlink/deployment/common/changeset"
"github.com/smartcontractkit/chainlink/deployment/common/proposalutils"
)

func Test_NewAcceptOwnershipChangeset(t *testing.T) {
t.Parallel()
e, _ := NewMemoryEnvironment(t)
state, err := LoadOnchainState(e.Env)
e, _ := testhelpers.NewMemoryEnvironment(t)
state, err := changeset.LoadOnchainState(e.Env)
require.NoError(t, err)

allChains := maps.Keys(e.Env.Chains)
Expand All @@ -35,92 +35,18 @@ func Test_NewAcceptOwnershipChangeset(t *testing.T) {

// at this point we have the initial deploys done, now we need to transfer ownership
// to the timelock contract
state, err = LoadOnchainState(e.Env)
state, err = changeset.LoadOnchainState(e.Env)
require.NoError(t, err)

// compose the transfer ownership and accept ownership changesets
_, err = commonchangeset.ApplyChangesets(t, e.Env, timelockContracts, []commonchangeset.ChangesetApplication{
// note this doesn't have proposals.
{
Changeset: commonchangeset.WrapChangeSet(commonchangeset.TransferToMCMSWithTimelock),
Config: genTestTransferOwnershipConfig(e, allChains, state),
Config: testhelpers.GenTestTransferOwnershipConfig(e, allChains, state),
},
})
require.NoError(t, err)

assertTimelockOwnership(t, e, allChains, state)
}

func genTestTransferOwnershipConfig(
e DeployedEnv,
chains []uint64,
state CCIPOnChainState,
) commonchangeset.TransferToMCMSWithTimelockConfig {
var (
timelocksPerChain = make(map[uint64]common.Address)
contracts = make(map[uint64][]common.Address)
)

// chain contracts
for _, chain := range chains {
timelocksPerChain[chain] = state.Chains[chain].Timelock.Address()
contracts[chain] = []common.Address{
state.Chains[chain].OnRamp.Address(),
state.Chains[chain].OffRamp.Address(),
state.Chains[chain].FeeQuoter.Address(),
state.Chains[chain].NonceManager.Address(),
state.Chains[chain].RMNRemote.Address(),
state.Chains[chain].TestRouter.Address(),
state.Chains[chain].Router.Address(),
}
}

// home chain
homeChainTimelockAddress := state.Chains[e.HomeChainSel].Timelock.Address()
timelocksPerChain[e.HomeChainSel] = homeChainTimelockAddress
contracts[e.HomeChainSel] = append(contracts[e.HomeChainSel],
state.Chains[e.HomeChainSel].CapabilityRegistry.Address(),
state.Chains[e.HomeChainSel].CCIPHome.Address(),
state.Chains[e.HomeChainSel].RMNHome.Address(),
)

return commonchangeset.TransferToMCMSWithTimelockConfig{
ContractsByChain: contracts,
}
}

// assertTimelockOwnership asserts that the ownership of the contracts has been transferred
// to the appropriate timelock contract on each chain.
func assertTimelockOwnership(
t *testing.T,
e DeployedEnv,
chains []uint64,
state CCIPOnChainState,
) {
// check that the ownership has been transferred correctly
for _, chain := range chains {
for _, contract := range []common.Address{
state.Chains[chain].OnRamp.Address(),
state.Chains[chain].OffRamp.Address(),
state.Chains[chain].FeeQuoter.Address(),
state.Chains[chain].NonceManager.Address(),
state.Chains[chain].RMNRemote.Address(),
} {
owner, _, err := commonchangeset.LoadOwnableContract(contract, e.Env.Chains[chain].Client)
require.NoError(t, err)
require.Equal(t, state.Chains[chain].Timelock.Address(), owner)
}
}

// check home chain contracts ownership
homeChainTimelockAddress := state.Chains[e.HomeChainSel].Timelock.Address()
for _, contract := range []common.Address{
state.Chains[e.HomeChainSel].CapabilityRegistry.Address(),
state.Chains[e.HomeChainSel].CCIPHome.Address(),
state.Chains[e.HomeChainSel].RMNHome.Address(),
} {
owner, _, err := commonchangeset.LoadOwnableContract(contract, e.Env.Chains[e.HomeChainSel].Client)
require.NoError(t, err)
require.Equal(t, homeChainTimelockAddress, owner)
}
testhelpers.AssertTimelockOwnership(t, e, allChains, state)
}
86 changes: 46 additions & 40 deletions deployment/ccip/changeset/cs_active_candidate_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package changeset
package changeset_test

import (
"math/big"
Expand All @@ -10,7 +10,9 @@ import (

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

"github.com/smartcontractkit/chainlink/deployment/ccip/changeset"
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset/internal"
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset/testhelpers"
commonchangeset "github.com/smartcontractkit/chainlink/deployment/common/changeset"

"github.com/stretchr/testify/require"
Expand All @@ -26,10 +28,10 @@ func Test_ActiveCandidate(t *testing.T) {
// We want to have the active instance execute a few messages
// and then setup a candidate instance. The candidate instance
// should not be able to transmit anything until we make it active.
tenv, _ := NewMemoryEnvironment(t,
WithChains(2),
WithNodes(4))
state, err := LoadOnchainState(tenv.Env)
tenv, _ := testhelpers.NewMemoryEnvironment(t,
testhelpers.WithNumOfChains(2),
testhelpers.WithNumOfNodes(4))
state, err := changeset.LoadOnchainState(tenv.Env)
require.NoError(t, err)

// Deploy to all chains.
Expand All @@ -41,9 +43,9 @@ func Test_ActiveCandidate(t *testing.T) {
sourceState := state.Chains[source]
tenv.Env, err = commonchangeset.ApplyChangesets(t, tenv.Env, tenv.TimelockContracts(t), []commonchangeset.ChangesetApplication{
{
Changeset: commonchangeset.WrapChangeSet(UpdateOnRampsDests),
Config: UpdateOnRampDestsConfig{
UpdatesByChain: map[uint64]map[uint64]OnRampDestinationUpdate{
Changeset: commonchangeset.WrapChangeSet(changeset.UpdateOnRampsDestsChangeset),
Config: changeset.UpdateOnRampDestsConfig{
UpdatesByChain: map[uint64]map[uint64]changeset.OnRampDestinationUpdate{
source: {
dest: {
IsEnabled: true,
Expand All @@ -54,35 +56,35 @@ func Test_ActiveCandidate(t *testing.T) {
},
},
{
Changeset: commonchangeset.WrapChangeSet(UpdateFeeQuoterPricesCS),
Config: UpdateFeeQuoterPricesConfig{
PricesByChain: map[uint64]FeeQuoterPriceUpdatePerSource{
Changeset: commonchangeset.WrapChangeSet(changeset.UpdateFeeQuoterPricesChangeset),
Config: changeset.UpdateFeeQuoterPricesConfig{
PricesByChain: map[uint64]changeset.FeeQuoterPriceUpdatePerSource{
source: {
TokenPrices: map[common.Address]*big.Int{
sourceState.LinkToken.Address(): DefaultLinkPrice,
sourceState.Weth9.Address(): DefaultWethPrice,
sourceState.LinkToken.Address(): testhelpers.DefaultLinkPrice,
sourceState.Weth9.Address(): testhelpers.DefaultWethPrice,
},
GasPrices: map[uint64]*big.Int{
dest: DefaultGasPrice,
dest: testhelpers.DefaultGasPrice,
},
},
},
},
},
{
Changeset: commonchangeset.WrapChangeSet(UpdateFeeQuoterDests),
Config: UpdateFeeQuoterDestsConfig{
Changeset: commonchangeset.WrapChangeSet(changeset.UpdateFeeQuoterDestsChangeset),
Config: changeset.UpdateFeeQuoterDestsConfig{
UpdatesByChain: map[uint64]map[uint64]fee_quoter.FeeQuoterDestChainConfig{
source: {
dest: DefaultFeeQuoterDestChainConfig(),
dest: changeset.DefaultFeeQuoterDestChainConfig(),
},
},
},
},
{
Changeset: commonchangeset.WrapChangeSet(UpdateOffRampSources),
Config: UpdateOffRampSourcesConfig{
UpdatesByChain: map[uint64]map[uint64]OffRampSourceUpdate{
Changeset: commonchangeset.WrapChangeSet(changeset.UpdateOffRampSourcesChangeset),
Config: changeset.UpdateOffRampSourcesConfig{
UpdatesByChain: map[uint64]map[uint64]changeset.OffRampSourceUpdate{
dest: {
source: {
IsEnabled: true,
Expand All @@ -92,9 +94,9 @@ func Test_ActiveCandidate(t *testing.T) {
},
},
{
Changeset: commonchangeset.WrapChangeSet(UpdateRouterRamps),
Config: UpdateRouterRampsConfig{
UpdatesByChain: map[uint64]RouterUpdates{
Changeset: commonchangeset.WrapChangeSet(changeset.UpdateRouterRampsChangeset),
Config: changeset.UpdateRouterRampsConfig{
UpdatesByChain: map[uint64]changeset.RouterUpdates{
// onRamp update on source chain
source: {
OnRampUpdates: map[uint64]bool{
Expand Down Expand Up @@ -125,17 +127,17 @@ func Test_ActiveCandidate(t *testing.T) {
_, err = commonchangeset.ApplyChangesets(t, tenv.Env, tenv.TimelockContracts(t), []commonchangeset.ChangesetApplication{
{
Changeset: commonchangeset.WrapChangeSet(commonchangeset.TransferToMCMSWithTimelock),
Config: genTestTransferOwnershipConfig(tenv, allChains, state),
Config: testhelpers.GenTestTransferOwnershipConfig(tenv, allChains, state),
},
})
require.NoError(t, err)
assertTimelockOwnership(t, tenv, allChains, state)
testhelpers.AssertTimelockOwnership(t, tenv, allChains, state)

sendMsg := func() {
latesthdr, err := tenv.Env.Chains[dest].Client.HeaderByNumber(testcontext.Get(t), nil)
require.NoError(t, err)
block := latesthdr.Number.Uint64()
msgSentEvent := TestSendRequest(t, tenv.Env, state, source, dest, false, router.ClientEVM2AnyMessage{
msgSentEvent := testhelpers.TestSendRequest(t, tenv.Env, state, source, dest, false, router.ClientEVM2AnyMessage{
Receiver: common.LeftPadBytes(state.Chains[dest].Receiver.Address().Bytes(), 32),
Data: []byte("hello world"),
TokenAmounts: nil,
Expand All @@ -147,13 +149,13 @@ func Test_ActiveCandidate(t *testing.T) {
startBlocks = map[uint64]*uint64{
dest: &block,
}
expectedSeqNum = map[SourceDestPair]uint64{
expectedSeqNum = map[testhelpers.SourceDestPair]uint64{
{
SourceChainSelector: source,
DestChainSelector: dest,
}: msgSentEvent.SequenceNumber,
}
expectedSeqNumExec = map[SourceDestPair][]uint64{
expectedSeqNumExec = map[testhelpers.SourceDestPair][]uint64{
{
SourceChainSelector: source,
DestChainSelector: dest,
Expand All @@ -162,8 +164,8 @@ func Test_ActiveCandidate(t *testing.T) {
)

// Confirm execution of the message
ConfirmCommitForAllWithExpectedSeqNums(t, tenv.Env, state, expectedSeqNum, startBlocks)
ConfirmExecWithSeqNrsForAll(t, tenv.Env, state, expectedSeqNumExec, startBlocks)
testhelpers.ConfirmCommitForAllWithExpectedSeqNums(t, tenv.Env, state, expectedSeqNum, startBlocks)
testhelpers.ConfirmExecWithSeqNrsForAll(t, tenv.Env, state, expectedSeqNumExec, startBlocks)
}

// send a message from source to dest and ensure that it gets executed
Expand All @@ -188,30 +190,34 @@ func Test_ActiveCandidate(t *testing.T) {

// Now we can add a candidate config, send another request, and observe behavior.
// The candidate config should not be able to execute messages.
tokenConfig := NewTestTokenConfig(state.Chains[tenv.FeedChainSel].USDFeeds)
tokenConfig := changeset.NewTestTokenConfig(state.Chains[tenv.FeedChainSel].USDFeeds)
_, err = commonchangeset.ApplyChangesets(t, tenv.Env, tenv.TimelockContracts(t), []commonchangeset.ChangesetApplication{
{
Changeset: commonchangeset.WrapChangeSet(SetCandidateChangeset),
Config: SetCandidateChangesetConfig{
SetCandidateConfigBase: SetCandidateConfigBase{
Changeset: commonchangeset.WrapChangeSet(changeset.SetCandidateChangeset),
Config: changeset.SetCandidateChangesetConfig{
SetCandidateConfigBase: changeset.SetCandidateConfigBase{
HomeChainSelector: tenv.HomeChainSel,
FeedChainSelector: tenv.FeedChainSel,
MCMS: &MCMSConfig{
MCMS: &changeset.MCMSConfig{
MinDelay: 0,
},
},
PluginInfo: []SetCandidatePluginInfo{
PluginInfo: []changeset.SetCandidatePluginInfo{
{
// NOTE: this is technically not a new chain, but needed for validation.
OCRConfigPerRemoteChainSelector: map[uint64]CCIPOCRParams{
dest: DefaultOCRParams(tenv.FeedChainSel, tokenConfig.GetTokenInfo(logger.TestLogger(t), state.Chains[dest].LinkToken, state.Chains[dest].Weth9), nil, true, false),
OCRConfigPerRemoteChainSelector: map[uint64]changeset.CCIPOCRParams{
dest: changeset.DeriveCCIPOCRParams(
changeset.WithDefaultCommitOffChainConfig(tenv.FeedChainSel, tokenConfig.GetTokenInfo(logger.TestLogger(t), state.Chains[dest].LinkToken, state.Chains[dest].Weth9)),
),
},
PluginType: types.PluginTypeCCIPCommit,
},
{
// NOTE: this is technically not a new chain, but needed for validation.
OCRConfigPerRemoteChainSelector: map[uint64]CCIPOCRParams{
dest: DefaultOCRParams(tenv.FeedChainSel, tokenConfig.GetTokenInfo(logger.TestLogger(t), state.Chains[dest].LinkToken, state.Chains[dest].Weth9), nil, false, true),
OCRConfigPerRemoteChainSelector: map[uint64]changeset.CCIPOCRParams{
dest: changeset.DeriveCCIPOCRParams(
changeset.WithDefaultExecuteOffChainConfig(nil),
),
},
PluginType: types.PluginTypeCCIPExec,
},
Expand Down
18 changes: 10 additions & 8 deletions deployment/ccip/changeset/cs_add_lane_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package changeset
package changeset_test

import (
"testing"
Expand All @@ -8,37 +8,39 @@ import (

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

"github.com/smartcontractkit/chainlink/deployment/ccip/changeset"
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset/testhelpers"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/router"
)

func TestAddLanesWithTestRouter(t *testing.T) {
t.Parallel()
e, _ := NewMemoryEnvironment(t)
e, _ := testhelpers.NewMemoryEnvironment(t)
// Here we have CR + nodes set up, but no CCIP contracts deployed.
state, err := LoadOnchainState(e.Env)
state, err := changeset.LoadOnchainState(e.Env)
require.NoError(t, err)

selectors := e.Env.AllChainSelectors()
chain1, chain2 := selectors[0], selectors[1]
AddLaneWithDefaultPricesAndFeeQuoterConfig(t, &e, state, chain1, chain2, true)
testhelpers.AddLaneWithDefaultPricesAndFeeQuoterConfig(t, &e, state, chain1, chain2, true)
// Need to keep track of the block number for each chain so that event subscription can be done from that block.
startBlocks := make(map[uint64]*uint64)
// Send a message from each chain to every other chain.
expectedSeqNumExec := make(map[SourceDestPair][]uint64)
expectedSeqNumExec := make(map[testhelpers.SourceDestPair][]uint64)
latesthdr, err := e.Env.Chains[chain2].Client.HeaderByNumber(testcontext.Get(t), nil)
require.NoError(t, err)
block := latesthdr.Number.Uint64()
startBlocks[chain2] = &block
msgSentEvent := TestSendRequest(t, e.Env, state, chain1, chain2, true, router.ClientEVM2AnyMessage{
msgSentEvent := testhelpers.TestSendRequest(t, e.Env, state, chain1, chain2, true, router.ClientEVM2AnyMessage{
Receiver: common.LeftPadBytes(state.Chains[chain2].Receiver.Address().Bytes(), 32),
Data: []byte("hello"),
TokenAmounts: nil,
FeeToken: common.HexToAddress("0x0"),
ExtraArgs: nil,
})
expectedSeqNumExec[SourceDestPair{
expectedSeqNumExec[testhelpers.SourceDestPair{
SourceChainSelector: chain1,
DestChainSelector: chain2,
}] = []uint64{msgSentEvent.SequenceNumber}
ConfirmExecWithSeqNrsForAll(t, e.Env, state, expectedSeqNumExec, startBlocks)
testhelpers.ConfirmExecWithSeqNrsForAll(t, e.Env, state, expectedSeqNumExec, startBlocks)
}
Loading

0 comments on commit ac3a55f

Please sign in to comment.