Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(deployment): add labels to the MCMSWithTimelockConfigV2 type #16487

Merged
merged 1 commit into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 40 additions & 6 deletions deployment/common/changeset/internal/evm/mcms.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ import (
"github.com/smartcontractkit/chainlink/deployment/common/view/v1_0"
)

// DeployMCMSOption is a function that modifies a TypeAndVersion before or after deployment.
type DeployMCMSOption func(*deployment.TypeAndVersion)

// WithLabel is a functional option that sets a label on the TypeAndVersion.
func WithLabel(label string) DeployMCMSOption {
return func(tv *deployment.TypeAndVersion) {
tv.AddLabel(label)
}
}

// MCMSWithTimelockEVMDeploy holds a bundle of MCMS contract deploys.
type MCMSWithTimelockEVMDeploy struct {
Canceller *deployment.ContractDeploy[*bindings.ManyChainMultiSig]
Expand All @@ -28,6 +38,7 @@ func deployMCMSWithConfigEVM(
chain deployment.Chain,
ab deployment.AddressBook,
mcmConfig mcmsTypes.Config,
options ...DeployMCMSOption,
) (*deployment.ContractDeploy[*bindings.ManyChainMultiSig], error) {
groupQuorums, groupParents, signerAddresses, signerGroups, err := evmMcms.ExtractSetConfigInputs(&mcmConfig)
if err != nil {
Expand All @@ -40,8 +51,14 @@ func deployMCMSWithConfigEVM(
chain.DeployerKey,
chain.Client,
)

tv := deployment.NewTypeAndVersion(contractType, deployment.Version1_0_0)
for _, option := range options {
option(&tv)
}

return deployment.ContractDeploy[*bindings.ManyChainMultiSig]{
Address: mcmAddr, Contract: mcm, Tx: tx, Tv: deployment.NewTypeAndVersion(contractType, deployment.Version1_0_0), Err: err2,
Address: mcmAddr, Contract: mcm, Tx: tx, Tv: tv, Err: err2,
}
})
if err != nil {
Expand Down Expand Up @@ -74,15 +91,20 @@ func DeployMCMSWithTimelockContractsEVM(
ab deployment.AddressBook,
config commontypes.MCMSWithTimelockConfigV2,
) (*MCMSWithTimelockEVMDeploy, error) {
bypasser, err := deployMCMSWithConfigEVM(commontypes.BypasserManyChainMultisig, lggr, chain, ab, config.Bypasser)
opts := []DeployMCMSOption{}
if config.Label != nil {
opts = append(opts, WithLabel(*config.Label))
}

bypasser, err := deployMCMSWithConfigEVM(commontypes.BypasserManyChainMultisig, lggr, chain, ab, config.Bypasser, opts...)
if err != nil {
return nil, err
}
canceller, err := deployMCMSWithConfigEVM(commontypes.CancellerManyChainMultisig, lggr, chain, ab, config.Canceller)
canceller, err := deployMCMSWithConfigEVM(commontypes.CancellerManyChainMultisig, lggr, chain, ab, config.Canceller, opts...)
if err != nil {
return nil, err
}
proposer, err := deployMCMSWithConfigEVM(commontypes.ProposerManyChainMultisig, lggr, chain, ab, config.Proposer)
proposer, err := deployMCMSWithConfigEVM(commontypes.ProposerManyChainMultisig, lggr, chain, ab, config.Proposer, opts...)
if err != nil {
return nil, err
}
Expand All @@ -104,8 +126,14 @@ func DeployMCMSWithTimelockContractsEVM(
[]common.Address{canceller.Address, proposer.Address, bypasser.Address}, // cancellers
[]common.Address{bypasser.Address}, // bypassers
)

tv := deployment.NewTypeAndVersion(commontypes.RBACTimelock, deployment.Version1_0_0)
if config.Label != nil {
tv.AddLabel(*config.Label)
}

return deployment.ContractDeploy[*bindings.RBACTimelock]{
Address: timelock, Contract: cc, Tx: tx2, Tv: deployment.NewTypeAndVersion(commontypes.RBACTimelock, deployment.Version1_0_0), Err: err2,
Address: timelock, Contract: cc, Tx: tx2, Tv: tv, Err: err2,
}
})
if err != nil {
Expand All @@ -120,8 +148,14 @@ func DeployMCMSWithTimelockContractsEVM(
chain.Client,
timelock.Address,
)

tv := deployment.NewTypeAndVersion(commontypes.CallProxy, deployment.Version1_0_0)
if config.Label != nil {
tv.AddLabel(*config.Label)
}

return deployment.ContractDeploy[*bindings.CallProxy]{
Address: callProxy, Contract: cc, Tx: tx2, Tv: deployment.NewTypeAndVersion(commontypes.CallProxy, deployment.Version1_0_0), Err: err2,
Address: callProxy, Contract: cc, Tx: tx2, Tv: tv, Err: err2,
}
})
if err != nil {
Expand Down
73 changes: 73 additions & 0 deletions deployment/common/changeset/internal/evm/mcms_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package mcmsnew_test

import (
"encoding/json"
"testing"

chainsel "github.com/smartcontractkit/chain-selectors"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink/deployment"
"github.com/smartcontractkit/chainlink/deployment/common/changeset/internal"
"github.com/smartcontractkit/chainlink/deployment/common/changeset/state"
"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"
)

func TestDeployMCMSWithConfig(t *testing.T) {
lggr := logger.TestLogger(t)

chains, _ := memory.NewMemoryChainsWithChainIDs(t, []uint64{
chainsel.TEST_90000001.EvmChainID,
}, 1)
ab := deployment.NewMemoryAddressBook()

// 1) Test WITHOUT a label
mcmNoLabel, err := internal.DeployMCMSWithConfig(
types.ProposerManyChainMultisig,
lggr,
chains[chainsel.TEST_90000001.Selector],
ab,
proposalutils.SingleGroupMCMS(t),
)
require.NoError(t, err)
require.Empty(t, mcmNoLabel.Tv.Labels, "expected no label to be set")

// 2) Test WITH a label
label := "SA"
mcmWithLabel, err := internal.DeployMCMSWithConfig(
types.ProposerManyChainMultisig,
lggr,
chains[chainsel.TEST_90000001.Selector],
ab,
proposalutils.SingleGroupMCMS(t),
internal.WithLabel(label),
)
require.NoError(t, err)
require.NotNil(t, mcmWithLabel.Tv.Labels, "expected labels to be set")
require.Contains(t, mcmWithLabel.Tv.Labels, label, "label mismatch")
}

func TestDeployMCMSWithTimelockContracts(t *testing.T) {
lggr := logger.TestLogger(t)
chains, _ := memory.NewMemoryChainsWithChainIDs(t, []uint64{
chainsel.TEST_90000001.EvmChainID,
}, 1)
ab := deployment.NewMemoryAddressBook()
_, err := internal.DeployMCMSWithTimelockContracts(lggr,
chains[chainsel.TEST_90000001.Selector],
ab, proposalutils.SingleGroupTimelockConfig(t))
require.NoError(t, err)
addresses, err := ab.AddressesForChain(chainsel.TEST_90000001.Selector)
require.NoError(t, err)
require.Len(t, addresses, 5)
mcmsState, err := state.MaybeLoadMCMSWithTimelockChainState(chains[chainsel.TEST_90000001.Selector], addresses)
require.NoError(t, err)
v, err := mcmsState.GenerateMCMSWithTimelockView()
require.NoError(t, err)
b, err := json.MarshalIndent(v, "", " ")
require.NoError(t, err)
t.Log(string(b))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checking we do want to log the result ? Or should be assert it with a JSON result?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷‍♂️ good question. I kinda copy&pasted the test...

}
1 change: 1 addition & 0 deletions deployment/common/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ type MCMSWithTimelockConfigV2 struct {
Bypasser mcmstypes.Config
Proposer mcmstypes.Config
TimelockMinDelay *big.Int
Label *string
}

type OCRParameters struct {
Expand Down
Loading