Skip to content

Commit

Permalink
use RenounceRole instead of Revoke
Browse files Browse the repository at this point in the history
  • Loading branch information
akhilchainani committed Dec 16, 2024
1 parent 02d721d commit 6e43f5d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
15 changes: 7 additions & 8 deletions deployment/common/changeset/transfer_to_mcms_with_timelock.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,14 @@ func TransferToDeployer(e deployment.Environment, cfg TransferToDeployerConfig)
return deployment.ChangesetOutput{}, nil
}

var _ deployment.ChangeSet[RevokeTimelockDeployerConfig] = RevokeTimelockDeployer
var _ deployment.ChangeSet[RenounceTimelockDeployerConfig] = RenounceTimelockDeployer

type RevokeTimelockDeployerConfig struct {
ContractAddress common.Address
ChainSel uint64
type RenounceTimelockDeployerConfig struct {
ChainSel uint64
}

// RevokeTimelockDeployer revokes the deployer key from administering the contract.
func RevokeTimelockDeployer(e deployment.Environment, cfg RevokeTimelockDeployerConfig) (deployment.ChangesetOutput, error) {
// RenounceTimelockDeployer revokes the deployer key from administering the contract.
func RenounceTimelockDeployer(e deployment.Environment, cfg RenounceTimelockDeployerConfig) (deployment.ChangesetOutput, error) {
contracts, err := MaybeLoadMCMSWithTimelockState(e, []uint64{cfg.ChainSel})
if err != nil {
return deployment.ChangesetOutput{}, err
Expand All @@ -233,13 +232,13 @@ func RevokeTimelockDeployer(e deployment.Environment, cfg RevokeTimelockDeployer
if err != nil {
return deployment.ChangesetOutput{}, fmt.Errorf("failed to get admin role: %w", err)
}
tx, err := tl.RevokeRole(e.Chains[cfg.ChainSel].DeployerKey, admin, e.Chains[cfg.ChainSel].DeployerKey.From)
tx, err := tl.RenounceRole(e.Chains[cfg.ChainSel].DeployerKey, admin, e.Chains[cfg.ChainSel].DeployerKey.From)
if err != nil {
return deployment.ChangesetOutput{}, fmt.Errorf("failed to revoke deployer key: %w", err)
}
if _, err := deployment.ConfirmIfNoError(e.Chains[cfg.ChainSel], tx, err); err != nil {
return deployment.ChangesetOutput{}, err
}
e.Logger.Infof("revoked deployer key from owning contract %s", cfg.ContractAddress)
e.Logger.Infof("revoked deployer key from owning contract %s", tl.Address().Hex())
return deployment.ChangesetOutput{}, nil
}
24 changes: 17 additions & 7 deletions deployment/common/changeset/transfer_to_mcms_with_timelock_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package changeset

import (
"encoding/hex"
"testing"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
Expand Down Expand Up @@ -81,7 +80,7 @@ func TestTransferToMCMSWithTimelock(t *testing.T) {
require.Equal(t, e.Chains[chain1].DeployerKey.From, o)
}

func TestRevokeTimelockDeployer(t *testing.T) {
func TestRenounceTimelockDeployer(t *testing.T) {
lggr := logger.TestLogger(t)
e := memory.NewMemoryEnvironment(t, lggr, 0, memory.MemoryEnvironmentConfig{
Chains: 1,
Expand Down Expand Up @@ -110,12 +109,23 @@ func TestRevokeTimelockDeployer(t *testing.T) {
adminRole, err := tl.ADMINROLE(nil)
require.NoError(t, err)

r, err := tl.GetRoleAdmin(&bind.CallOpts{}, adminRole)
r, err := tl.GetRoleMemberCount(&bind.CallOpts{}, adminRole)
require.NoError(t, err)
h := hex.EncodeToString(r[:])
t.Logf("admin role: %s", h)
a := common.BytesToAddress(r[:])
require.Equal(t, 2, r.Int64())

require.Equal(t, a, e.Chains[chain1].DeployerKey.From)
// Revoke Deployer
e, err = ApplyChangesets(t, e, nil, []ChangesetApplication{
{
Changeset: WrapChangeSet(RenounceTimelockDeployer),
Config: RenounceTimelockDeployerConfig{
ChainSel: chain1,
},
},
})
require.NoError(t, err)

// Check that the deployer is no longer an admin
r, err = tl.GetRoleMemberCount(&bind.CallOpts{}, adminRole)
require.NoError(t, err)
require.Equal(t, 1, r.Int64())
}

0 comments on commit 6e43f5d

Please sign in to comment.