2022-01-08 00:39:27 +00:00
|
|
|
package kavadist_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
|
2024-02-06 22:54:10 +00:00
|
|
|
tmtime "github.com/cometbft/cometbft/types/time"
|
2022-01-08 00:39:27 +00:00
|
|
|
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
|
|
|
|
"github.com/kava-labs/kava/x/kavadist"
|
|
|
|
testutil "github.com/kava-labs/kava/x/kavadist/testutil"
|
|
|
|
"github.com/kava-labs/kava/x/kavadist/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
type genesisTestSuite struct {
|
|
|
|
testutil.Suite
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *genesisTestSuite) TestInitGenesis_ValidationPanic() {
|
|
|
|
invalidState := types.NewGenesisState(
|
|
|
|
types.Params{
|
|
|
|
Active: true,
|
|
|
|
Periods: []types.Period{
|
|
|
|
{
|
|
|
|
Start: time.Date(2021, 1, 1, 1, 1, 1, 1, time.UTC),
|
|
|
|
End: tmtime.Canonical(time.Unix(1, 0)),
|
|
|
|
Inflation: sdk.OneDec(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
tmtime.Canonical(time.Unix(1, 0)),
|
|
|
|
)
|
|
|
|
|
|
|
|
suite.Require().Panics(func() {
|
|
|
|
kavadist.InitGenesis(suite.Ctx, suite.Keeper, suite.AccountKeeper, invalidState)
|
|
|
|
}, "expected init genesis to panic with invalid state")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *genesisTestSuite) TestInitAndExportGenesis() {
|
|
|
|
state := types.NewGenesisState(
|
|
|
|
types.Params{
|
|
|
|
Active: true,
|
|
|
|
Periods: []types.Period{
|
|
|
|
{
|
|
|
|
Start: time.Date(2021, 1, 1, 1, 1, 1, 1, time.UTC),
|
|
|
|
End: time.Date(2021, 2, 1, 1, 1, 1, 1, time.UTC),
|
|
|
|
Inflation: sdk.OneDec(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
time.Date(2020, 1, 2, 1, 1, 1, 1, time.UTC),
|
|
|
|
)
|
|
|
|
|
|
|
|
kavadist.InitGenesis(suite.Ctx, suite.Keeper, suite.AccountKeeper, state)
|
|
|
|
suite.Require().Equal(state.Params, suite.Keeper.GetParams(suite.Ctx))
|
|
|
|
|
|
|
|
exportedState := kavadist.ExportGenesis(suite.Ctx, suite.Keeper)
|
|
|
|
suite.Require().Equal(state, exportedState)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGenesisTestSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(genesisTestSuite))
|
|
|
|
}
|