mirror of
https://github.com/colinear-labs/chain.git
synced 2026-03-05 04:44:25 -08:00
Initialized with Ignite CLI
This commit is contained in:
7
x/cosmostest/keeper/grpc_query.go
Normal file
7
x/cosmostest/keeper/grpc_query.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
"cosmos-test/x/cosmostest/types"
|
||||
)
|
||||
|
||||
var _ types.QueryServer = Keeper{}
|
||||
19
x/cosmostest/keeper/grpc_query_params.go
Normal file
19
x/cosmostest/keeper/grpc_query_params.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"cosmos-test/x/cosmostest/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
func (k Keeper) Params(c context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
|
||||
if req == nil {
|
||||
return nil, status.Error(codes.InvalidArgument, "invalid request")
|
||||
}
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
|
||||
return &types.QueryParamsResponse{Params: k.GetParams(ctx)}, nil
|
||||
}
|
||||
21
x/cosmostest/keeper/grpc_query_params_test.go
Normal file
21
x/cosmostest/keeper/grpc_query_params_test.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package keeper_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
testkeeper "cosmos-test/testutil/keeper"
|
||||
"cosmos-test/x/cosmostest/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestParamsQuery(t *testing.T) {
|
||||
keeper, ctx := testkeeper.CosmostestKeeper(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)
|
||||
}
|
||||
46
x/cosmostest/keeper/keeper.go
Normal file
46
x/cosmostest/keeper/keeper.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
|
||||
"cosmos-test/x/cosmostest/types"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
|
||||
)
|
||||
|
||||
type (
|
||||
Keeper struct {
|
||||
cdc codec.BinaryCodec
|
||||
storeKey sdk.StoreKey
|
||||
memKey sdk.StoreKey
|
||||
paramstore paramtypes.Subspace
|
||||
}
|
||||
)
|
||||
|
||||
func NewKeeper(
|
||||
cdc codec.BinaryCodec,
|
||||
storeKey,
|
||||
memKey sdk.StoreKey,
|
||||
ps paramtypes.Subspace,
|
||||
|
||||
) *Keeper {
|
||||
// set KeyTable if it has not already been set
|
||||
if !ps.HasKeyTable() {
|
||||
ps = ps.WithKeyTable(types.ParamKeyTable())
|
||||
}
|
||||
|
||||
return &Keeper{
|
||||
|
||||
cdc: cdc,
|
||||
storeKey: storeKey,
|
||||
memKey: memKey,
|
||||
paramstore: ps,
|
||||
}
|
||||
}
|
||||
|
||||
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
|
||||
return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName))
|
||||
}
|
||||
17
x/cosmostest/keeper/msg_server.go
Normal file
17
x/cosmostest/keeper/msg_server.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
"cosmos-test/x/cosmostest/types"
|
||||
)
|
||||
|
||||
type msgServer struct {
|
||||
Keeper
|
||||
}
|
||||
|
||||
// NewMsgServerImpl returns an implementation of the MsgServer interface
|
||||
// for the provided Keeper.
|
||||
func NewMsgServerImpl(keeper Keeper) types.MsgServer {
|
||||
return &msgServer{Keeper: keeper}
|
||||
}
|
||||
|
||||
var _ types.MsgServer = msgServer{}
|
||||
16
x/cosmostest/keeper/msg_server_test.go
Normal file
16
x/cosmostest/keeper/msg_server_test.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package keeper_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
keepertest "cosmos-test/testutil/keeper"
|
||||
"cosmos-test/x/cosmostest/keeper"
|
||||
"cosmos-test/x/cosmostest/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
func setupMsgServer(t testing.TB) (types.MsgServer, context.Context) {
|
||||
k, ctx := keepertest.CosmostestKeeper(t)
|
||||
return keeper.NewMsgServerImpl(*k), sdk.WrapSDKContext(ctx)
|
||||
}
|
||||
16
x/cosmostest/keeper/params.go
Normal file
16
x/cosmostest/keeper/params.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
"cosmos-test/x/cosmostest/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
// GetParams get all parameters as types.Params
|
||||
func (k Keeper) GetParams(ctx sdk.Context) types.Params {
|
||||
return types.NewParams()
|
||||
}
|
||||
|
||||
// SetParams set the params
|
||||
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
|
||||
k.paramstore.SetParamSet(ctx, ¶ms)
|
||||
}
|
||||
18
x/cosmostest/keeper/params_test.go
Normal file
18
x/cosmostest/keeper/params_test.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package keeper_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
testkeeper "cosmos-test/testutil/keeper"
|
||||
"cosmos-test/x/cosmostest/types"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestGetParams(t *testing.T) {
|
||||
k, ctx := testkeeper.CosmostestKeeper(t)
|
||||
params := types.DefaultParams()
|
||||
|
||||
k.SetParams(ctx, params)
|
||||
|
||||
require.EqualValues(t, params, k.GetParams(ctx))
|
||||
}
|
||||
Reference in New Issue
Block a user