Skip to content

Commit

Permalink
fix compilation err at setup_test
Browse files Browse the repository at this point in the history
  • Loading branch information
taryune committed Feb 28, 2024
1 parent 5c192a1 commit 8a64606
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 107 deletions.
22 changes: 7 additions & 15 deletions testutil/keeper/epochs.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ import (

"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/runtime"
sdk "github.com/cosmos/cosmos-sdk/types"
typesparams "github.com/cosmos/cosmos-sdk/x/params/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"

"github.com/mycel-domain/mycel/x/epochs/keeper"
"github.com/mycel-domain/mycel/x/epochs/types"
Expand All @@ -27,34 +29,24 @@ func EpochsKeeper(tb testing.TB) (*keeper.Keeper, sdk.Context) {
tb.Helper()

storeKey := storetypes.NewKVStoreKey(types.StoreKey)
memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey)

db := tmdb.NewMemDB()
stateStore := store.NewCommitMultiStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics())
stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db)
stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil)
require.NoError(tb, stateStore.LoadLatestVersion())

registry := codectypes.NewInterfaceRegistry()
cdc := codec.NewProtoCodec(registry)
authority := authtypes.NewModuleAddress(govtypes.ModuleName)

paramsSubspace := typesparams.NewSubspace(cdc,
types.Amino,
storeKey,
memStoreKey,
"EpochsParams",
)
k := keeper.NewKeeper(
cdc,
storeKey,
memStoreKey,
paramsSubspace,
runtime.NewKVStoreService(storeKey),
log.NewNopLogger(),
authority.String(),
)

ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger())

// Initialize params
k.SetParams(ctx, types.DefaultParams())

return k, ctx
}
19 changes: 7 additions & 12 deletions testutil/keeper/furnace.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ import (

"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/runtime"
sdk "github.com/cosmos/cosmos-sdk/types"
typesparams "github.com/cosmos/cosmos-sdk/x/params/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"

"github.com/mycel-domain/mycel/x/furnace/keeper"
"github.com/mycel-domain/mycel/x/furnace/types"
Expand All @@ -27,28 +29,21 @@ func FurnaceKeeper(tb testing.TB) (*keeper.Keeper, sdk.Context) {
tb.Helper()

storeKey := storetypes.NewKVStoreKey(types.StoreKey)
memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey)

db := tmdb.NewMemDB()
stateStore := store.NewCommitMultiStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics())
stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db)
stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil)
require.NoError(tb, stateStore.LoadLatestVersion())

registry := codectypes.NewInterfaceRegistry()
cdc := codec.NewProtoCodec(registry)
authority := authtypes.NewModuleAddress(govtypes.ModuleName)

paramsSubspace := typesparams.NewSubspace(cdc,
types.Amino,
storeKey,
memStoreKey,
"FurnaceParams",
)
k := keeper.NewKeeper(
cdc,
storeKey,
memStoreKey,
paramsSubspace,
runtime.NewKVStoreService(storeKey),
log.NewNopLogger(),
authority.String(),
nil,
nil,
)
Expand Down
20 changes: 7 additions & 13 deletions testutil/keeper/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ import (

"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/runtime"
sdk "github.com/cosmos/cosmos-sdk/types"
typesparams "github.com/cosmos/cosmos-sdk/x/params/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"

"github.com/mycel-domain/mycel/x/registry/keeper"
"github.com/mycel-domain/mycel/x/registry/types"
Expand All @@ -27,29 +29,21 @@ func RegistryKeeper(tb testing.TB) (*keeper.Keeper, sdk.Context) {
tb.Helper()

storeKey := storetypes.NewKVStoreKey(types.StoreKey)
memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey)

db := tmdb.NewMemDB()
stateStore := store.NewCommitMultiStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics())
stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db)
stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil)
require.NoError(tb, stateStore.LoadLatestVersion())

registry := codectypes.NewInterfaceRegistry()
cdc := codec.NewProtoCodec(registry)
authority := authtypes.NewModuleAddress(govtypes.ModuleName)

paramsSubspace := typesparams.NewSubspace(cdc,
types.Amino,
storeKey,
memStoreKey,
"RegistryParams",
)
k := keeper.NewKeeper(
cdc,
storeKey,
memStoreKey,
paramsSubspace,
nil,
runtime.NewKVStoreService(storeKey),
log.NewNopLogger(),
authority.String(),
nil,
nil,
nil,
Expand Down
129 changes: 65 additions & 64 deletions x/epochs/keeper/query_epoch_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"google.golang.org/grpc/status"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
// "github.com/cosmos/cosmos-sdk/types/query"

keepertest "github.com/mycel-domain/mycel/testutil/keeper"
"github.com/mycel-domain/mycel/testutil/nullify"
Expand All @@ -25,27 +25,27 @@ func TestEpochInfoQuerySingle(t *testing.T) {
msgs := createNEpochInfo(keeper, ctx, 2)
for _, tc := range []struct {
desc string
request *types.QueryGetEpochInfoRequest
response *types.QueryGetEpochInfoResponse
request *types.QueryCurrentEpochRequest
response *types.QueryCurrentEpochResponse
err error
}{
{
desc: "First",
request: &types.QueryGetEpochInfoRequest{
request: &types.QueryCurrentEpochRequest{
Identifier: msgs[0].Identifier,
},
response: &types.QueryGetEpochInfoResponse{EpochInfo: msgs[0]},
response: &types.QueryCurrentEpochResponse{EpochInfo: msgs[0]},
},
{
desc: "Second",
request: &types.QueryGetEpochInfoRequest{
request: &types.QueryCurrentEpochRequest{
Identifier: msgs[1].Identifier,
},
response: &types.QueryGetEpochInfoResponse{EpochInfo: msgs[1]},
response: &types.QueryCurrentEpochResponse{EpochInfo: msgs[1]},
},
{
desc: "KeyNotFound",
request: &types.QueryGetEpochInfoRequest{
request: &types.QueryCurrentEpochRequest{
Identifier: strconv.Itoa(100000),
},
err: status.Error(codes.NotFound, "not found"),
Expand All @@ -56,7 +56,7 @@ func TestEpochInfoQuerySingle(t *testing.T) {
},
} {
t.Run(tc.desc, func(t *testing.T) {
response, err := keeper.EpochInfo(wctx, tc.request)
response, err := keeper.CurrentEpoch(wctx, tc.request)
if tc.err != nil {
require.ErrorIs(t, err, tc.err)
} else {
Expand All @@ -70,58 +70,59 @@ func TestEpochInfoQuerySingle(t *testing.T) {
}
}

func TestEpochInfoQueryPaginated(t *testing.T) {
keeper, ctx := keepertest.EpochsKeeper(t)
wctx := sdk.WrapSDKContext(ctx)
msgs := createNEpochInfo(keeper, ctx, 5)

request := func(next []byte, offset, limit uint64, total bool) *types.QueryAllEpochInfoRequest {
return &types.QueryAllEpochInfoRequest{
Pagination: &query.PageRequest{
Key: next,
Offset: offset,
Limit: limit,
CountTotal: total,
},
}
}
t.Run("ByOffset", func(t *testing.T) {
step := 2
for i := 0; i < len(msgs); i += step {
resp, err := keeper.EpochInfoAll(wctx, request(nil, uint64(i), uint64(step), false))
require.NoError(t, err)
require.LessOrEqual(t, len(resp.EpochInfo), step)
require.Subset(t,
nullify.Fill(msgs),
nullify.Fill(resp.EpochInfo),
)
}
})
t.Run("ByKey", func(t *testing.T) {
step := 2
var next []byte
for i := 0; i < len(msgs); i += step {
resp, err := keeper.EpochInfoAll(wctx, request(next, 0, uint64(step), false))
require.NoError(t, err)
require.LessOrEqual(t, len(resp.EpochInfo), step)
require.Subset(t,
nullify.Fill(msgs),
nullify.Fill(resp.EpochInfo),
)
next = resp.Pagination.NextKey
}
})
t.Run("Total", func(t *testing.T) {
resp, err := keeper.EpochInfoAll(wctx, request(nil, 0, 0, true))
require.NoError(t, err)
require.Equal(t, len(msgs), int(resp.Pagination.Total))
require.ElementsMatch(t,
nullify.Fill(msgs),
nullify.Fill(resp.EpochInfo),
)
})
t.Run("InvalidRequest", func(t *testing.T) {
_, err := keeper.EpochInfoAll(wctx, nil)
require.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request"))
})
}
//
// func TestEpochInfoQueryPaginated(t *testing.T) {
// keeper, ctx := keepertest.EpochsKeeper(t)
// wctx := sdk.WrapSDKContext(ctx)
// msgs := createNEpochInfo(keeper, ctx, 5)
//
// request := func(next []byte, offset, limit uint64, total bool) *types.QueryEpochsInfoRequest {
// return &types.QueryEpochsInfoRequest{
// Pagination: &query.PageRequest{
// Key: next,
// Offset: offset,
// Limit: limit,
// CountTotal: total,
// },
// }
// }
// t.Run("ByOffset", func(t *testing.T) {
// step := 2
// for i := 0; i < len(msgs); i += step {
// resp, err := keeper.EpochInfos(wctx, request(nil, uint64(i), uint64(step), false))
// require.NoError(t, err)
// require.LessOrEqual(t, len(resp.EpochInfo), step)
// require.Subset(t,
// nullify.Fill(msgs),
// nullify.Fill(resp.EpochInfo),
// )
// }
// })
// t.Run("ByKey", func(t *testing.T) {
// step := 2
// var next []byte
// for i := 0; i < len(msgs); i += step {
// resp, err := keeper.EpochInfos(wctx, request(next, 0, uint64(step), false))
// require.NoError(t, err)
// require.LessOrEqual(t, len(resp.Epochs), step)
// require.Subset(t,
// nullify.Fill(msgs),
// nullify.Fill(resp.Epochs),
// )
// next = resp.Pagination.NextKey
// }
// })
// t.Run("Total", func(t *testing.T) {
// resp, err := keeper.EpochInfos(wctx, request(nil, 0, 0, true))
// require.NoError(t, err)
// require.Equal(t, len(msgs), int(resp.Pagination.Total))
// require.ElementsMatch(t,
// nullify.Fill(msgs),
// nullify.Fill(resp.Epochs),
// )
// })
// t.Run("InvalidRequest", func(t *testing.T) {
// _, err := keeper.EpochInfos(wctx, nil)
// require.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request"))
// })
// }
6 changes: 5 additions & 1 deletion x/epochs/keeper/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (

"github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"

Check failure on line 10 in x/epochs/keeper/setup_test.go

View workflow job for this annotation

GitHub Actions / lint

"github.com/cosmos/cosmos-sdk/x/auth/types" imported as authtypes and not used (typecheck)

Check failure on line 10 in x/epochs/keeper/setup_test.go

View workflow job for this annotation

GitHub Actions / go

"github.com/cosmos/cosmos-sdk/x/auth/types" imported as authtypes and not used
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"

mycelapp "github.com/mycel-domain/mycel/app"
"github.com/mycel-domain/mycel/x/epochs/types"
Expand All @@ -32,10 +34,12 @@ func (suite *KeeperTestSuite) SetupTest() {
app := mycelapp.Setup(suite.T(), false)
ctx := app.BaseApp.NewContext(false)

app.BankKeeper.SetParams(ctx, banktypes.DefaultParams())

suite.app = app
suite.ctx = ctx

queryHelper := baseapp.NewQueryServerTestHelper(suite.ctx, suite.app.InterfaceRegistry())
queryHelper := baseapp.NewQueryServerTestHelper(suite.ctx, suite.app.AppCodec().InterfaceRegistry())
types.RegisterQueryServer(queryHelper, suite.app.EpochsKeeper)
suite.queryClient = types.NewQueryClient(queryHelper)
}
2 changes: 1 addition & 1 deletion x/furnace/keeper/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (suite *KeeperTestSuite) SetupTest() {
suite.app = app
suite.ctx = ctx

queryHelper := baseapp.NewQueryServerTestHelper(suite.ctx, suite.app.InterfaceRegistry())
queryHelper := baseapp.NewQueryServerTestHelper(suite.ctx, suite.app.AppCodec().InterfaceRegistry())
types.RegisterQueryServer(queryHelper, suite.app.EpochsKeeper)
suite.queryClient = types.NewQueryClient(queryHelper)
}
2 changes: 1 addition & 1 deletion x/registry/keeper/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (suite *KeeperTestSuite) SetupTest() {
suite.app = app
suite.ctx = ctx

queryHelper := baseapp.NewQueryServerTestHelper(suite.ctx, suite.app.InterfaceRegistry())
queryHelper := baseapp.NewQueryServerTestHelper(suite.ctx, suite.app.AppCodec().InterfaceRegistry())
types.RegisterQueryServer(queryHelper, suite.app.RegistryKeeper)
suite.queryClient = types.NewQueryClient(queryHelper)

Expand Down

0 comments on commit 8a64606

Please sign in to comment.