Merge PR #4798: Deprecate remove and add permissions in ModuleAccount

This commit is contained in:
colin axner 2019-07-31 08:07:39 -07:00 committed by Alexander Bezobchuk
parent 0fec74893d
commit 83b1a9fc22
4 changed files with 5 additions and 41 deletions

View File

@ -0,0 +1 @@
# 4762 Deprecate remove and add permissions in ModuleAccount.

View File

@ -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) {
@ -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)
}

View File

@ -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 {

View File

@ -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)