Skip to content

Commit

Permalink
refactor mcms utils
Browse files Browse the repository at this point in the history
  • Loading branch information
krehermann committed Dec 12, 2024
1 parent fa91ed1 commit f4b09c6
Show file tree
Hide file tree
Showing 21 changed files with 186 additions and 161 deletions.
7 changes: 4 additions & 3 deletions deployment/ccip/changeset/accept_ownership_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"golang.org/x/exp/maps"

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

func Test_NewAcceptOwnershipChangeset(t *testing.T) {
Expand All @@ -21,12 +22,12 @@ func Test_NewAcceptOwnershipChangeset(t *testing.T) {
source := allChains[0]
dest := allChains[1]

timelockContracts := map[uint64]*commonchangeset.TimelockExecutionContracts{
source: &commonchangeset.TimelockExecutionContracts{
timelockContracts := map[uint64]*proposalutils.TimelockExecutionContracts{
source: &proposalutils.TimelockExecutionContracts{
Timelock: state.Chains[source].Timelock,
CallProxy: state.Chains[source].CallProxy,
},
dest: &commonchangeset.TimelockExecutionContracts{
dest: &proposalutils.TimelockExecutionContracts{
Timelock: state.Chains[dest].Timelock,
CallProxy: state.Chains[dest].CallProxy,
},
Expand Down
13 changes: 4 additions & 9 deletions deployment/ccip/changeset/cs_add_chain_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package changeset

import (
"math/big"
"testing"
"time"

"github.com/smartcontractkit/chainlink/deployment/ccip/changeset/internal"
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/v2/core/capabilities/ccip/types"

Expand Down Expand Up @@ -47,12 +47,7 @@ func TestAddChainInbound(t *testing.T) {
require.NoError(t, err)
require.NoError(t, e.Env.ExistingAddresses.Merge(newAddresses))

cfg := commontypes.MCMSWithTimelockConfig{
Canceller: commonchangeset.SingleGroupMCMS(t),
Bypasser: commonchangeset.SingleGroupMCMS(t),
Proposer: commonchangeset.SingleGroupMCMS(t),
TimelockMinDelay: big.NewInt(0),
}
cfg := proposalutils.SingleGroupTimelockConfig(t)
e.Env, err = commonchangeset.ApplyChangesets(t, e.Env, nil, []commonchangeset.ChangesetApplication{
{
Changeset: commonchangeset.WrapChangeSet(commonchangeset.DeployLinkToken),
Expand Down Expand Up @@ -153,7 +148,7 @@ func TestAddChainInbound(t *testing.T) {
}

// transfer ownership to timelock
_, err = commonchangeset.ApplyChangesets(t, e.Env, map[uint64]*commonchangeset.TimelockExecutionContracts{
_, err = commonchangeset.ApplyChangesets(t, e.Env, map[uint64]*proposalutils.TimelockExecutionContracts{
initialDeploy[0]: {
Timelock: state.Chains[initialDeploy[0]].Timelock,
CallProxy: state.Chains[initialDeploy[0]].CallProxy,
Expand Down Expand Up @@ -195,7 +190,7 @@ func TestAddChainInbound(t *testing.T) {
nodeIDs = append(nodeIDs, node.NodeID)
}

_, err = commonchangeset.ApplyChangesets(t, e.Env, map[uint64]*commonchangeset.TimelockExecutionContracts{
_, err = commonchangeset.ApplyChangesets(t, e.Env, map[uint64]*proposalutils.TimelockExecutionContracts{
e.HomeChainSel: {
Timelock: state.Chains[e.HomeChainSel].Timelock,
CallProxy: state.Chains[e.HomeChainSel].CallProxy,
Expand Down
20 changes: 10 additions & 10 deletions deployment/ccip/changeset/cs_ccip_home_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ func TestActiveCandidate(t *testing.T) {
ConfirmExecWithSeqNrsForAll(t, e, state, expectedSeqNumExec, startBlocks)

// compose the transfer ownership and accept ownership changesets
timelockContracts := make(map[uint64]*commonchangeset.TimelockExecutionContracts)
timelockContracts := make(map[uint64]*proposalutils.TimelockExecutionContracts)
for _, chain := range allChains {
timelockContracts[chain] = &commonchangeset.TimelockExecutionContracts{
timelockContracts[chain] = &proposalutils.TimelockExecutionContracts{
Timelock: state.Chains[chain].Timelock,
CallProxy: state.Chains[chain].CallProxy,
}
Expand Down Expand Up @@ -176,8 +176,8 @@ func TestActiveCandidate(t *testing.T) {
Batch: setCommitCandidateOp,
}}, "set new candidates on commit plugin", 0)
require.NoError(t, err)
setCommitCandidateSigned := commonchangeset.SignProposal(t, e, setCommitCandidateProposal)
commonchangeset.ExecuteProposal(t, e, setCommitCandidateSigned, &commonchangeset.TimelockExecutionContracts{
setCommitCandidateSigned := proposalutils.SignProposal(t, e, setCommitCandidateProposal)
proposalutils.ExecuteProposal(t, e, setCommitCandidateSigned, &proposalutils.TimelockExecutionContracts{
Timelock: state.Chains[tenv.HomeChainSel].Timelock,
CallProxy: state.Chains[tenv.HomeChainSel].CallProxy,
}, tenv.HomeChainSel)
Expand All @@ -197,8 +197,8 @@ func TestActiveCandidate(t *testing.T) {
Batch: setExecCandidateOp,
}}, "set new candidates on commit and exec plugins", 0)
require.NoError(t, err)
setExecCandidateSigned := commonchangeset.SignProposal(t, e, setExecCandidateProposal)
commonchangeset.ExecuteProposal(t, e, setExecCandidateSigned, &commonchangeset.TimelockExecutionContracts{
setExecCandidateSigned := proposalutils.SignProposal(t, e, setExecCandidateProposal)
proposalutils.ExecuteProposal(t, e, setExecCandidateSigned, &proposalutils.TimelockExecutionContracts{
Timelock: state.Chains[tenv.HomeChainSel].Timelock,
CallProxy: state.Chains[tenv.HomeChainSel].CallProxy,
}, tenv.HomeChainSel)
Expand Down Expand Up @@ -234,8 +234,8 @@ func TestActiveCandidate(t *testing.T) {
Batch: promoteOps,
}}, "promote candidates and revoke actives", 0)
require.NoError(t, err)
promoteSigned := commonchangeset.SignProposal(t, e, promoteProposal)
commonchangeset.ExecuteProposal(t, e, promoteSigned, &commonchangeset.TimelockExecutionContracts{
promoteSigned := proposalutils.SignProposal(t, e, promoteProposal)
proposalutils.ExecuteProposal(t, e, promoteSigned, &proposalutils.TimelockExecutionContracts{
Timelock: state.Chains[tenv.HomeChainSel].Timelock,
CallProxy: state.Chains[tenv.HomeChainSel].CallProxy,
}, tenv.HomeChainSel)
Expand Down Expand Up @@ -298,7 +298,7 @@ func Test_PromoteCandidate(t *testing.T) {

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{
_, err = commonchangeset.ApplyChangesets(t, tenv.Env, map[uint64]*proposalutils.TimelockExecutionContracts{
source: {
Timelock: state.Chains[source].Timelock,
CallProxy: state.Chains[source].CallProxy,
Expand Down Expand Up @@ -345,7 +345,7 @@ func Test_PromoteCandidate(t *testing.T) {
MinDelay: 0,
}
}
_, err = commonchangeset.ApplyChangesets(t, tenv.Env, map[uint64]*commonchangeset.TimelockExecutionContracts{
_, err = commonchangeset.ApplyChangesets(t, tenv.Env, map[uint64]*proposalutils.TimelockExecutionContracts{
tenv.HomeChainSel: {
Timelock: state.Chains[tenv.HomeChainSel].Timelock,
CallProxy: state.Chains[tenv.HomeChainSel].CallProxy,
Expand Down
10 changes: 3 additions & 7 deletions deployment/ccip/changeset/cs_deploy_chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package changeset
import (
"encoding/json"
"fmt"
"math/big"
"testing"

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

"github.com/smartcontractkit/chainlink/deployment"
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/logger"
Expand All @@ -31,12 +31,7 @@ func TestDeployChainContractsChangeset(t *testing.T) {
p2pIds := nodes.NonBootstraps().PeerIDs()
cfg := make(map[uint64]commontypes.MCMSWithTimelockConfig)
for _, chain := range e.AllChainSelectors() {
cfg[chain] = commontypes.MCMSWithTimelockConfig{
Canceller: commonchangeset.SingleGroupMCMS(t),
Bypasser: commonchangeset.SingleGroupMCMS(t),
Proposer: commonchangeset.SingleGroupMCMS(t),
TimelockMinDelay: big.NewInt(0),
}
cfg[chain] = proposalutils.SingleGroupTimelockConfig(t)
}
e, err = commonchangeset.ApplyChangesets(t, e, nil, []commonchangeset.ChangesetApplication{
{
Expand Down Expand Up @@ -99,6 +94,7 @@ func TestDeployChainContractsChangeset(t *testing.T) {
}

func TestDeployCCIPContracts(t *testing.T) {
t.Parallel()
e := NewMemoryEnvironment(t)
// Deploy all the CCIP contracts.
state, err := LoadOnchainState(e.Env)
Expand Down
5 changes: 3 additions & 2 deletions deployment/ccip/changeset/cs_initial_add_chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/stretchr/testify/require"

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

Expand All @@ -25,10 +26,10 @@ func TestInitialAddChainAppliedTwice(t *testing.T) {
allChains := e.Env.AllChainSelectors()
tokenConfig := NewTestTokenConfig(state.Chains[e.FeedChainSel].USDFeeds)
chainConfigs := make(map[uint64]CCIPOCRParams)
timelockContractsPerChain := make(map[uint64]*commonchangeset.TimelockExecutionContracts)
timelockContractsPerChain := make(map[uint64]*proposalutils.TimelockExecutionContracts)

for _, chain := range allChains {
timelockContractsPerChain[chain] = &commonchangeset.TimelockExecutionContracts{
timelockContractsPerChain[chain] = &proposalutils.TimelockExecutionContracts{
Timelock: state.Chains[chain].Timelock,
CallProxy: state.Chains[chain].CallProxy,
}
Expand Down
7 changes: 3 additions & 4 deletions deployment/ccip/changeset/cs_update_rmn_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/mcms"
"github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/timelock"
"github.com/smartcontractkit/chainlink/deployment"
commonchangeset "github.com/smartcontractkit/chainlink/deployment/common/changeset"
"github.com/smartcontractkit/chainlink/deployment/common/proposalutils"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/rmn_home"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/rmn_remote"
Expand Down Expand Up @@ -274,10 +273,10 @@ func NewPromoteCandidateConfigChangeset(e deployment.Environment, config Promote
}, nil
}

func buildTimelockPerChain(e deployment.Environment, state CCIPOnChainState) map[uint64]*commonchangeset.TimelockExecutionContracts {
timelocksPerChain := make(map[uint64]*commonchangeset.TimelockExecutionContracts)
func buildTimelockPerChain(e deployment.Environment, state CCIPOnChainState) map[uint64]*proposalutils.TimelockExecutionContracts {
timelocksPerChain := make(map[uint64]*proposalutils.TimelockExecutionContracts)
for _, chain := range e.Chains {
timelocksPerChain[chain.Selector] = &commonchangeset.TimelockExecutionContracts{
timelocksPerChain[chain.Selector] = &proposalutils.TimelockExecutionContracts{
Timelock: state.Chains[chain.Selector].Timelock,
CallProxy: state.Chains[chain.Selector].CallProxy,
}
Expand Down
1 change: 1 addition & 0 deletions deployment/ccip/changeset/cs_update_rmn_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func TestUpdateRMNConfig(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
updateRMNConfig(t, tc)
})
}
Expand Down
12 changes: 4 additions & 8 deletions deployment/ccip/changeset/test_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/smartcontractkit/chainlink/deployment"
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"
)
Expand Down Expand Up @@ -299,12 +300,7 @@ func NewEnvironmentWithJobsAndContracts(t *testing.T, tc *TestConfigs, tEnv Test
mcmsCfg := make(map[uint64]commontypes.MCMSWithTimelockConfig)

for _, c := range e.Env.AllChainSelectors() {
mcmsCfg[c] = commontypes.MCMSWithTimelockConfig{
Canceller: commonchangeset.SingleGroupMCMS(t),
Bypasser: commonchangeset.SingleGroupMCMS(t),
Proposer: commonchangeset.SingleGroupMCMS(t),
TimelockMinDelay: big.NewInt(0),
}
mcmsCfg[c] = proposalutils.SingleGroupTimelockConfig(t)
}
var (
usdcChains []uint64
Expand Down Expand Up @@ -382,9 +378,9 @@ func NewEnvironmentWithJobsAndContracts(t *testing.T, tc *TestConfigs, tEnv Test
}
// Build the per chain config.
chainConfigs := make(map[uint64]CCIPOCRParams)
timelockContractsPerChain := make(map[uint64]*commonchangeset.TimelockExecutionContracts)
timelockContractsPerChain := make(map[uint64]*proposalutils.TimelockExecutionContracts)
for _, chain := range allChains {
timelockContractsPerChain[chain] = &commonchangeset.TimelockExecutionContracts{
timelockContractsPerChain[chain] = &proposalutils.TimelockExecutionContracts{
Timelock: state.Chains[chain].Timelock,
CallProxy: state.Chains[chain].CallProxy,
}
Expand Down
9 changes: 5 additions & 4 deletions deployment/common/changeset/internal/mcms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/smartcontractkit/chainlink/deployment"
"github.com/smartcontractkit/chainlink/deployment/common/changeset"
"github.com/smartcontractkit/chainlink/deployment/common/changeset/internal"
"github.com/smartcontractkit/chainlink/deployment/common/proposalutils"
"github.com/smartcontractkit/chainlink/deployment/common/types"
"github.com/smartcontractkit/chainlink/deployment/environment/memory"
"github.com/smartcontractkit/chainlink/v2/core/logger"
Expand All @@ -23,7 +24,7 @@ func TestDeployMCMSWithConfig(t *testing.T) {
})
ab := deployment.NewMemoryAddressBook()
_, err := internal.DeployMCMSWithConfig(types.ProposerManyChainMultisig,
lggr, chains[chainsel.TEST_90000001.Selector], ab, changeset.SingleGroupMCMS(t))
lggr, chains[chainsel.TEST_90000001.Selector], ab, proposalutils.SingleGroupMCMS(t))
require.NoError(t, err)
}

Expand All @@ -36,9 +37,9 @@ func TestDeployMCMSWithTimelockContracts(t *testing.T) {
_, err := internal.DeployMCMSWithTimelockContracts(lggr,
chains[chainsel.TEST_90000001.Selector],
ab, types.MCMSWithTimelockConfig{
Canceller: changeset.SingleGroupMCMS(t),
Bypasser: changeset.SingleGroupMCMS(t),
Proposer: changeset.SingleGroupMCMS(t),
Canceller: proposalutils.SingleGroupMCMS(t),
Bypasser: proposalutils.SingleGroupMCMS(t),
Proposer: proposalutils.SingleGroupMCMS(t),
TimelockMinDelay: big.NewInt(0),
})
require.NoError(t, err)
Expand Down
Loading

0 comments on commit f4b09c6

Please sign in to comment.