Skip to content

Commit 58dcef1

Browse files
atheeshpsahith-naraharifedekunze
authored
x/mint: gRPC query service (#6535)
* Added grpc for mint * changed unused params * updated tests * removed empty query request * fixed lint issues * review changes * review changes * migrated to use test suite * Update x/mint/keeper/grpc_query_test.go Co-authored-by: SaReN <sahithnarahari@gmail.com> Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
1 parent a0daec2 commit 58dcef1

File tree

4 files changed

+1338
-0
lines changed

4 files changed

+1338
-0
lines changed

proto/cosmos/mint/query.proto

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
syntax = "proto3";
2+
package cosmos.mint;
3+
4+
import "gogoproto/gogo.proto";
5+
import "cosmos/mint/mint.proto";
6+
7+
option go_package = "github.com/cosmos/cosmos-sdk/x/mint/types";
8+
9+
// Query provides defines the gRPC querier service
10+
service Query {
11+
// Params returns the total set of minting parameters.
12+
rpc Params (QueryParamsRequest) returns (QueryParamsResponse) {}
13+
14+
// Inflation returns the current minting inflation value.
15+
rpc Inflation (QueryInflationRequest) returns (QueryInflationResponse) {}
16+
17+
// AnnualProvisions current minting annual provisions value.
18+
rpc AnnualProvisions (QueryAnnualProvisionsRequest) returns (QueryAnnualProvisionsResponse) {}
19+
}
20+
21+
// QueryParamsRequest is the request type for the Query/Params RPC method
22+
message QueryParamsRequest { }
23+
24+
// QueryParamsResponse is the response type for the Query/Params RPC method
25+
message QueryParamsResponse {
26+
Params params = 1 [(gogoproto.nullable) = false];
27+
}
28+
29+
// QueryInflationRequest is the request type for the Query/Inflation RPC method
30+
message QueryInflationRequest { }
31+
32+
// QueryInflationResponse is the response type for the Query/Inflation RPC method
33+
message QueryInflationResponse {
34+
bytes inflation = 1 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false];
35+
}
36+
37+
// QueryAnnualProvisionsRequest is the request type for the Query/AnnualProvisions RPC method
38+
message QueryAnnualProvisionsRequest { }
39+
40+
// QueryAnnualProvisionsResponse is the response type for the Query/AnnualProvisions RPC method
41+
message QueryAnnualProvisionsResponse {
42+
bytes annual_provisions = 1 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false];
43+
}

x/mint/keeper/grpc_query.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package keeper
2+
3+
import (
4+
"context"
5+
6+
sdk "github.com/cosmos/cosmos-sdk/types"
7+
"github.com/cosmos/cosmos-sdk/x/mint/types"
8+
)
9+
10+
var _ types.QueryServer = Keeper{}
11+
12+
// Params returns params of the mint module.
13+
func (k Keeper) Params(c context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
14+
ctx := sdk.UnwrapSDKContext(c)
15+
params := k.GetParams(ctx)
16+
17+
return &types.QueryParamsResponse{Params: params}, nil
18+
}
19+
20+
// Inflation returns minter.Inflation of the mint module.
21+
func (k Keeper) Inflation(c context.Context, _ *types.QueryInflationRequest) (*types.QueryInflationResponse, error) {
22+
ctx := sdk.UnwrapSDKContext(c)
23+
minter := k.GetMinter(ctx)
24+
25+
return &types.QueryInflationResponse{Inflation: minter.Inflation}, nil
26+
}
27+
28+
// AnnualProvisions returns minter.AnnualProvisions of the mint module.
29+
func (k Keeper) AnnualProvisions(c context.Context, _ *types.QueryAnnualProvisionsRequest) (*types.QueryAnnualProvisionsResponse, error) {
30+
ctx := sdk.UnwrapSDKContext(c)
31+
minter := k.GetMinter(ctx)
32+
33+
return &types.QueryAnnualProvisionsResponse{AnnualProvisions: minter.AnnualProvisions}, nil
34+
}

x/mint/keeper/grpc_query_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package keeper_test
2+
3+
import (
4+
gocontext "context"
5+
"testing"
6+
7+
"github.com/cosmos/cosmos-sdk/baseapp"
8+
"github.com/cosmos/cosmos-sdk/simapp"
9+
sdk "github.com/cosmos/cosmos-sdk/types"
10+
"github.com/cosmos/cosmos-sdk/x/mint/types"
11+
"github.com/stretchr/testify/suite"
12+
abci "github.com/tendermint/tendermint/abci/types"
13+
)
14+
15+
type MintTestSuite struct {
16+
suite.Suite
17+
18+
app *simapp.SimApp
19+
ctx sdk.Context
20+
queryClient types.QueryClient
21+
}
22+
23+
func (suite *MintTestSuite) SetupTest() {
24+
app := simapp.Setup(false)
25+
ctx := app.BaseApp.NewContext(false, abci.Header{})
26+
27+
queryHelper := baseapp.NewQueryServerTestHelper(ctx, app.InterfaceRegistry())
28+
types.RegisterQueryServer(queryHelper, app.MintKeeper)
29+
queryClient := types.NewQueryClient(queryHelper)
30+
31+
suite.app = app
32+
suite.ctx = ctx
33+
34+
suite.queryClient = queryClient
35+
}
36+
37+
func (suite *MintTestSuite) TestGRPCParams() {
38+
app, ctx, queryClient := suite.app, suite.ctx, suite.queryClient
39+
40+
params, err := queryClient.Params(gocontext.Background(), &types.QueryParamsRequest{})
41+
suite.Require().NoError(err)
42+
suite.Require().Equal(params.Params, app.MintKeeper.GetParams(ctx))
43+
44+
inflation, err := queryClient.Inflation(gocontext.Background(), &types.QueryInflationRequest{})
45+
suite.Require().NoError(err)
46+
suite.Require().Equal(inflation.Inflation, app.MintKeeper.GetMinter(ctx).Inflation)
47+
48+
annualProvisions, err := queryClient.AnnualProvisions(gocontext.Background(), &types.QueryAnnualProvisionsRequest{})
49+
suite.Require().NoError(err)
50+
suite.Require().Equal(annualProvisions.AnnualProvisions, app.MintKeeper.GetMinter(ctx).AnnualProvisions)
51+
}
52+
53+
func TestMintTestSuite(t *testing.T) {
54+
suite.Run(t, new(MintTestSuite))
55+
}

0 commit comments

Comments
 (0)