Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/Slashing: gRPC query service #6597

Merged
merged 13 commits into from
Jul 6, 2020
Prev Previous commit
Next Next commit
Use suite for grpc tests
  • Loading branch information
sahith-narahari committed Jul 6, 2020
commit 312ec400ba873718e92b65acb7bc3a34a1b02a20
6 changes: 3 additions & 3 deletions proto/cosmos/slashing/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ option go_package = "github.com/cosmos/cosmos-sdk/x/slashing/types";

// Query provides defines the gRPC querier service
service Query {
// Parameters queries the parameters of slashing module
// Params queries the parameters of slashing module
rpc Params (QueryParamsRequest) returns (QueryParamsResponse){}

// SigningInfo queries the signing info of given cons address
Expand All @@ -19,10 +19,10 @@ service Query {
rpc SigningInfos (QuerySigningInfosRequest) returns (QuerySigningInfosResponse) {}
}

// QueryParametersRequest is the request type for the Query/Parameters RPC method
// QueryParamsRequest is the request type for the Query/Parameters RPC method
message QueryParamsRequest{}

// QueryParametersResponse is the response type for the Query/Parameters RPC method
// QueryParamsResponse is the response type for the Query/Parameters RPC method
message QueryParamsResponse{
cosmos.slashing.Params params = 1[(gogoproto.nullable) = false];
}
Expand Down
68 changes: 63 additions & 5 deletions x/slashing/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,85 @@ package keeper_test
import (
gocontext "context"
"testing"
"time"

"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
abci "github.com/tendermint/tendermint/abci/types"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/slashing/keeper"
"github.com/cosmos/cosmos-sdk/x/slashing/types"
)

func TestGRPCQueryParams(t *testing.T) {
type SlashingTestSuite struct {
suite.Suite

app *simapp.SimApp
ctx sdk.Context
queryClient types.QueryClient
addrDels []sdk.AccAddress
}

func (suite *SlashingTestSuite) SetupTest() {
app := simapp.Setup(false)
ctx := app.BaseApp.NewContext(false, abci.Header{})

app.AccountKeeper.SetParams(ctx, authtypes.DefaultParams())
app.BankKeeper.SetSendEnabled(ctx, true)
app.SlashingKeeper.SetParams(ctx, keeper.TestParams())

addrDels := simapp.AddTestAddrsIncremental(app, ctx, 2, sdk.TokensFromConsensusPower(200))

info1 := types.NewValidatorSigningInfo(sdk.ConsAddress(addrDels[0]), int64(4), int64(3),
time.Unix(2, 0), false, int64(10))
info2 := types.NewValidatorSigningInfo(sdk.ConsAddress(addrDels[1]), int64(5), int64(4),
time.Unix(2, 0), false, int64(10))
app.SlashingKeeper.SetValidatorSigningInfo(ctx, sdk.ConsAddress(addrDels[0]), info1)
app.SlashingKeeper.SetValidatorSigningInfo(ctx, sdk.ConsAddress(addrDels[1]), info2)

suite.app = app
suite.ctx = ctx
suite.addrDels = addrDels

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

paramsResp, err := queryClient.Params(gocontext.Background(), &types.QueryParamsRequest{})
require.NoError(t, err)
suite.queryClient = queryClient
}

func (suite *SlashingTestSuite) TestGRPCQueryParams() {
queryClient := suite.queryClient
var paramsResp, err = queryClient.Params(gocontext.Background(), nil)
suite.Error(err)
suite.Nil(paramsResp)

paramsResp, err = queryClient.Params(gocontext.Background(), &types.QueryParamsRequest{})

suite.NoError(err)
suite.Equal(keeper.TestParams(), paramsResp.Params)
}

func (suite *SlashingTestSuite) TestGRPCSigningInfo() {
queryClient := suite.queryClient

infoResp, err := queryClient.SigningInfo(gocontext.Background(), &types.QuerySigningInfoRequest{ConsAddress: nil})
suite.Error(err)
suite.Nil(infoResp)

consAddr := sdk.ConsAddress(suite.addrDels[0])
info, found := suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, consAddr)
suite.True(found)

infoResp, err = queryClient.SigningInfo(gocontext.Background(),
&types.QuerySigningInfoRequest{ConsAddress: consAddr})
suite.NoError(err)
suite.Equal(&info, infoResp.ValSigningInfo)
}

require.Equal(t, keeper.TestParams(), paramsResp.Params)
func TestSlashingTestSuite(t *testing.T) {
suite.Run(t, new(SlashingTestSuite))
}
8 changes: 4 additions & 4 deletions x/slashing/types/query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions x/upgrade/types/query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.