-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
epoching: keeper functions, queries, and testing infra (#19)
- Loading branch information
1 parent
a0e0200
commit aa07c40
Showing
9 changed files
with
309 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package keeper | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/babylonchain/babylon/x/epoching/keeper" | ||
"github.com/babylonchain/babylon/x/epoching/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" | ||
typesparams "github.com/cosmos/cosmos-sdk/x/params/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 EpochingKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) { | ||
storeKey := sdk.NewKVStoreKey(types.StoreKey) | ||
memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey) | ||
|
||
db := tmdb.NewMemDB() | ||
stateStore := store.NewCommitMultiStore(db) | ||
stateStore.MountStoreWithDB(storeKey, sdk.StoreTypeIAVL, db) | ||
stateStore.MountStoreWithDB(memStoreKey, sdk.StoreTypeMemory, nil) | ||
require.NoError(t, stateStore.LoadLatestVersion()) | ||
|
||
registry := codectypes.NewInterfaceRegistry() | ||
cdc := codec.NewProtoCodec(registry) | ||
|
||
paramsSubspace := typesparams.NewSubspace(cdc, | ||
types.Amino, | ||
storeKey, | ||
memStoreKey, | ||
"EpochingParams", | ||
) | ||
k := keeper.NewKeeper( | ||
cdc, | ||
storeKey, | ||
memStoreKey, | ||
paramsSubspace, | ||
) | ||
|
||
ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger()) | ||
|
||
// Initialize params | ||
k.SetParams(ctx, types.DefaultParams()) | ||
|
||
return &k, ctx | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,22 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"testing" | ||
|
||
testkeeper "github.com/babylonchain/babylon/testutil/keeper" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/babylonchain/babylon/x/epoching/types" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestParamsQuery(t *testing.T) { | ||
keeper, ctx := testkeeper.EpochingKeeper(t) | ||
wctx := sdk.WrapSDKContext(ctx) | ||
params := types.DefaultParams() | ||
keeper.SetParams(ctx, params) | ||
|
||
response, err := keeper.Params(wctx, &types.QueryParamsRequest{}) | ||
require.NoError(t, err) | ||
require.Equal(t, &types.QueryParamsResponse{Params: params}, response) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package keeper_test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,16 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
keepertest "github.com/babylonchain/babylon/testutil/keeper" | ||
"github.com/babylonchain/babylon/x/epoching/keeper" | ||
"github.com/babylonchain/babylon/x/epoching/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
func setupMsgServer(t testing.TB) (types.MsgServer, context.Context) { | ||
k, ctx := keepertest.EpochingKeeper(t) | ||
return keeper.NewMsgServerImpl(*k), sdk.WrapSDKContext(ctx) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,18 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"testing" | ||
|
||
testkeeper "github.com/babylonchain/babylon/testutil/keeper" | ||
"github.com/babylonchain/babylon/x/epoching/types" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestGetParams(t *testing.T) { | ||
k, ctx := testkeeper.EpochingKeeper(t) | ||
params := types.DefaultParams() | ||
|
||
k.SetParams(ctx, params) | ||
|
||
require.EqualValues(t, params, k.GetParams(ctx)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.