Skip to content

Commit

Permalink
Add Querier to x/acp module, refactor Params query and TestParamsQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
iverc committed Jan 14, 2025
1 parent 41173d7 commit 2a8e4a3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
12 changes: 11 additions & 1 deletion x/acp/keeper/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,14 @@ import (
"github.com/sourcenetwork/sourcehub/x/acp/types"
)

var _ types.QueryServer = Keeper{}
var _ types.QueryServer = Querier{}

// Querier defines a wrapper around the x/acp keeper providing gRPC method handlers.
type Querier struct {
Keeper
}

// NewQuerier initializes new querier.
func NewQuerier(k Keeper) Querier {
return Querier{Keeper: k}
}
6 changes: 2 additions & 4 deletions x/acp/keeper/query_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@ package keeper
import (
"context"

sdk "github.com/cosmos/cosmos-sdk/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/sourcenetwork/sourcehub/x/acp/types"
)

func (k Keeper) Params(goCtx context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
func (q Querier) Params(ctx context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
ctx := sdk.UnwrapSDKContext(goCtx)

return &types.QueryParamsResponse{Params: k.GetParams(ctx)}, nil
return &types.QueryParamsResponse{Params: q.GetParams(ctx)}, nil
}
5 changes: 4 additions & 1 deletion x/acp/keeper/query_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/stretchr/testify/require"

keepertest "github.com/sourcenetwork/sourcehub/testutil/keeper"
acpkeeper "github.com/sourcenetwork/sourcehub/x/acp/keeper"
"github.com/sourcenetwork/sourcehub/x/acp/types"
)

Expand All @@ -14,7 +15,9 @@ func TestParamsQuery(t *testing.T) {
params := types.DefaultParams()
require.NoError(t, keeper.SetParams(ctx, params))

response, err := keeper.Params(ctx, &types.QueryParamsRequest{})
querier := acpkeeper.NewQuerier(keeper)

response, err := querier.Params(ctx, &types.QueryParamsRequest{})
require.NoError(t, err)
require.Equal(t, &types.QueryParamsResponse{Params: params}, response)
}
2 changes: 1 addition & 1 deletion x/acp/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (AppModuleBasic) GetQueryCmd() *cobra.Command {
// RegisterServices registers a gRPC query service to respond to the module-specific gRPC queries
func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
types.RegisterQueryServer(cfg.QueryServer(), am.keeper)
types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQuerier(am.keeper))
}

// RegisterInvariants registers the invariants of the module. If an invariant deviates from its predicted value, the InvariantRegistry triggers appropriate logic (most often the chain will be halted)
Expand Down

0 comments on commit 2a8e4a3

Please sign in to comment.