mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-14 03:55:19 +00:00
67 lines
1.6 KiB
Go
67 lines
1.6 KiB
Go
|
package kavadist_test
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
"time"
|
||
|
|
||
|
"github.com/stretchr/testify/suite"
|
||
|
|
||
|
tmtime "github.com/tendermint/tendermint/types/time"
|
||
|
|
||
|
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))
|
||
|
}
|