Skip to content

Commit

Permalink
add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
AnieeG committed Dec 20, 2024
1 parent 7091d7e commit 9adf70f
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 7 deletions.
14 changes: 7 additions & 7 deletions deployment/ccip/changeset/cs_chain_contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ type NonceManagerUpdate struct {
type PreviousRampCfg struct {
RemoteChainSelector uint64
OverrideExisting bool
OnRamp bool
OffRamp bool
EnableOnRamp bool
EnableOffRamp bool
}

func (cfg UpdateNonceManagerConfig) Validate(e deployment.Environment) error {
Expand Down Expand Up @@ -85,17 +85,17 @@ func (cfg UpdateNonceManagerConfig) Validate(e deployment.Environment) error {
if _, ok := state.Chains[prevRamp.RemoteChainSelector]; !ok {
return fmt.Errorf("dest chain %d not found in onchain state for chain %d", prevRamp.RemoteChainSelector, sourceSel)
}
if !prevRamp.OnRamp && !prevRamp.OffRamp {
if !prevRamp.EnableOnRamp && !prevRamp.EnableOffRamp {
return errors.New("must specify either onramp or offramp")
}
if prevRamp.OnRamp {
if prevRamp.EnableOnRamp {
if prevOnRamp := state.Chains[sourceSel].EVM2EVMOnRamp; prevOnRamp == nil {
return fmt.Errorf("no previous onramp for source chain %d", sourceSel)
} else if prevOnRamp[prevRamp.RemoteChainSelector] == nil {
return fmt.Errorf("no previous onramp for source chain %d and dest chain %d", sourceSel, prevRamp.RemoteChainSelector)
}
}
if prevRamp.OffRamp {
if prevRamp.EnableOffRamp {
if prevOffRamp := state.Chains[sourceSel].EVM2EVMOffRamp; prevOffRamp == nil {
return fmt.Errorf("missing previous offramps for chain %d", sourceSel)
} else if prevOffRamp[prevRamp.RemoteChainSelector] == nil {
Expand Down Expand Up @@ -138,10 +138,10 @@ func UpdateNonceManagersCS(e deployment.Environment, cfg UpdateNonceManagerConfi
previousRampsArgs := make([]nonce_manager.NonceManagerPreviousRampsArgs, 0)
for _, prevRamp := range updates.PreviousRampsArgs {
var onRamp, offRamp common.Address
if prevRamp.OnRamp {
if prevRamp.EnableOnRamp {
onRamp = s.Chains[chainSel].EVM2EVMOnRamp[prevRamp.RemoteChainSelector].Address()
}
if prevRamp.OffRamp {
if prevRamp.EnableOffRamp {
offRamp = s.Chains[chainSel].EVM2EVMOffRamp[prevRamp.RemoteChainSelector].Address()
}
previousRampsArgs = append(previousRampsArgs, nonce_manager.NonceManagerPreviousRampsArgs{
Expand Down
58 changes: 58 additions & 0 deletions deployment/ccip/changeset/cs_chain_contracts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"golang.org/x/exp/maps"

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

commonchangeset "github.com/smartcontractkit/chainlink/deployment/common/changeset"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/fee_quoter"
)
Expand Down Expand Up @@ -303,3 +304,60 @@ func TestUpdateRouterRamps(t *testing.T) {
})
}
}

func TestUpdateNonceManagersCS(t *testing.T) {
for _, tc := range []struct {
name string
mcmsEnabled bool
}{
{
name: "MCMS enabled",
mcmsEnabled: true,
},
{
name: "MCMS disabled",
mcmsEnabled: false,
},
} {
t.Run(tc.name, func(t *testing.T) {
tenv := NewMemoryEnvironment(t)
state, err := LoadOnchainState(tenv.Env)
require.NoError(t, err)

allChains := maps.Keys(tenv.Env.Chains)
source := allChains[0]
dest := allChains[1]

if tc.mcmsEnabled {
// Transfer ownership to timelock so that we can promote the zero digest later down the line.
transferToTimelock(t, tenv, state, source, dest)
}

var mcmsConfig *MCMSConfig
if tc.mcmsEnabled {
mcmsConfig = &MCMSConfig{
MinDelay: 0,
}
}

_, err = commonchangeset.ApplyChangesets(t, tenv.Env, tenv.TimelockContracts(t), []commonchangeset.ChangesetApplication{
{
Changeset: commonchangeset.WrapChangeSet(UpdateNonceManagersCS),
Config: UpdateNonceManagerConfig{
UpdatesByChain: map[uint64]NonceManagerUpdate{
source: {
RemovedAuthCallers: []common.Address{state.Chains[source].OnRamp.Address()},
},
},
MCMS: mcmsConfig,
},
},
})
require.NoError(t, err)
// Assert the nonce manager configuration is as we expect.
callers, err := state.Chains[source].NonceManager.GetAllAuthorizedCallers(nil)
require.NoError(t, err)
require.NotContains(t, callers, state.Chains[source].OnRamp.Address())
})
}
}

0 comments on commit 9adf70f

Please sign in to comment.