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

feat(x/params): add DeleteSubspace to params keeper #396

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 11 additions & 0 deletions x/params/keeper/keeper.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package keeper

import (
"fmt"

"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -71,3 +73,12 @@ func (k Keeper) GetSubspaces() []types.Subspace {

return spaces
}

func (k Keeper) DeleteSubspace(s string) error {
_, ok := k.spaces[s]
if !ok {
return fmt.Errorf("can not delete subspace %s because it does not exist", s)
}
delete(k.spaces, s)
return nil
}
19 changes: 19 additions & 0 deletions x/params/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"cosmossdk.io/math"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
Expand Down Expand Up @@ -278,3 +279,21 @@ func TestJSONUpdate(t *testing.T) {
space.Get(ctx, key, &param)
require.Equal(t, paramJSON{40964096, "goodbyeworld"}, param)
}

func TestDeleteSubspace(t *testing.T) {
_, _, _, _, keeper := testComponents()
name := "test"

t.Run("should return an error if DeleteSubspace is invoked on a non-existent subspace", func(t *testing.T) {
err := keeper.DeleteSubspace(name)
assert.Error(t, err)
})
t.Run("should return no error if DeleteSubspace is invoked on a subspace", func(t *testing.T) {
keeper.Subspace(name)
err := keeper.DeleteSubspace(name)
assert.NoError(t, err)
_, exists := keeper.GetSubspace(name)
assert.False(t, exists)
})

}
Loading