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

Deprecate remove and add permissions in ModuleAccount #4798

Merged
merged 3 commits into from
Jul 31, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions .pending/improvements/modules/4762-Deprecate-remov
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# 4762 Deprecate remove and add permissions in ModuleAccount.
7 changes: 4 additions & 3 deletions x/supply/internal/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/stretchr/testify/require"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/supply/internal/types"
)

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

// add unregistered permissions
randomPermAcc.AddPermissions("other")
err = keeper.ValidatePermissions(randomPermAcc)
// unregistered permissions
otherAcc := types.NewEmptyModuleAccount("other", "other")
err = keeper.ValidatePermissions(otherAcc)
require.Error(t, err)
}
18 changes: 0 additions & 18 deletions x/supply/internal/types/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,6 @@ func NewModuleAccount(ba *authtypes.BaseAccount,
}
}

// AddPermissions adds the permissions to the module account's list of granted
// permissions.
func (ma *ModuleAccount) AddPermissions(permissions ...string) {
ma.Permissions = append(ma.Permissions, permissions...)
}

// RemovePermission removes the permission from the list of granted permissions
// or returns an error if the permission is has not been granted.
func (ma *ModuleAccount) RemovePermission(permission string) error {
for i, perm := range ma.Permissions {
if perm == permission {
ma.Permissions = append(ma.Permissions[:i], ma.Permissions[i+1:]...)
return nil
}
}
return fmt.Errorf("cannot remove non granted permission %s", permission)
}

// HasPermission returns whether or not the module account has permission.
func (ma ModuleAccount) HasPermission(permission string) bool {
for _, perm := range ma.Permissions {
Expand Down
20 changes: 0 additions & 20 deletions x/supply/internal/types/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,6 @@ func TestModuleAccountMarshalYAML(t *testing.T) {
require.Equal(t, want, moduleAcc.String())
}

func TestRemovePermissions(t *testing.T) {
name := "test"
macc := NewEmptyModuleAccount(name)
require.Empty(t, macc.GetPermissions())

macc.AddPermissions(Minter, Burner, Staking)
require.Equal(t, []string{Minter, Burner, Staking}, macc.GetPermissions(), "did not add permissions")

err := macc.RemovePermission("random")
require.Error(t, err, "did not error on removing nonexistent permission")

err = macc.RemovePermission(Burner)
require.NoError(t, err, "failed to remove permission")
require.Equal(t, []string{Minter, Staking}, macc.GetPermissions(), "does not have correct permissions")

err = macc.RemovePermission(Staking)
require.NoError(t, err, "failed to remove permission")
require.Equal(t, []string{Minter}, macc.GetPermissions(), "does not have correct permissions")
}

func TestHasPermissions(t *testing.T) {
name := "test"
macc := NewEmptyModuleAccount(name, Staking, Minter, Burner)
Expand Down