mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-14 03:55:19 +00:00
f37321839b
* add `x/kavamint` module (#1376) * stub out the x/kavamint module * mint staking rewards in x/kavamint BeginBlocker * calculate cumulative inflation from x/kavamint * cleanup, abstract bond denom, grpc query tests * store & use previous block time to calculate mints * move test suite to testutil * add test of x/kavamint BeginBlocker * cleanup & comments from @DracoLi review * fix x/incentive integration test * remove rest client grpc test * add x/kavamint module spec * track previous block time in genesis * suggested cleanup from PR review * bugfix incorrect module account check * add x/community module (#1388) * add x/community module * refactor and setup fund-community-pool tx * remove unused features (params, genesis state) * test x/community query and message * update with master branch deps * updates from review * indicate deprecated methods on module (still needed to fulfill interface) * remove legacy querier * derive msg Route() and Type() from sdk.MsgTypeURL(&msg) * use module name for message Route() * mint community pool inflation in x/kavamint (#1389) * mint community pool inflation in x/kavamint * refactor x/kavamint abci inflation test * test inflation from x/kavamint * default kavamint rates to 0% * rename kavamint account name variables * panic if genesis kavamint previous block time not set * emit event on kavamint begin blocker * add kavamint year of inflation sanity check test * update fund_community_pool message event * add x/community spec * refactor inflation accumulation into single func * use new comm pool in kavadist multispend proposal (#1403) the x/community module houses the new community pool. this commit points the CommunityPoolMultiSpendProposal at the new community pool so that multispend proposals can continue to be processed once original fee pool funds are move to x/community * updates from proto lint changes * update earn proposals to use new community pool originally the CommunityPoolDepositProposal & CommunityPoolWithdrawProposal used the vanilla community pool fee pool. this commit updates them both to use the new x/community module account. * spec formatting update * add x/community & x/kavamint to internal testnet genesis * increase test coverage of x/kavamint * increase test coverage of x/community * use string type for sdk.Dec proto fields; disable generation of getters for genesis and params (and other store objects) * follow sdk conventions for params endpoint naming * add kavamint to swagger; update swagger & proto docs * remove legacy querier; touch up module to match others * reduce max minting rate; refactor genesis to allow nil/zero block time; repace proto stringers and remove getters; keep sdk.Dec values strings in protos; increase validation of sdk.Dec values in params; increase coverage; add module account permission checks; ensure import and export of genesis does not change state * fix scaling of rate values -- should be yearly rates * revert key change * fix typo in test name * fix regression in running tests -- rename method Co-authored-by: Nick DeLuca <nickdeluca08@gmail.com>
118 lines
4.0 KiB
Go
118 lines
4.0 KiB
Go
package kavamint_test
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/kava-labs/kava/x/kavamint"
|
|
"github.com/kava-labs/kava/x/kavamint/testutil"
|
|
"github.com/kava-labs/kava/x/kavamint/types"
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
|
)
|
|
|
|
type genesisTestSuite struct {
|
|
testutil.KavamintTestSuite
|
|
}
|
|
|
|
func (suite *genesisTestSuite) Test_InitGenesis_ValidationPanic() {
|
|
invalidState := types.NewGenesisState(
|
|
types.NewParams(sdk.OneDec(), types.MaxMintingRate.Add(sdk.OneDec())), // rate over max
|
|
time.Time{},
|
|
)
|
|
|
|
suite.Panics(func() {
|
|
kavamint.InitGenesis(suite.Ctx, suite.Keeper, suite.App.GetAccountKeeper(), invalidState)
|
|
}, "expected init genesis to panic with invalid state")
|
|
}
|
|
|
|
func (suite *genesisTestSuite) Test_InitGenesis_ModuleAccountDoesNotHaveMinterPerms() {
|
|
gs := types.DefaultGenesisState()
|
|
|
|
ak := suite.App.GetAccountKeeper()
|
|
macc := ak.GetModuleAccount(suite.Ctx, types.ModuleName)
|
|
suite.Require().NotNil(macc)
|
|
|
|
m, ok := macc.(*authtypes.ModuleAccount)
|
|
suite.Require().True(ok)
|
|
|
|
m.Permissions = []string{}
|
|
ak.SetAccount(suite.Ctx, m)
|
|
|
|
suite.PanicsWithValue("kavamint module account does not have minter permissions", func() {
|
|
kavamint.InitGenesis(suite.Ctx, suite.Keeper, suite.App.GetAccountKeeper(), gs)
|
|
})
|
|
}
|
|
|
|
func (suite *genesisTestSuite) Test_InitGenesis_CreatesModuleAccountWithPermissions() {
|
|
gs := types.DefaultGenesisState()
|
|
ak := suite.App.GetAccountKeeper()
|
|
|
|
kavamint.InitGenesis(suite.Ctx, suite.Keeper, ak, gs)
|
|
|
|
// by pass auto creation of module accounts
|
|
addr, _ := ak.GetModuleAddressAndPermissions(types.ModuleName)
|
|
acc := suite.App.GetAccountKeeper().GetAccount(suite.Ctx, addr)
|
|
suite.Require().NotNil(acc)
|
|
|
|
macc, ok := acc.(authtypes.ModuleAccountI)
|
|
suite.Require().True(ok)
|
|
|
|
suite.True(macc.HasPermission(authtypes.Minter))
|
|
}
|
|
|
|
func (suite *genesisTestSuite) Test_InitAndExportGenesis_DefaultValues() {
|
|
state := types.DefaultGenesisState()
|
|
|
|
kavamint.InitGenesis(suite.Ctx, suite.Keeper, suite.App.GetAccountKeeper(), state)
|
|
|
|
suite.Equal(types.DefaultParams(), suite.Keeper.GetParams(suite.Ctx), "expected default params to bet set in store")
|
|
|
|
storeTime := suite.Keeper.GetPreviousBlockTime(suite.Ctx)
|
|
suite.Equal(types.DefaultPreviousBlockTime, storeTime, "expected default previous block time to be set in store")
|
|
|
|
exportedState := kavamint.ExportGenesis(suite.Ctx, suite.Keeper)
|
|
suite.Equal(state, exportedState, "expected exported state to match imported state")
|
|
}
|
|
|
|
func (suite *genesisTestSuite) Test_InitAndExportGenesis_SetValues() {
|
|
prevBlockTime := time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC)
|
|
state := types.NewGenesisState(
|
|
types.NewParams(sdk.MustNewDecFromStr("0.000000000000000001"), sdk.MustNewDecFromStr("0.000000000000000002")),
|
|
prevBlockTime,
|
|
)
|
|
|
|
kavamint.InitGenesis(suite.Ctx, suite.Keeper, suite.App.GetAccountKeeper(), state)
|
|
|
|
suite.Equal(state.Params, suite.Keeper.GetParams(suite.Ctx), "expected params to bet set in store")
|
|
|
|
storeTime := suite.Keeper.GetPreviousBlockTime(suite.Ctx)
|
|
suite.Equal(state.PreviousBlockTime, storeTime, "expected previous block time to be set in store")
|
|
|
|
exportedState := kavamint.ExportGenesis(suite.Ctx, suite.Keeper)
|
|
suite.Equal(state, exportedState, "expected exported state to match imported state")
|
|
}
|
|
|
|
func (suite *genesisTestSuite) Test_InitAndExportGenesis_ZeroValues() {
|
|
state := types.NewGenesisState(
|
|
types.NewParams(sdk.ZeroDec(), sdk.ZeroDec()),
|
|
time.Time{},
|
|
)
|
|
|
|
kavamint.InitGenesis(suite.Ctx, suite.Keeper, suite.App.GetAccountKeeper(), state)
|
|
|
|
suite.Equal(state.Params, suite.Keeper.GetParams(suite.Ctx), "expected params to bet set in store")
|
|
|
|
storeTime := suite.Keeper.GetPreviousBlockTime(suite.Ctx)
|
|
suite.Equal(state.PreviousBlockTime, storeTime, "expected previous block time to be set in store")
|
|
|
|
exportedState := kavamint.ExportGenesis(suite.Ctx, suite.Keeper)
|
|
suite.Equal(state, exportedState, "expected exported state to match imported state")
|
|
}
|
|
|
|
func TestGenesisTestSuite(t *testing.T) {
|
|
suite.Run(t, new(genesisTestSuite))
|
|
}
|