Skip to content

Commit 83b1a9f

Browse files
colin-axneralexanderbez
authored andcommitted
Merge PR #4798: Deprecate remove and add permissions in ModuleAccount
1 parent 0fec748 commit 83b1a9f

File tree

4 files changed

+5
-41
lines changed

4 files changed

+5
-41
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# 4762 Deprecate remove and add permissions in ModuleAccount.

x/supply/internal/keeper/keeper_test.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/stretchr/testify/require"
77

88
sdk "github.com/cosmos/cosmos-sdk/types"
9+
"github.com/cosmos/cosmos-sdk/x/supply/internal/types"
910
)
1011

1112
func TestSupply(t *testing.T) {
@@ -32,8 +33,8 @@ func TestValidatePermissions(t *testing.T) {
3233
err = keeper.ValidatePermissions(randomPermAcc)
3334
require.NoError(t, err)
3435

35-
// add unregistered permissions
36-
randomPermAcc.AddPermissions("other")
37-
err = keeper.ValidatePermissions(randomPermAcc)
36+
// unregistered permissions
37+
otherAcc := types.NewEmptyModuleAccount("other", "other")
38+
err = keeper.ValidatePermissions(otherAcc)
3839
require.Error(t, err)
3940
}

x/supply/internal/types/account.go

-18
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,6 @@ func NewModuleAccount(ba *authtypes.BaseAccount,
5656
}
5757
}
5858

59-
// AddPermissions adds the permissions to the module account's list of granted
60-
// permissions.
61-
func (ma *ModuleAccount) AddPermissions(permissions ...string) {
62-
ma.Permissions = append(ma.Permissions, permissions...)
63-
}
64-
65-
// RemovePermission removes the permission from the list of granted permissions
66-
// or returns an error if the permission is has not been granted.
67-
func (ma *ModuleAccount) RemovePermission(permission string) error {
68-
for i, perm := range ma.Permissions {
69-
if perm == permission {
70-
ma.Permissions = append(ma.Permissions[:i], ma.Permissions[i+1:]...)
71-
return nil
72-
}
73-
}
74-
return fmt.Errorf("cannot remove non granted permission %s", permission)
75-
}
76-
7759
// HasPermission returns whether or not the module account has permission.
7860
func (ma ModuleAccount) HasPermission(permission string) bool {
7961
for _, perm := range ma.Permissions {

x/supply/internal/types/account_test.go

-20
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,6 @@ func TestModuleAccountMarshalYAML(t *testing.T) {
3636
require.Equal(t, want, moduleAcc.String())
3737
}
3838

39-
func TestRemovePermissions(t *testing.T) {
40-
name := "test"
41-
macc := NewEmptyModuleAccount(name)
42-
require.Empty(t, macc.GetPermissions())
43-
44-
macc.AddPermissions(Minter, Burner, Staking)
45-
require.Equal(t, []string{Minter, Burner, Staking}, macc.GetPermissions(), "did not add permissions")
46-
47-
err := macc.RemovePermission("random")
48-
require.Error(t, err, "did not error on removing nonexistent permission")
49-
50-
err = macc.RemovePermission(Burner)
51-
require.NoError(t, err, "failed to remove permission")
52-
require.Equal(t, []string{Minter, Staking}, macc.GetPermissions(), "does not have correct permissions")
53-
54-
err = macc.RemovePermission(Staking)
55-
require.NoError(t, err, "failed to remove permission")
56-
require.Equal(t, []string{Minter}, macc.GetPermissions(), "does not have correct permissions")
57-
}
58-
5939
func TestHasPermissions(t *testing.T) {
6040
name := "test"
6141
macc := NewEmptyModuleAccount(name, Staking, Minter, Burner)

0 commit comments

Comments
 (0)