0g-chain/x/community/keeper/params_test.go
Ruaridh bc260d8091
feat(community): add switchover param (#1704)
* add community params type

* add get/set params methods

* add community genesis state type

* add community init/export genesis

* add querier methods for params

* add query cli cmd

* update changelog

* update protonet genesis

* Add `RewardsPerSecond` param to `x/community` module (#1707)

* Add RewardsPerSecond param to community

* Update rewards per second param to int

* Add rewards_per_second to protonet genesis

* Use default rewards per second of 744191

* Include value if negative in Validate error

* Rename RewardsPerSecond param to StakingRewardsPerSecond

* Add changelog entry

* Add param migration, update consensus version to 2

* Update proto docs

* Update staking_rewards_per_second param name in protonet genesis (#1730)

* Update godoc

Co-authored-by: Robert Pirtle <Astropirtle@gmail.com>

* add genesis state tests

* document what 0 upgrade time means

* update kvtool to include new params

---------

Co-authored-by: drklee3 <derrick@dlee.dev>
Co-authored-by: Robert Pirtle <Astropirtle@gmail.com>
2023-09-22 09:05:12 -07:00

75 lines
2.0 KiB
Go

package keeper_test
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"
tmtime "github.com/tendermint/tendermint/types/time"
"github.com/kava-labs/kava/app"
"github.com/kava-labs/kava/x/community/keeper"
"github.com/kava-labs/kava/x/community/types"
)
// Test suite used for all store tests
type StoreTestSuite struct {
suite.Suite
App app.TestApp
Ctx sdk.Context
Keeper keeper.Keeper
}
// The default state used by each test
func (suite *StoreTestSuite) SetupTest() {
app.SetSDKConfig()
suite.App = app.NewTestApp()
suite.Ctx = suite.App.NewContext(true, tmproto.Header{Height: 1, Time: tmtime.Now()})
suite.Keeper = suite.App.GetCommunityKeeper()
}
func TestStoreTestSuite(t *testing.T) {
suite.Run(t, new(StoreTestSuite))
}
func (suite *StoreTestSuite) TestGetSetParams() {
suite.Run("get params returns not found on empty store", func() {
_, found := suite.Keeper.GetParams(suite.Ctx)
suite.Require().False(found)
})
suite.Run("set params cannot store invalid params", func() {
invalid := types.Params{UpgradeTimeDisableInflation: time.Date(-1, 1, 1, 0, 0, 0, 0, time.UTC)}
suite.Panics(func() {
suite.Keeper.SetParams(suite.Ctx, invalid)
})
})
suite.Run("get params returns stored params", func() {
suite.Keeper.SetParams(suite.Ctx, types.DefaultParams())
storedParams, found := suite.Keeper.GetParams(suite.Ctx)
suite.True(found)
suite.Equal(types.DefaultParams(), storedParams)
})
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),
sdkmath.NewInt(1000),
)
suite.Keeper.SetParams(suite.Ctx, params)
storedParams, found := suite.Keeper.GetParams(suite.Ctx)
suite.True(found)
suite.NotEqual(params, types.DefaultParams())
suite.Equal(params, storedParams)
})
}