0g-chain/x/community/keeper/params_test.go
Nick DeLuca 102cc0fff3
Community Pool Staking Rewards Implementation & Improvements (#1742)
* add new field upgrade_time_set_staking_rewards_per_second with intention
of integrating into the disable inflation logic to set an initial
staking reward time

* when the disable inflation upgrade time occurs, set the staking rewards
per second to the value specified by the new
upgrade_time_set_staking_rewards_per_second.  This will allow a decoupled
implementation between the ugprade switching logic, and the core
functionality of paying staking rewards from the pool

* add staking rewards state to community keeper and community module
genesis that is required to calculate and track staking reward payouts
accross blocks

* add implementation of staking reward payouts

* remove unused error

* touch up tests and add a test case that fully tests behavior when pool
is drained

* add function comments

* refactor and pull out main calculation to private pure function with
no dependence on keeper

* zero out default parameters -- these are too chain specific to have
useful defaults

* small touch ups on comments, test cases

* use correct Int from sdkmath, not old sdk types; update protonet genesis
for new parmater

* fix copy pasta comment

* use bond denom from staking keeper instead of referncing ukava directly

* add staking reward state for valid genesis

* update kvtool genesis for new params and rewards state
2023-10-03 08:41:54 -07:00

76 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.LegacyNewDec(1000),
sdkmath.LegacyNewDec(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)
})
}