From 83b1a9fc222c0f10e66ddbc567d8af28cc7312c9 Mon Sep 17 00:00:00 2001 From: colin axner Date: Wed, 31 Jul 2019 08:07:39 -0700 Subject: [PATCH] Merge PR #4798: Deprecate remove and add permissions in ModuleAccount --- .../improvements/modules/4762-Deprecate-remov | 1 + x/supply/internal/keeper/keeper_test.go | 7 ++++--- x/supply/internal/types/account.go | 18 ----------------- x/supply/internal/types/account_test.go | 20 ------------------- 4 files changed, 5 insertions(+), 41 deletions(-) create mode 100644 .pending/improvements/modules/4762-Deprecate-remov diff --git a/.pending/improvements/modules/4762-Deprecate-remov b/.pending/improvements/modules/4762-Deprecate-remov new file mode 100644 index 0000000000..463b32db26 --- /dev/null +++ b/.pending/improvements/modules/4762-Deprecate-remov @@ -0,0 +1 @@ +# 4762 Deprecate remove and add permissions in ModuleAccount. \ No newline at end of file diff --git a/x/supply/internal/keeper/keeper_test.go b/x/supply/internal/keeper/keeper_test.go index fe2ce3dce2..18fcb96757 100644 --- a/x/supply/internal/keeper/keeper_test.go +++ b/x/supply/internal/keeper/keeper_test.go @@ -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) } diff --git a/x/supply/internal/types/account.go b/x/supply/internal/types/account.go index 76588ce1ec..b07bb31c91 100644 --- a/x/supply/internal/types/account.go +++ b/x/supply/internal/types/account.go @@ -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 { diff --git a/x/supply/internal/types/account_test.go b/x/supply/internal/types/account_test.go index 061cf6f2a9..e9d3a0760b 100644 --- a/x/supply/internal/types/account_test.go +++ b/x/supply/internal/types/account_test.go @@ -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)