Skip to content

Commit

Permalink
test: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
snobbee committed Nov 15, 2023
1 parent 0f1a88b commit 58d1c00
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 8 deletions.
38 changes: 38 additions & 0 deletions testutil/keeper/epochs.go
Original file line number Diff line number Diff line change
@@ -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
}
16 changes: 8 additions & 8 deletions x/epochs/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 58d1c00

Please sign in to comment.