Skip to content

Commit

Permalink
feat: delete subspace (#396)
Browse files Browse the repository at this point in the history
  • Loading branch information
rootulp authored Apr 29, 2024
1 parent d2720e3 commit 2b80623
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
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)
})

}

0 comments on commit 2b80623

Please sign in to comment.