diff --git a/testutil/keeper/epochs.go b/testutil/keeper/epochs.go new file mode 100644 index 0000000000..3940c6b297 --- /dev/null +++ b/testutil/keeper/epochs.go @@ -0,0 +1,38 @@ +package keeper + +import ( + "testing" + + "github.com/Sifchain/sifnode/x/epochs/keeper" + "github.com/Sifchain/sifnode/x/epochs/types" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/store" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/libs/log" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + tmdb "github.com/tendermint/tm-db" +) + +func EpochsKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) { + storeKey := sdk.NewKVStoreKey(types.StoreKey) + + db := tmdb.NewMemDB() + stateStore := store.NewCommitMultiStore(db) + stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db) + require.NoError(t, stateStore.LoadLatestVersion()) + + registry := codectypes.NewInterfaceRegistry() + cdc := codec.NewProtoCodec(registry) + + k := keeper.NewKeeper( + cdc, + storeKey, + ) + + ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger()) + + return k, ctx +} diff --git a/x/epochs/genesis_test.go b/x/epochs/genesis_test.go index d0af2f00c4..db43d084ee 100644 --- a/x/epochs/genesis_test.go +++ b/x/epochs/genesis_test.go @@ -52,14 +52,14 @@ func TestEpochsExportGenesis(t *testing.T) { genesis := epochs.ExportGenesis(ctx, app.EpochsKeeper) require.Len(t, genesis.Epochs, 3) - require.Equal(t, genesis.Epochs[0].Identifier, types.HourEpochID) - require.Equal(t, genesis.Epochs[1].Identifier, types.DayEpochID) - require.Equal(t, genesis.Epochs[1].StartTime, chainStartTime) - require.Equal(t, genesis.Epochs[1].Duration, time.Hour*24) - require.Equal(t, genesis.Epochs[1].CurrentEpoch, int64(0)) - require.Equal(t, genesis.Epochs[1].CurrentEpochStartHeight, chainStartHeight) - require.Equal(t, genesis.Epochs[1].CurrentEpochStartTime, chainStartTime) - require.Equal(t, genesis.Epochs[1].EpochCountingStarted, false) + require.Equal(t, genesis.Epochs[1].Identifier, types.HourEpochID) + require.Equal(t, genesis.Epochs[0].Identifier, types.DayEpochID) + require.Equal(t, genesis.Epochs[0].StartTime, chainStartTime) + require.Equal(t, genesis.Epochs[0].Duration, time.Hour*24) + require.Equal(t, genesis.Epochs[0].CurrentEpoch, int64(0)) + require.Equal(t, genesis.Epochs[0].CurrentEpochStartHeight, chainStartHeight) + require.Equal(t, genesis.Epochs[0].CurrentEpochStartTime, chainStartTime) + require.Equal(t, genesis.Epochs[0].EpochCountingStarted, false) require.Equal(t, genesis.Epochs[2].Identifier, types.WeekEpochID) require.Equal(t, genesis.Epochs[2].StartTime, chainStartTime) require.Equal(t, genesis.Epochs[2].Duration, time.Hour*24*7)