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>
This commit is contained in:
parent
a0daec2d94
commit
58dcef15e1
43
proto/cosmos/mint/query.proto
Normal file
43
proto/cosmos/mint/query.proto
Normal file
@ -0,0 +1,43 @@
|
||||
syntax = "proto3";
|
||||
package cosmos.mint;
|
||||
|
||||
import "gogoproto/gogo.proto";
|
||||
import "cosmos/mint/mint.proto";
|
||||
|
||||
option go_package = "github.com/cosmos/cosmos-sdk/x/mint/types";
|
||||
|
||||
// Query provides defines the gRPC querier service
|
||||
service Query {
|
||||
// Params returns the total set of minting parameters.
|
||||
rpc Params (QueryParamsRequest) returns (QueryParamsResponse) {}
|
||||
|
||||
// Inflation returns the current minting inflation value.
|
||||
rpc Inflation (QueryInflationRequest) returns (QueryInflationResponse) {}
|
||||
|
||||
// AnnualProvisions current minting annual provisions value.
|
||||
rpc AnnualProvisions (QueryAnnualProvisionsRequest) returns (QueryAnnualProvisionsResponse) {}
|
||||
}
|
||||
|
||||
// QueryParamsRequest is the request type for the Query/Params RPC method
|
||||
message QueryParamsRequest { }
|
||||
|
||||
// QueryParamsResponse is the response type for the Query/Params RPC method
|
||||
message QueryParamsResponse {
|
||||
Params params = 1 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
// QueryInflationRequest is the request type for the Query/Inflation RPC method
|
||||
message QueryInflationRequest { }
|
||||
|
||||
// QueryInflationResponse is the response type for the Query/Inflation RPC method
|
||||
message QueryInflationResponse {
|
||||
bytes inflation = 1 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
// QueryAnnualProvisionsRequest is the request type for the Query/AnnualProvisions RPC method
|
||||
message QueryAnnualProvisionsRequest { }
|
||||
|
||||
// QueryAnnualProvisionsResponse is the response type for the Query/AnnualProvisions RPC method
|
||||
message QueryAnnualProvisionsResponse {
|
||||
bytes annual_provisions = 1 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false];
|
||||
}
|
||||
34
x/mint/keeper/grpc_query.go
Normal file
34
x/mint/keeper/grpc_query.go
Normal file
@ -0,0 +1,34 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/mint/types"
|
||||
)
|
||||
|
||||
var _ types.QueryServer = Keeper{}
|
||||
|
||||
// Params returns params of the mint module.
|
||||
func (k Keeper) Params(c context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
params := k.GetParams(ctx)
|
||||
|
||||
return &types.QueryParamsResponse{Params: params}, nil
|
||||
}
|
||||
|
||||
// Inflation returns minter.Inflation of the mint module.
|
||||
func (k Keeper) Inflation(c context.Context, _ *types.QueryInflationRequest) (*types.QueryInflationResponse, error) {
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
minter := k.GetMinter(ctx)
|
||||
|
||||
return &types.QueryInflationResponse{Inflation: minter.Inflation}, nil
|
||||
}
|
||||
|
||||
// AnnualProvisions returns minter.AnnualProvisions of the mint module.
|
||||
func (k Keeper) AnnualProvisions(c context.Context, _ *types.QueryAnnualProvisionsRequest) (*types.QueryAnnualProvisionsResponse, error) {
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
minter := k.GetMinter(ctx)
|
||||
|
||||
return &types.QueryAnnualProvisionsResponse{AnnualProvisions: minter.AnnualProvisions}, nil
|
||||
}
|
||||
55
x/mint/keeper/grpc_query_test.go
Normal file
55
x/mint/keeper/grpc_query_test.go
Normal file
@ -0,0 +1,55 @@
|
||||
package keeper_test
|
||||
|
||||
import (
|
||||
gocontext "context"
|
||||
"testing"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/mint/types"
|
||||
"github.com/stretchr/testify/suite"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
)
|
||||
|
||||
type MintTestSuite struct {
|
||||
suite.Suite
|
||||
|
||||
app *simapp.SimApp
|
||||
ctx sdk.Context
|
||||
queryClient types.QueryClient
|
||||
}
|
||||
|
||||
func (suite *MintTestSuite) SetupTest() {
|
||||
app := simapp.Setup(false)
|
||||
ctx := app.BaseApp.NewContext(false, abci.Header{})
|
||||
|
||||
queryHelper := baseapp.NewQueryServerTestHelper(ctx, app.InterfaceRegistry())
|
||||
types.RegisterQueryServer(queryHelper, app.MintKeeper)
|
||||
queryClient := types.NewQueryClient(queryHelper)
|
||||
|
||||
suite.app = app
|
||||
suite.ctx = ctx
|
||||
|
||||
suite.queryClient = queryClient
|
||||
}
|
||||
|
||||
func (suite *MintTestSuite) TestGRPCParams() {
|
||||
app, ctx, queryClient := suite.app, suite.ctx, suite.queryClient
|
||||
|
||||
params, err := queryClient.Params(gocontext.Background(), &types.QueryParamsRequest{})
|
||||
suite.Require().NoError(err)
|
||||
suite.Require().Equal(params.Params, app.MintKeeper.GetParams(ctx))
|
||||
|
||||
inflation, err := queryClient.Inflation(gocontext.Background(), &types.QueryInflationRequest{})
|
||||
suite.Require().NoError(err)
|
||||
suite.Require().Equal(inflation.Inflation, app.MintKeeper.GetMinter(ctx).Inflation)
|
||||
|
||||
annualProvisions, err := queryClient.AnnualProvisions(gocontext.Background(), &types.QueryAnnualProvisionsRequest{})
|
||||
suite.Require().NoError(err)
|
||||
suite.Require().Equal(annualProvisions.AnnualProvisions, app.MintKeeper.GetMinter(ctx).AnnualProvisions)
|
||||
}
|
||||
|
||||
func TestMintTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(MintTestSuite))
|
||||
}
|
||||
1206
x/mint/types/query.pb.go
Normal file
1206
x/mint/types/query.pb.go
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user