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(community): add MsgUpdateParams for governance #1745

Merged
merged 10 commits into from
Oct 11, 2023
56 changes: 56 additions & 0 deletions x/community/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import (

sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/stretchr/testify/suite"

"github.com/kava-labs/kava/x/community/keeper"
"github.com/kava-labs/kava/x/community/testutil"
"github.com/kava-labs/kava/x/community/types"
)
Expand Down Expand Up @@ -89,3 +92,56 @@ func (suite *KeeperTestSuite) TestGetAndSetStakingRewardsState() {

suite.Equal(validParams, keeper.GetStakingRewardsState(suite.Ctx), "expected fetched state to equal set state")
}

func (suite *KeeperTestSuite) TestGetAuthority_Default() {
suite.Equal(
authtypes.NewModuleAddress(govtypes.ModuleName),
suite.Keeper.GetAuthority(),
"expected fetched authority to equal x/gov address",
)
}

func (suite *KeeperTestSuite) TestGetAuthority_Any() {
tests := []struct {
name string
authority sdk.AccAddress
}{
{
name: "gov",
authority: authtypes.NewModuleAddress(govtypes.ModuleName),
},
{
name: "empty",
authority: sdk.AccAddress{},
},
drklee3 marked this conversation as resolved.
Show resolved Hide resolved
{
name: "random",
authority: sdk.AccAddress("random"),
},
}

for _, tc := range tests {
suite.Run(tc.name, func() {
suite.Keeper = keeper.NewKeeper(
suite.App.AppCodec(),
suite.App.GetKVStoreKey(types.StoreKey),
suite.App.GetAccountKeeper(),
suite.App.GetBankKeeper(),
suite.App.GetCDPKeeper(),
suite.App.GetDistrKeeper(),
suite.App.GetHardKeeper(),
suite.App.GetMintKeeper(),
suite.App.GetKavadistKeeper(),
suite.App.GetStakingKeeper(),
tc.authority,
)

suite.Equalf(
tc.authority,
suite.Keeper.GetAuthority(),
"expected fetched authority to equal %s address",
tc.authority,
)
})
}
}
58 changes: 58 additions & 0 deletions x/community/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (

sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/stretchr/testify/suite"

"github.com/kava-labs/kava/app"
Expand Down Expand Up @@ -110,3 +112,59 @@ func (suite *msgServerTestSuite) TestMsgFundCommunityPool() {
})
}
}

func (suite *msgServerTestSuite) TestMsgUpdateParams() {
govAddr := authtypes.NewModuleAddress(govtypes.ModuleName)

testCases := []struct {
name string
msg types.MsgUpdateParams
expectedError error
}{
{
name: "valid",
msg: types.MsgUpdateParams{
Authority: govAddr.String(),
Params: types.DefaultParams(),
},
expectedError: nil,
},
{
name: "invalid - bad authority",
msg: types.MsgUpdateParams{
Authority: sdk.AccAddress{1, 2, 3}.String(),
Params: types.DefaultParams(),
},
expectedError: govtypes.ErrInvalidSigner,
},
{
name: "invalid - empty authority",
msg: types.MsgUpdateParams{
Authority: "",
Params: types.DefaultParams(),
},
expectedError: govtypes.ErrInvalidSigner,
},
{
name: "invalid - parameters",
msg: types.MsgUpdateParams{
Authority: govAddr.String(),
Params: types.Params{},
},
expectedError: types.ErrInvalidParams,
},
}

for _, tc := range testCases {
suite.Run(tc.name, func() {
suite.SetupTest()

_, err := suite.msgServer.UpdateParams(sdk.WrapSDKContext(suite.Ctx), &tc.msg)
if tc.expectedError == nil {
suite.NoError(err)
} else {
suite.ErrorIs(err, tc.expectedError)
}
})
}
}
Loading