diff --git a/CHANGELOG.md b/CHANGELOG.md index 79ba058520..75ab30e095 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## State Machine Breaking - (community) [#1704] Add param to control when inflation will be disabled +- (community) [#1707] Default staking rewards per second set to `744191` ## [v0.24.0] @@ -284,6 +285,7 @@ the [changelog](https://github.com/cosmos/cosmos-sdk/blob/v0.38.4/CHANGELOG.md). - [#257](https://github.com/Kava-Labs/kava/pulls/257) Include scripts to run large-scale simulations remotely using aws-batch +[#1707]: https://github.com/Kava-Labs/kava/pull/1707 [#1668]: https://github.com/Kava-Labs/kava/pull/1668 [#1669]: https://github.com/Kava-Labs/kava/pull/1669 [#1655]: https://github.com/Kava-Labs/kava/pull/1655 diff --git a/ci/env/kava-protonet/genesis.json b/ci/env/kava-protonet/genesis.json index f3a94a101e..06d11c7caa 100644 --- a/ci/env/kava-protonet/genesis.json +++ b/ci/env/kava-protonet/genesis.json @@ -1316,7 +1316,8 @@ }, "community": { "params": { - "upgrade_time_disable_inflation": "2023-11-01T00:00:00Z" + "upgrade_time_disable_inflation": "2023-11-01T00:00:00Z", + "rewards_per_second": "744191" } }, "crisis": { diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index da7dd77bdc..507aeb44e2 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -2906,6 +2906,7 @@ Params defines the parameters of the community module. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | | `upgrade_time_disable_inflation` | [google.protobuf.Timestamp](#google.protobuf.Timestamp) | | | +| `staking_rewards_per_second` | [string](#string) | | | diff --git a/proto/kava/community/v1beta1/params.proto b/proto/kava/community/v1beta1/params.proto index 78cf7db6c2..57a29bc8ff 100644 --- a/proto/kava/community/v1beta1/params.proto +++ b/proto/kava/community/v1beta1/params.proto @@ -1,6 +1,7 @@ syntax = "proto3"; package kava.community.v1beta1; +import "cosmos_proto/cosmos.proto"; import "gogoproto/gogo.proto"; import "google/protobuf/timestamp.proto"; @@ -12,4 +13,10 @@ message Params { (gogoproto.stdtime) = true, (gogoproto.nullable) = false ]; + + string staking_rewards_per_second = 2 [ + (cosmos_proto.scalar) = "cosmos.Int", + (gogoproto.customtype) = "cosmossdk.io/math.Int", + (gogoproto.nullable) = false + ]; } diff --git a/x/community/genesis_test.go b/x/community/genesis_test.go index 4904e45c48..aa780115c4 100644 --- a/x/community/genesis_test.go +++ b/x/community/genesis_test.go @@ -6,6 +6,7 @@ import ( "github.com/stretchr/testify/suite" + sdkmath "cosmossdk.io/math" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/kava-labs/kava/x/community" @@ -30,7 +31,10 @@ func (suite *genesisTestSuite) TestInitGenesis() { accountKeeper := suite.App.GetAccountKeeper() genesisState := types.NewGenesisState( - types.NewParams(time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC)), + types.NewParams( + time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC), + sdkmath.NewInt(1000), + ), ) suite.NotPanics(func() { @@ -49,8 +53,10 @@ func (suite *genesisTestSuite) TestInitGenesis() { } func (suite *genesisTestSuite) TestExportGenesis() { - - params := types.NewParams(time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC)) + params := types.NewParams( + time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC), + sdkmath.NewInt(1000), + ) suite.Keeper.SetParams(suite.Ctx, params) genesisState := community.ExportGenesis(suite.Ctx, suite.Keeper) @@ -60,7 +66,10 @@ func (suite *genesisTestSuite) TestExportGenesis() { func (suite *genesisTestSuite) TestInitExportIsLossless() { genesisState := types.NewGenesisState( - types.NewParams(time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC)), + types.NewParams( + time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC), + sdkmath.NewInt(1000), + ), ) community.InitGenesis(suite.Ctx, suite.Keeper, suite.App.GetAccountKeeper(), genesisState) diff --git a/x/community/keeper/grpc_query_test.go b/x/community/keeper/grpc_query_test.go index 7ab06051a8..d414a77986 100644 --- a/x/community/keeper/grpc_query_test.go +++ b/x/community/keeper/grpc_query_test.go @@ -34,7 +34,10 @@ func TestGrpcQueryTestSuite(t *testing.T) { } func (suite *grpcQueryTestSuite) TestGrpcQueryParams() { - p := types.NewParams(time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC)) + p := types.NewParams( + time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC), + sdkmath.NewInt(1000), + ) suite.Keeper.SetParams(suite.Ctx, p) res, err := suite.queryClient.Params(context.Background(), &types.QueryParamsRequest{}) diff --git a/x/community/keeper/migrations.go b/x/community/keeper/migrations.go new file mode 100644 index 0000000000..036c56fe12 --- /dev/null +++ b/x/community/keeper/migrations.go @@ -0,0 +1,27 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + v2 "github.com/kava-labs/kava/x/community/migrations/v2" +) + +// Migrator is a struct for handling in-place store migrations. +type Migrator struct { + keeper Keeper +} + +// NewMigrator returns a new Migrator. +func NewMigrator(keeper Keeper) Migrator { + return Migrator{ + keeper: keeper, + } +} + +// Migrate1to2 migrates from version 1 to 2. +func (m Migrator) Migrate1to2(ctx sdk.Context) error { + return v2.Migrate( + ctx, + ctx.KVStore(m.keeper.key), + m.keeper.cdc, + ) +} diff --git a/x/community/keeper/params_test.go b/x/community/keeper/params_test.go index c0b4008f85..ec744dca8c 100644 --- a/x/community/keeper/params_test.go +++ b/x/community/keeper/params_test.go @@ -4,6 +4,7 @@ import ( "testing" "time" + sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/suite" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" @@ -59,7 +60,10 @@ func (suite *StoreTestSuite) TestGetSetParams() { suite.Run("set overwrite previous value", func() { suite.Keeper.SetParams(suite.Ctx, types.DefaultParams()) - params := types.NewParams(time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC)) + params := types.NewParams( + time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC), + sdkmath.NewInt(1000), + ) suite.Keeper.SetParams(suite.Ctx, params) storedParams, found := suite.Keeper.GetParams(suite.Ctx) diff --git a/x/community/migrations/v2/store.go b/x/community/migrations/v2/store.go new file mode 100644 index 0000000000..5fb978927e --- /dev/null +++ b/x/community/migrations/v2/store.go @@ -0,0 +1,38 @@ +package v2 + +import ( + "time" + + storetypes "github.com/cosmos/cosmos-sdk/store/types" + + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/kava-labs/kava/x/community/types" +) + +const ( + ModuleName = "mint" +) + +// Migrate migrates the x/community module state from the consensus version 1 to +// version 2. Specifically, sets new parameters in the module state. +func Migrate( + ctx sdk.Context, + store storetypes.KVStore, + cdc codec.BinaryCodec, +) error { + params := types.NewParams( + // 2023-11-01T00:00:00Z + time.Date(2023, 11, 1, 0, 0, 0, 0, time.UTC), + sdk.NewInt(744191), + ) + + if err := params.Validate(); err != nil { + return err + } + + bz := cdc.MustMarshal(¶ms) + store.Set(types.ParamsKey, bz) + + return nil +} diff --git a/x/community/migrations/v2/store_test.go b/x/community/migrations/v2/store_test.go new file mode 100644 index 0000000000..7b189dbc06 --- /dev/null +++ b/x/community/migrations/v2/store_test.go @@ -0,0 +1,48 @@ +package v2_test + +import ( + "testing" + "time" + + "github.com/stretchr/testify/require" + + "github.com/cosmos/cosmos-sdk/testutil" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/kava-labs/kava/app" + v2 "github.com/kava-labs/kava/x/community/migrations/v2" + "github.com/kava-labs/kava/x/community/types" +) + +func TestMigrateStore(t *testing.T) { + tApp := app.NewTestApp() + cdc := tApp.AppCodec() + storeKey := sdk.NewKVStoreKey("community") + ctx := testutil.DefaultContext(storeKey, sdk.NewTransientStoreKey("transient_test")) + store := ctx.KVStore(storeKey) + + require.Nil( + t, + store.Get(types.ParamsKey), + "params shouldn't exist in store before migration", + ) + + require.NoError(t, v2.Migrate(ctx, store, cdc)) + + paramsBytes := store.Get(types.ParamsKey) + require.NotNil(t, paramsBytes, "params should be in store after migration") + + var params types.Params + cdc.MustUnmarshal(paramsBytes, ¶ms) + + t.Logf("params: %+v", params) + + require.Equal( + t, + types.NewParams( + time.Date(2023, 11, 1, 0, 0, 0, 0, time.UTC), + sdk.NewInt(744191), + ), + params, + "params should be correct after migration", + ) +} diff --git a/x/community/module.go b/x/community/module.go index 2b1bfbecbe..ec409a2ec0 100644 --- a/x/community/module.go +++ b/x/community/module.go @@ -3,6 +3,7 @@ package community import ( "context" "encoding/json" + "fmt" "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" @@ -20,6 +21,9 @@ import ( "github.com/kava-labs/kava/x/community/types" ) +// ConsensusVersion defines the current module consensus version. +const ConsensusVersion = 2 + var ( _ module.AppModule = AppModule{} _ module.AppModuleBasic = AppModuleBasic{} @@ -119,12 +123,17 @@ func (am AppModule) LegacyQuerierHandler(_ *codec.LegacyAmino) sdk.Querier { } // ConsensusVersion implements AppModule/ConsensusVersion. -func (AppModule) ConsensusVersion() uint64 { return 1 } +func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion } // RegisterServices registers module services. func (am AppModule) RegisterServices(cfg module.Configurator) { types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQueryServerImpl(am.keeper)) + + m := keeper.NewMigrator(am.keeper) + if err := cfg.RegisterMigration(types.ModuleName, 1, m.Migrate1to2); err != nil { + panic(fmt.Sprintf("failed to migrate x/community from version 1 to 2: %v", err)) + } } // InitGenesis module init-genesis diff --git a/x/community/types/params.go b/x/community/types/params.go index 9d6518b01e..aed1553187 100644 --- a/x/community/types/params.go +++ b/x/community/types/params.go @@ -1,15 +1,27 @@ package types -import "time" +import ( + "errors" + fmt "fmt" + "time" + + sdkmath "cosmossdk.io/math" +) var ( DefaultUpgradeTimeDisableInflation = time.Time{} + // DefaultStakingRewardsPerSecond is ~4.6 KAVA per block, 6.3s block time + DefaultStakingRewardsPerSecond = sdkmath.NewInt(744191) ) // NewParams returns a new params object -func NewParams(upgradeTime time.Time) Params { +func NewParams( + upgradeTime time.Time, + stakingRewardsPerSecond sdkmath.Int, +) Params { return Params{ UpgradeTimeDisableInflation: upgradeTime, + StakingRewardsPerSecond: stakingRewardsPerSecond, } } @@ -17,10 +29,19 @@ func NewParams(upgradeTime time.Time) Params { func DefaultParams() Params { return NewParams( DefaultUpgradeTimeDisableInflation, + DefaultStakingRewardsPerSecond, ) } // Validate checks the params are valid func (p Params) Validate() error { + if p.StakingRewardsPerSecond.IsNil() { + return errors.New("StakingRewardsPerSecond should not be nil") + } + + if p.StakingRewardsPerSecond.IsNegative() { + return fmt.Errorf("StakingRewardsPerSecond should not be negative: %s", p.StakingRewardsPerSecond) + } + return nil } diff --git a/x/community/types/params.pb.go b/x/community/types/params.pb.go index bc31ad1c91..a1be284e86 100644 --- a/x/community/types/params.pb.go +++ b/x/community/types/params.pb.go @@ -4,7 +4,9 @@ package types import ( + cosmossdk_io_math "cosmossdk.io/math" fmt "fmt" + _ "github.com/cosmos/cosmos-proto" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" @@ -29,7 +31,8 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // Params defines the parameters of the community module. type Params struct { - UpgradeTimeDisableInflation time.Time `protobuf:"bytes,1,opt,name=upgrade_time_disable_inflation,json=upgradeTimeDisableInflation,proto3,stdtime" json:"upgrade_time_disable_inflation"` + UpgradeTimeDisableInflation time.Time `protobuf:"bytes,1,opt,name=upgrade_time_disable_inflation,json=upgradeTimeDisableInflation,proto3,stdtime" json:"upgrade_time_disable_inflation"` + StakingRewardsPerSecond cosmossdk_io_math.Int `protobuf:"bytes,2,opt,name=staking_rewards_per_second,json=stakingRewardsPerSecond,proto3,customtype=cosmossdk.io/math.Int" json:"staking_rewards_per_second"` } func (m *Params) Reset() { *m = Params{} } @@ -81,23 +84,28 @@ func init() { } var fileDescriptor_0a48475520900507 = []byte{ - // 251 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0xc1, 0x4a, 0x03, 0x31, - 0x10, 0x86, 0x37, 0x97, 0x22, 0xeb, 0xad, 0x88, 0xc8, 0x0a, 0x59, 0xd1, 0x8b, 0x20, 0x26, 0x54, - 0xdf, 0xa0, 0xe8, 0xc1, 0x9b, 0x88, 0x27, 0x2f, 0xcb, 0xc4, 0xa6, 0x31, 0xb8, 0xd9, 0x84, 0xcd, - 0x6c, 0xb1, 0x6f, 0xd1, 0xc7, 0xea, 0xb1, 0x47, 0x4f, 0x2a, 0xbb, 0x2f, 0x22, 0x49, 0xba, 0xe2, - 0xed, 0x1f, 0xe6, 0xe3, 0x63, 0xfe, 0xc9, 0x2f, 0xde, 0x61, 0x05, 0xfc, 0xd5, 0x1a, 0xd3, 0x35, - 0x1a, 0xd7, 0x7c, 0x35, 0x13, 0x12, 0x61, 0xc6, 0x1d, 0xb4, 0x60, 0x3c, 0x73, 0xad, 0x45, 0x3b, - 0x3d, 0x0e, 0x10, 0xfb, 0x83, 0xd8, 0x1e, 0x2a, 0x8e, 0x94, 0x55, 0x36, 0x22, 0x3c, 0xa4, 0x44, - 0x17, 0xa5, 0xb2, 0x56, 0xd5, 0x92, 0xc7, 0x49, 0x74, 0x4b, 0x8e, 0xda, 0x48, 0x8f, 0x60, 0x5c, - 0x02, 0xce, 0x7d, 0x3e, 0x79, 0x8c, 0xfa, 0xa9, 0xce, 0x69, 0xe7, 0x54, 0x0b, 0x0b, 0x59, 0x05, - 0xa8, 0x5a, 0x68, 0x0f, 0xa2, 0x96, 0x95, 0x6e, 0x96, 0x35, 0xa0, 0xb6, 0xcd, 0x09, 0x39, 0x23, - 0x97, 0x87, 0x37, 0x05, 0x4b, 0x4e, 0x36, 0x3a, 0xd9, 0xf3, 0xe8, 0x9c, 0x1f, 0x6c, 0xbf, 0xca, - 0x6c, 0xf3, 0x5d, 0x92, 0xa7, 0xd3, 0xbd, 0x2b, 0xec, 0xee, 0x92, 0xe9, 0x61, 0x14, 0xcd, 0xef, - 0xb7, 0x3d, 0x25, 0xbb, 0x9e, 0x92, 0x9f, 0x9e, 0x92, 0xcd, 0x40, 0xb3, 0xdd, 0x40, 0xb3, 0xcf, - 0x81, 0x66, 0x2f, 0x57, 0x4a, 0xe3, 0x5b, 0x27, 0x42, 0x3f, 0x1e, 0x8a, 0x5e, 0xd7, 0x20, 0x7c, - 0x4c, 0xfc, 0xe3, 0xdf, 0x67, 0x70, 0xed, 0xa4, 0x17, 0x93, 0x78, 0xc1, 0xed, 0x6f, 0x00, 0x00, - 0x00, 0xff, 0xff, 0x17, 0xd9, 0x52, 0x52, 0x38, 0x01, 0x00, 0x00, + // 336 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x91, 0xcf, 0x4e, 0x2a, 0x31, + 0x14, 0x87, 0xa7, 0x77, 0x41, 0xae, 0xe3, 0x8e, 0xf8, 0x07, 0xc7, 0x64, 0x86, 0xe8, 0x86, 0x84, + 0xd0, 0x06, 0x7d, 0x03, 0xa2, 0x0b, 0x76, 0x04, 0x5d, 0xb9, 0x69, 0x3a, 0x4c, 0x29, 0x0d, 0xd3, + 0x76, 0xd2, 0x76, 0x50, 0xde, 0x82, 0x87, 0xf1, 0x21, 0x58, 0x12, 0x57, 0xc6, 0x44, 0x34, 0xf0, + 0x22, 0xa6, 0xd3, 0xc1, 0xb8, 0x3b, 0xe7, 0xf4, 0xeb, 0xd7, 0xfc, 0x4e, 0xc3, 0xeb, 0x39, 0x59, + 0x10, 0x34, 0x51, 0x42, 0x94, 0x92, 0xdb, 0x25, 0x5a, 0xf4, 0x53, 0x6a, 0x49, 0x1f, 0x15, 0x44, + 0x13, 0x61, 0x60, 0xa1, 0x95, 0x55, 0xcd, 0x33, 0x07, 0xc1, 0x5f, 0x08, 0xd6, 0x50, 0x74, 0x31, + 0x51, 0x46, 0x28, 0x83, 0x2b, 0x0a, 0xf9, 0xc6, 0x5f, 0x89, 0x4e, 0x98, 0x62, 0xca, 0xcf, 0x5d, + 0x55, 0x4f, 0x13, 0xa6, 0x14, 0xcb, 0x29, 0xaa, 0xba, 0xb4, 0x9c, 0x22, 0xcb, 0x05, 0x35, 0x96, + 0x88, 0xc2, 0x03, 0x57, 0x9f, 0x20, 0x6c, 0x8c, 0xaa, 0xa7, 0x9b, 0x3c, 0x8c, 0xcb, 0x82, 0x69, + 0x92, 0x51, 0xec, 0x28, 0x9c, 0x71, 0x43, 0xd2, 0x9c, 0x62, 0x2e, 0xa7, 0x39, 0xb1, 0x5c, 0xc9, + 0x16, 0x68, 0x83, 0xce, 0xf1, 0x4d, 0x04, 0xbd, 0x14, 0x1e, 0xa4, 0xf0, 0xf1, 0x20, 0x1d, 0xfc, + 0x5f, 0x6f, 0x93, 0x60, 0xf5, 0x95, 0x80, 0xf1, 0x65, 0xed, 0x72, 0x67, 0x77, 0xde, 0x34, 0x3c, + 0x88, 0x9a, 0xb3, 0x30, 0x32, 0x96, 0xcc, 0xb9, 0x64, 0x58, 0xd3, 0x67, 0xa2, 0x33, 0x83, 0x0b, + 0xaa, 0xb1, 0xa1, 0x13, 0x25, 0xb3, 0xd6, 0xbf, 0x36, 0xe8, 0x1c, 0x0d, 0xba, 0x4e, 0xf5, 0xb1, + 0x4d, 0x4e, 0x7d, 0x4c, 0x93, 0xcd, 0x21, 0x57, 0x48, 0x10, 0x3b, 0x83, 0x43, 0x69, 0xdf, 0x5e, + 0x7b, 0x61, 0x9d, 0x7f, 0x28, 0xed, 0xf8, 0xbc, 0xd6, 0x8d, 0xbd, 0x6d, 0x44, 0xf5, 0x43, 0xe5, + 0x1a, 0xdc, 0xaf, 0x77, 0x31, 0xd8, 0xec, 0x62, 0xf0, 0xbd, 0x8b, 0xc1, 0x6a, 0x1f, 0x07, 0x9b, + 0x7d, 0x1c, 0xbc, 0xef, 0xe3, 0xe0, 0xa9, 0xcb, 0xb8, 0x9d, 0x95, 0xa9, 0xdb, 0x32, 0x72, 0xeb, + 0xee, 0xe5, 0x24, 0x35, 0x55, 0x85, 0x5e, 0xfe, 0xfc, 0x8f, 0x5d, 0x16, 0xd4, 0xa4, 0x8d, 0x2a, + 0xeb, 0xed, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xc5, 0xad, 0xf1, 0xc6, 0xbe, 0x01, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -120,6 +128,16 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + { + size := m.StakingRewardsPerSecond.Size() + i -= size + if _, err := m.StakingRewardsPerSecond.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 n1, err1 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.UpgradeTimeDisableInflation, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.UpgradeTimeDisableInflation):]) if err1 != nil { return 0, err1 @@ -150,6 +168,8 @@ func (m *Params) Size() (n int) { _ = l l = github_com_gogo_protobuf_types.SizeOfStdTime(m.UpgradeTimeDisableInflation) n += 1 + l + sovParams(uint64(l)) + l = m.StakingRewardsPerSecond.Size() + n += 1 + l + sovParams(uint64(l)) return n } @@ -221,6 +241,40 @@ func (m *Params) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field StakingRewardsPerSecond", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.StakingRewardsPerSecond.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipParams(dAtA[iNdEx:]) diff --git a/x/community/types/params_test.go b/x/community/types/params_test.go new file mode 100644 index 0000000000..9b141c524e --- /dev/null +++ b/x/community/types/params_test.go @@ -0,0 +1,57 @@ +package types_test + +import ( + "testing" + "time" + + "github.com/stretchr/testify/require" + + sdkmath "cosmossdk.io/math" + "github.com/kava-labs/kava/x/community/types" +) + +func TestParamsValidate(t *testing.T) { + testCases := []struct { + name string + params types.Params + expectedErr string + }{ + { + name: "valid parms", + params: types.Params{ + UpgradeTimeDisableInflation: time.Time{}, + StakingRewardsPerSecond: sdkmath.NewInt(1000), + }, + expectedErr: "", + }, + { + name: "nil rewards per second", + params: types.Params{ + UpgradeTimeDisableInflation: time.Time{}, + StakingRewardsPerSecond: sdkmath.Int{}, + }, + expectedErr: "StakingRewardsPerSecond should not be nil", + }, + { + name: "negative rewards per second", + params: types.Params{ + UpgradeTimeDisableInflation: time.Time{}, + StakingRewardsPerSecond: sdkmath.NewInt(-5), + }, + expectedErr: "StakingRewardsPerSecond should not be negative", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + err := tc.params.Validate() + + if tc.expectedErr == "" { + require.NoError(t, err) + } else { + require.Error(t, err) + require.Contains(t, err.Error(), tc.expectedErr) + } + }) + } +}