Skip to content

Commit

Permalink
pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
makramkd committed Dec 11, 2024
1 parent e5f856b commit 88af68e
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ type PromoteAllCandidatesChangesetConfig struct {
}

func (p PromoteAllCandidatesChangesetConfig) Validate(e deployment.Environment, state CCIPOnChainState) (deployment.Nodes, error) {
if p.HomeChainSelector == 0 {
return nil, fmt.Errorf("HomeChainSelector must be set")
if err := deployment.IsValidChainSelector(p.HomeChainSelector); err != nil {
return nil, fmt.Errorf("home chain selector invalid: %w", err)
}
if p.DONChainSelector == 0 {
return nil, fmt.Errorf("DONChainSelector must be set")
if err := deployment.IsValidChainSelector(p.DONChainSelector); err != nil {
return nil, fmt.Errorf("don chain selector invalid: %w", err)
}
if len(p.NodeIDs) == 0 {
return nil, fmt.Errorf("NodeIDs must be set")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package changeset
import (
"testing"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/smartcontractkit/ccip-owner-contracts/pkg/gethwrappers"
"github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/mcms"
Expand All @@ -12,6 +13,7 @@ import (
"github.com/smartcontractkit/chainlink-testing-framework/lib/utils/testcontext"

"github.com/smartcontractkit/chainlink/deployment/ccip/changeset/internal"
"github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/types"
cctypes "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/types"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/router"

Expand Down Expand Up @@ -258,3 +260,121 @@ func TestActiveCandidate(t *testing.T) {
require.NoError(t, err)
// [NEW ACTIVE, NO CANDIDATE] done sending successful request
}

func Test_PromoteCandidate(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) {
ctx := testcontext.Get(t)
tenv := NewMemoryEnvironment(t,
WithChains(2),
WithNodes(4))
state, err := LoadOnchainState(tenv.Env)
require.NoError(t, err)

// Deploy to all chains.
allChains := maps.Keys(tenv.Env.Chains)
source := allChains[0]
dest := allChains[1]

nodes, err := deployment.NodeInfo(tenv.Env.NodeIDs, tenv.Env.Offchain)
require.NoError(t, err)

var nodeIDs []string
for _, node := range nodes {
nodeIDs = append(nodeIDs, node.NodeID)
}

if tc.mcmsEnabled {
// Transfer ownership to timelock so that we can promote the zero digest later down the line.
_, err = commonchangeset.ApplyChangesets(t, tenv.Env, map[uint64]*commonchangeset.TimelockExecutionContracts{
source: {
Timelock: state.Chains[source].Timelock,
CallProxy: state.Chains[source].CallProxy,
},
dest: {
Timelock: state.Chains[dest].Timelock,
CallProxy: state.Chains[dest].CallProxy,
},
tenv.HomeChainSel: {
Timelock: state.Chains[tenv.HomeChainSel].Timelock,
CallProxy: state.Chains[tenv.HomeChainSel].CallProxy,
},
}, []commonchangeset.ChangesetApplication{
{
Changeset: commonchangeset.WrapChangeSet(commonchangeset.TransferToMCMSWithTimelock),
Config: genTestTransferOwnershipConfig(tenv, allChains, state),
},
})
require.NoError(t, err)
assertTimelockOwnership(t, tenv, allChains, state)
}

var (
capReg = state.Chains[tenv.HomeChainSel].CapabilityRegistry
ccipHome = state.Chains[tenv.HomeChainSel].CCIPHome
)
donID, err := internal.DonIDForChain(capReg, ccipHome, dest)
require.NoError(t, err)
require.NotEqual(t, uint32(0), donID)
candidateDigestCommitBefore, err := ccipHome.GetCandidateDigest(&bind.CallOpts{
Context: ctx,
}, donID, uint8(types.PluginTypeCCIPCommit))
require.NoError(t, err)
require.Equal(t, [32]byte{}, candidateDigestCommitBefore)
candidateDigestExecBefore, err := ccipHome.GetCandidateDigest(&bind.CallOpts{
Context: ctx,
}, donID, uint8(types.PluginTypeCCIPExec))
require.NoError(t, err)
require.Equal(t, [32]byte{}, candidateDigestExecBefore)

var mcmsConfig *MCMSConfig
if tc.mcmsEnabled {
mcmsConfig = &MCMSConfig{
MinDelay: 0,
}
}
_, err = commonchangeset.ApplyChangesets(t, tenv.Env, map[uint64]*commonchangeset.TimelockExecutionContracts{
tenv.HomeChainSel: {
Timelock: state.Chains[tenv.HomeChainSel].Timelock,
CallProxy: state.Chains[tenv.HomeChainSel].CallProxy,
},
}, []commonchangeset.ChangesetApplication{
{
Changeset: commonchangeset.WrapChangeSet(PromoteAllCandidatesChangeset),
Config: PromoteAllCandidatesChangesetConfig{
HomeChainSelector: tenv.HomeChainSel,
DONChainSelector: dest,
NodeIDs: nodeIDs,
MCMS: mcmsConfig,
},
},
})
require.NoError(t, err)

// after promoting the zero digest, active digest should also be zero
activeDigestCommit, err := ccipHome.GetActiveDigest(&bind.CallOpts{
Context: ctx,
}, donID, uint8(types.PluginTypeCCIPCommit))
require.NoError(t, err)
require.Equal(t, [32]byte{}, activeDigestCommit)

activeDigestExec, err := ccipHome.GetActiveDigest(&bind.CallOpts{
Context: ctx,
}, donID, uint8(types.PluginTypeCCIPExec))
require.NoError(t, err)
require.Equal(t, [32]byte{}, activeDigestExec)
})
}
}
137 changes: 0 additions & 137 deletions deployment/ccip/changeset/cs_promote_candidate_test.go

This file was deleted.

0 comments on commit 88af68e

Please sign in to comment.