Register gRPC Gateway routes (#7173)
* added unimplemeted code * added a test for bank get balances * fixed lint * Fix decode error * fixed tests * added missing gRPC tests for x/bank * added tests for params, rewards in x/distribution * added tests for x/distr grpc tests * added todos * removed register grpc routes * registered x/ibc client handlers * updated todos * fixed error * fixed tests * review changes * review change Co-authored-by: anilCSE <anil@vitwit.com> Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
This commit is contained in:
parent
2bbcdbb219
commit
5df7dbc182
|
@ -1,6 +1,7 @@
|
|||
package auth
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
|
@ -66,7 +67,8 @@ func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Rout
|
|||
}
|
||||
|
||||
// RegisterGRPCRoutes registers the gRPC Gateway routes for the auth module.
|
||||
func (a AppModuleBasic) RegisterGRPCRoutes(_ client.Context, _ *runtime.ServeMux) {
|
||||
func (AppModuleBasic) RegisterGRPCRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
|
||||
types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
|
||||
}
|
||||
|
||||
// GetTxCmd returns the root tx command for the auth module.
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package rest_test
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
|
@ -8,6 +9,8 @@ import (
|
|||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
grpctypes "github.com/cosmos/cosmos-sdk/types/grpc"
|
||||
"github.com/cosmos/cosmos-sdk/types/query"
|
||||
"github.com/cosmos/cosmos-sdk/types/rest"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
)
|
||||
|
||||
|
@ -93,3 +96,67 @@ func (s *IntegrationTestSuite) TestTotalSupplyGRPCHandler() {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestBalancesGRPCHandler() {
|
||||
val := s.network.Validators[0]
|
||||
baseURL := val.APIAddress
|
||||
|
||||
// TODO: need to pass bech32 string instead of base64 encoding string.
|
||||
// ref: https://github.com/cosmos/cosmos-sdk/issues/7195
|
||||
accAddrBase64 := base64.URLEncoding.EncodeToString(val.Address)
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
url string
|
||||
respType proto.Message
|
||||
expected proto.Message
|
||||
}{
|
||||
{
|
||||
"gRPC total account balance",
|
||||
fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s", baseURL, accAddrBase64),
|
||||
&types.QueryAllBalancesResponse{},
|
||||
&types.QueryAllBalancesResponse{
|
||||
Balances: sdk.NewCoins(
|
||||
sdk.NewCoin(fmt.Sprintf("%stoken", val.Moniker), s.cfg.AccountTokens),
|
||||
sdk.NewCoin(s.cfg.BondDenom, s.cfg.StakingTokens.Sub(s.cfg.BondedTokens)),
|
||||
),
|
||||
Pagination: &query.PageResponse{
|
||||
Total: 2,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"gPRC account balance of a denom",
|
||||
fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s/%s", baseURL, accAddrBase64, s.cfg.BondDenom),
|
||||
&types.QueryBalanceResponse{},
|
||||
&types.QueryBalanceResponse{
|
||||
Balance: &sdk.Coin{
|
||||
Denom: s.cfg.BondDenom,
|
||||
Amount: s.cfg.StakingTokens.Sub(s.cfg.BondedTokens),
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"gPRC account balance of a bogus denom",
|
||||
fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s/foobar", baseURL, accAddrBase64),
|
||||
&types.QueryBalanceResponse{},
|
||||
&types.QueryBalanceResponse{
|
||||
Balance: &sdk.Coin{
|
||||
Denom: "foobar",
|
||||
Amount: sdk.NewInt(0),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
s.Run(tc.name, func() {
|
||||
resp, err := rest.GetRequest(tc.url)
|
||||
s.Require().NoError(err)
|
||||
|
||||
s.Require().NoError(val.ClientCtx.JSONMarshaler.UnmarshalJSON(resp, tc.respType))
|
||||
s.Require().Equal(tc.expected.String(), tc.respType.String())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Rout
|
|||
}
|
||||
|
||||
// RegisterGRPCRoutes registers the gRPC Gateway routes for the bank module.
|
||||
func (a AppModuleBasic) RegisterGRPCRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
|
||||
func (AppModuleBasic) RegisterGRPCRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
|
||||
types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,489 @@
|
|||
package rest_test
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/network"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
grpctypes "github.com/cosmos/cosmos-sdk/types/grpc"
|
||||
"github.com/cosmos/cosmos-sdk/types/query"
|
||||
"github.com/cosmos/cosmos-sdk/types/rest"
|
||||
"github.com/cosmos/cosmos-sdk/x/distribution/types"
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
||||
type IntegrationTestSuite struct {
|
||||
suite.Suite
|
||||
|
||||
cfg network.Config
|
||||
network *network.Network
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) SetupSuite() {
|
||||
s.T().Log("setting up integration test suite")
|
||||
|
||||
cfg := network.DefaultConfig()
|
||||
cfg.NumValidators = 1
|
||||
|
||||
s.cfg = cfg
|
||||
s.network = network.New(s.T(), cfg)
|
||||
|
||||
_, err := s.network.WaitForHeight(1)
|
||||
s.Require().NoError(err)
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestQueryParamsGRPC() {
|
||||
val := s.network.Validators[0]
|
||||
baseURL := val.APIAddress
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
url string
|
||||
respType proto.Message
|
||||
expected proto.Message
|
||||
}{
|
||||
{
|
||||
"gRPC request params",
|
||||
fmt.Sprintf("%s/cosmos/distribution/v1beta1/params", baseURL),
|
||||
&types.QueryParamsResponse{},
|
||||
&types.QueryParamsResponse{
|
||||
Params: types.DefaultParams(),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
resp, err := rest.GetRequest(tc.url)
|
||||
s.Run(tc.name, func() {
|
||||
s.Require().NoError(err)
|
||||
s.Require().NoError(val.ClientCtx.JSONMarshaler.UnmarshalJSON(resp, tc.respType))
|
||||
s.Require().Equal(tc.expected, tc.respType)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestQueryOutstandingRewardsGRPC() {
|
||||
val := s.network.Validators[0]
|
||||
baseURL := val.APIAddress
|
||||
|
||||
// TODO: need to pass bech32 string instead of base64 encoding string
|
||||
// ref: https://github.com/cosmos/cosmos-sdk/issues/7195
|
||||
valAddrBase64 := base64.URLEncoding.EncodeToString(val.ValAddress)
|
||||
|
||||
rewards, err := sdk.ParseDecCoins("19.6stake")
|
||||
s.Require().NoError(err)
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
url string
|
||||
headers map[string]string
|
||||
expErr bool
|
||||
respType proto.Message
|
||||
expected proto.Message
|
||||
}{
|
||||
{
|
||||
"gRPC request params with wrong validator address",
|
||||
fmt.Sprintf("%s/cosmos/distribution/v1beta1/validators/%s/outstanding_rewards", baseURL, "wrongAddress"),
|
||||
map[string]string{},
|
||||
false,
|
||||
&types.QueryValidatorOutstandingRewardsResponse{},
|
||||
&types.QueryValidatorOutstandingRewardsResponse{},
|
||||
},
|
||||
{
|
||||
"gRPC request params valid address",
|
||||
fmt.Sprintf("%s/cosmos/distribution/v1beta1/validators/%s/outstanding_rewards", baseURL, valAddrBase64),
|
||||
map[string]string{
|
||||
grpctypes.GRPCBlockHeightHeader: "2",
|
||||
},
|
||||
false,
|
||||
&types.QueryValidatorOutstandingRewardsResponse{},
|
||||
&types.QueryValidatorOutstandingRewardsResponse{
|
||||
Rewards: types.ValidatorOutstandingRewards{
|
||||
Rewards: rewards,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
resp, err := testutil.GetRequestWithHeaders(tc.url, tc.headers)
|
||||
s.Run(tc.name, func() {
|
||||
if tc.expErr {
|
||||
s.Require().Error(val.ClientCtx.JSONMarshaler.UnmarshalJSON(resp, tc.respType))
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
s.Require().NoError(val.ClientCtx.JSONMarshaler.UnmarshalJSON(resp, tc.respType))
|
||||
s.Require().Equal(tc.expected.String(), tc.respType.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestQueryValidatorCommissionGRPC() {
|
||||
val := s.network.Validators[0]
|
||||
baseURL := val.APIAddress
|
||||
|
||||
// TODO: need to pass bech32 string instead of base64 encoding string
|
||||
// ref: https://github.com/cosmos/cosmos-sdk/issues/7195
|
||||
valAddrBase64 := base64.URLEncoding.EncodeToString(val.ValAddress)
|
||||
|
||||
commission, err := sdk.ParseDecCoins("9.8stake")
|
||||
s.Require().NoError(err)
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
url string
|
||||
headers map[string]string
|
||||
expErr bool
|
||||
respType proto.Message
|
||||
expected proto.Message
|
||||
}{
|
||||
{
|
||||
"gRPC request params with wrong validator address",
|
||||
fmt.Sprintf("%s/cosmos/distribution/v1beta1/validators/%s/commission", baseURL, "wrongAddress"),
|
||||
map[string]string{},
|
||||
false,
|
||||
&types.QueryValidatorCommissionResponse{},
|
||||
&types.QueryValidatorCommissionResponse{},
|
||||
},
|
||||
{
|
||||
"gRPC request params valid address",
|
||||
fmt.Sprintf("%s/cosmos/distribution/v1beta1/validators/%s/commission", baseURL, valAddrBase64),
|
||||
map[string]string{
|
||||
grpctypes.GRPCBlockHeightHeader: "2",
|
||||
},
|
||||
false,
|
||||
&types.QueryValidatorCommissionResponse{},
|
||||
&types.QueryValidatorCommissionResponse{
|
||||
Commission: types.ValidatorAccumulatedCommission{
|
||||
Commission: commission,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
resp, err := testutil.GetRequestWithHeaders(tc.url, tc.headers)
|
||||
s.Run(tc.name, func() {
|
||||
if tc.expErr {
|
||||
s.Require().Error(err)
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
s.Require().NoError(val.ClientCtx.JSONMarshaler.UnmarshalJSON(resp, tc.respType))
|
||||
s.Require().Equal(tc.expected.String(), tc.respType.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestQuerySlashesGRPC() {
|
||||
val := s.network.Validators[0]
|
||||
baseURL := val.APIAddress
|
||||
|
||||
// TODO: need to pass bech32 string instead of base64 encoding string
|
||||
// ref: https://github.com/cosmos/cosmos-sdk/issues/7195
|
||||
valAddressBase64 := base64.URLEncoding.EncodeToString(val.Address)
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
url string
|
||||
expErr bool
|
||||
respType proto.Message
|
||||
expected proto.Message
|
||||
}{
|
||||
{
|
||||
"invalid validator address",
|
||||
fmt.Sprintf("%s/cosmos/distribution/v1beta1/validators/%s/slashes", baseURL, ""),
|
||||
true,
|
||||
&types.QueryValidatorSlashesResponse{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"invalid start height",
|
||||
fmt.Sprintf("%s/cosmos/distribution/v1beta1/validators/%s/slashes?starting_height=%s&ending_height=%s", baseURL, valAddressBase64, "-1", "3"),
|
||||
true,
|
||||
&types.QueryValidatorSlashesResponse{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"invalid start height",
|
||||
fmt.Sprintf("%s/cosmos/distribution/v1beta1/validators/%s/slashes?starting_height=%s&ending_height=%s", baseURL, valAddressBase64, "1", "-3"),
|
||||
true,
|
||||
&types.QueryValidatorSlashesResponse{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"valid request get slashes",
|
||||
fmt.Sprintf("%s/cosmos/distribution/v1beta1/validators/%s/slashes?starting_height=%s&ending_height=%s", baseURL, valAddressBase64, "1", "3"),
|
||||
false,
|
||||
&types.QueryValidatorSlashesResponse{},
|
||||
&types.QueryValidatorSlashesResponse{
|
||||
Pagination: &query.PageResponse{},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
resp, err := rest.GetRequest(tc.url)
|
||||
|
||||
s.Run(tc.name, func() {
|
||||
if tc.expErr {
|
||||
s.Require().Error(val.ClientCtx.JSONMarshaler.UnmarshalJSON(resp, tc.respType))
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
s.Require().NoError(val.ClientCtx.JSONMarshaler.UnmarshalJSON(resp, tc.respType))
|
||||
s.Require().Equal(tc.expected.String(), tc.respType.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestQueryDelegatorRewardsGRPC() {
|
||||
val := s.network.Validators[0]
|
||||
baseUrl := val.APIAddress
|
||||
|
||||
// TODO: need to pass bech32 string instead of base64 encoding string
|
||||
// ref: https://github.com/cosmos/cosmos-sdk/issues/7195
|
||||
delAddrBase64 := base64.URLEncoding.EncodeToString(val.Address)
|
||||
valAddrBase64 := base64.URLEncoding.EncodeToString(val.ValAddress)
|
||||
|
||||
rewards, err := sdk.ParseDecCoins("9.8stake")
|
||||
s.Require().NoError(err)
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
url string
|
||||
headers map[string]string
|
||||
expErr bool
|
||||
respType proto.Message
|
||||
expected proto.Message
|
||||
}{
|
||||
{
|
||||
"wrong delegator address",
|
||||
fmt.Sprintf("%s/cosmos/distribution/v1beta1/delegators/%s/rewards", baseUrl, "wrongDelegatorAddress"),
|
||||
map[string]string{},
|
||||
true,
|
||||
&types.QueryDelegationTotalRewardsResponse{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"valid request",
|
||||
fmt.Sprintf("%s/cosmos/distribution/v1beta1/delegators/%s/rewards", baseUrl, delAddrBase64),
|
||||
map[string]string{
|
||||
grpctypes.GRPCBlockHeightHeader: "2",
|
||||
},
|
||||
false,
|
||||
&types.QueryDelegationTotalRewardsResponse{},
|
||||
&types.QueryDelegationTotalRewardsResponse{
|
||||
Rewards: []types.DelegationDelegatorReward{
|
||||
types.NewDelegationDelegatorReward(val.ValAddress, rewards),
|
||||
},
|
||||
Total: rewards,
|
||||
},
|
||||
},
|
||||
{
|
||||
"wrong validator address(specific validator rewards)",
|
||||
fmt.Sprintf("%s/cosmos/distribution/v1beta1/delegators/%s/rewards/%s", baseUrl, delAddrBase64, "wrongValAddress"),
|
||||
map[string]string{},
|
||||
true,
|
||||
&types.QueryDelegationTotalRewardsResponse{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"valid request(specific validator rewards)",
|
||||
fmt.Sprintf("%s/cosmos/distribution/v1beta1/delegators/%s/rewards/%s", baseUrl, delAddrBase64, valAddrBase64),
|
||||
map[string]string{
|
||||
grpctypes.GRPCBlockHeightHeader: "2",
|
||||
},
|
||||
false,
|
||||
&types.QueryDelegationRewardsResponse{},
|
||||
&types.QueryDelegationRewardsResponse{
|
||||
Rewards: rewards,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
resp, err := testutil.GetRequestWithHeaders(tc.url, tc.headers)
|
||||
|
||||
s.Run(tc.name, func() {
|
||||
if tc.expErr {
|
||||
s.Require().Error(val.ClientCtx.JSONMarshaler.UnmarshalJSON(resp, tc.respType))
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
s.Require().NoError(val.ClientCtx.JSONMarshaler.UnmarshalJSON(resp, tc.respType))
|
||||
s.Require().Equal(tc.expected.String(), tc.respType.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestQueryDelegatorValidatorsGRPC() {
|
||||
val := s.network.Validators[0]
|
||||
baseUrl := val.APIAddress
|
||||
|
||||
// TODO: need to pass bech32 string instead of base64 encoding string
|
||||
// ref: https://github.com/cosmos/cosmos-sdk/issues/7195
|
||||
delAddrBase64 := base64.URLEncoding.EncodeToString(val.Address)
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
url string
|
||||
expErr bool
|
||||
respType proto.Message
|
||||
expected proto.Message
|
||||
}{
|
||||
{
|
||||
"empty delegator address",
|
||||
fmt.Sprintf("%s/cosmos/distribution/v1beta1/delegators/%s/validators", baseUrl, ""),
|
||||
true,
|
||||
&types.QueryDelegatorValidatorsResponse{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"wrong delegator address",
|
||||
fmt.Sprintf("%s/cosmos/distribution/v1beta1/delegators/%s/validators", baseUrl, "wrongDelegatorAddress"),
|
||||
true,
|
||||
&types.QueryDelegatorValidatorsResponse{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"valid request",
|
||||
fmt.Sprintf("%s/cosmos/distribution/v1beta1/delegators/%s/validators", baseUrl, delAddrBase64),
|
||||
false,
|
||||
&types.QueryDelegatorValidatorsResponse{},
|
||||
&types.QueryDelegatorValidatorsResponse{
|
||||
Validators: []sdk.ValAddress{val.ValAddress},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
resp, err := rest.GetRequest(tc.url)
|
||||
|
||||
s.Run(tc.name, func() {
|
||||
if tc.expErr {
|
||||
s.Require().Error(val.ClientCtx.JSONMarshaler.UnmarshalJSON(resp, tc.respType))
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
s.Require().NoError(val.ClientCtx.JSONMarshaler.UnmarshalJSON(resp, tc.respType))
|
||||
s.Require().Equal(tc.expected.String(), tc.respType.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestQueryWithdrawAddressGRPC() {
|
||||
val := s.network.Validators[0]
|
||||
baseUrl := val.APIAddress
|
||||
|
||||
// TODO: need to pass bech32 string instead of base64 encoding string
|
||||
// ref: https://github.com/cosmos/cosmos-sdk/issues/7195
|
||||
delAddrBase64 := base64.URLEncoding.EncodeToString(val.Address)
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
url string
|
||||
expErr bool
|
||||
respType proto.Message
|
||||
expected proto.Message
|
||||
}{
|
||||
{
|
||||
"empty delegator address",
|
||||
fmt.Sprintf("%s/cosmos/distribution/v1beta1/delegators/%s/withdraw_address", baseUrl, ""),
|
||||
true,
|
||||
&types.QueryDelegatorWithdrawAddressResponse{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"wrong delegator address",
|
||||
fmt.Sprintf("%s/cosmos/distribution/v1beta1/delegators/%s/withdraw_address", baseUrl, "wrongDelegatorAddress"),
|
||||
true,
|
||||
&types.QueryDelegatorWithdrawAddressResponse{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"valid request",
|
||||
fmt.Sprintf("%s/cosmos/distribution/v1beta1/delegators/%s/withdraw_address", baseUrl, delAddrBase64),
|
||||
false,
|
||||
&types.QueryDelegatorWithdrawAddressResponse{},
|
||||
&types.QueryDelegatorWithdrawAddressResponse{
|
||||
WithdrawAddress: val.Address,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
resp, err := rest.GetRequest(tc.url)
|
||||
|
||||
s.Run(tc.name, func() {
|
||||
if tc.expErr {
|
||||
s.Require().Error(val.ClientCtx.JSONMarshaler.UnmarshalJSON(resp, tc.respType))
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
s.Require().NoError(val.ClientCtx.JSONMarshaler.UnmarshalJSON(resp, tc.respType))
|
||||
s.Require().Equal(tc.expected.String(), tc.respType.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestQueryValidatorCommunityPoolGRPC() {
|
||||
val := s.network.Validators[0]
|
||||
baseURL := val.APIAddress
|
||||
|
||||
communityPool, err := sdk.ParseDecCoins("0.4stake")
|
||||
s.Require().NoError(err)
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
url string
|
||||
headers map[string]string
|
||||
expErr bool
|
||||
respType proto.Message
|
||||
expected proto.Message
|
||||
}{
|
||||
{
|
||||
"gRPC request params with wrong validator address",
|
||||
fmt.Sprintf("%s/cosmos/distribution/v1beta1/community_pool", baseURL),
|
||||
map[string]string{
|
||||
grpctypes.GRPCBlockHeightHeader: "2",
|
||||
},
|
||||
false,
|
||||
&types.QueryCommunityPoolResponse{},
|
||||
&types.QueryCommunityPoolResponse{
|
||||
Pool: communityPool,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
resp, err := testutil.GetRequestWithHeaders(tc.url, tc.headers)
|
||||
|
||||
s.Run(tc.name, func() {
|
||||
if tc.expErr {
|
||||
s.Require().Error(err)
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
s.Require().NoError(val.ClientCtx.JSONMarshaler.UnmarshalJSON(resp, tc.respType))
|
||||
s.Require().Equal(tc.expected.String(), tc.respType.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestIntegrationTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(IntegrationTestSuite))
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package distribution
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
|
@ -69,7 +70,9 @@ func (AppModuleBasic) RegisterRESTRoutes(clientCtx sdkclient.Context, rtr *mux.R
|
|||
}
|
||||
|
||||
// RegisterGRPCRoutes registers the gRPC Gateway routes for the distribution module.
|
||||
func (AppModuleBasic) RegisterGRPCRoutes(_ sdkclient.Context, _ *runtime.ServeMux) {}
|
||||
func (AppModuleBasic) RegisterGRPCRoutes(clientCtx sdkclient.Context, mux *runtime.ServeMux) {
|
||||
types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
|
||||
}
|
||||
|
||||
// GetTxCmd returns the root tx command for the distribution module.
|
||||
func (AppModuleBasic) GetTxCmd() *cobra.Command {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package evidence
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
|
@ -86,7 +87,8 @@ func (a AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Ro
|
|||
}
|
||||
|
||||
// RegisterGRPCRoutes registers the gRPC Gateway routes for the evidence module.
|
||||
func (a AppModuleBasic) RegisterGRPCRoutes(_ client.Context, _ *runtime.ServeMux) {
|
||||
func (a AppModuleBasic) RegisterGRPCRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
|
||||
types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
|
||||
}
|
||||
|
||||
// GetTxCmd returns the evidence module's root tx command.
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package transfer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
|
@ -73,7 +74,8 @@ func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Rout
|
|||
}
|
||||
|
||||
// RegisterGRPCRoutes registers the gRPC Gateway routes for the ibc-transfer module.
|
||||
func (a AppModuleBasic) RegisterGRPCRoutes(_ client.Context, _ *runtime.ServeMux) {
|
||||
func (AppModuleBasic) RegisterGRPCRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
|
||||
types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
|
||||
}
|
||||
|
||||
// GetTxCmd implements AppModuleBasic interface
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package ibc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
|
@ -19,6 +20,9 @@ import (
|
|||
"github.com/cosmos/cosmos-sdk/types/module"
|
||||
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
|
||||
ibcclient "github.com/cosmos/cosmos-sdk/x/ibc/02-client"
|
||||
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
|
||||
connectiontypes "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types"
|
||||
channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types"
|
||||
host "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
|
||||
"github.com/cosmos/cosmos-sdk/x/ibc/client/cli"
|
||||
"github.com/cosmos/cosmos-sdk/x/ibc/keeper"
|
||||
|
@ -65,7 +69,10 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, config client.TxE
|
|||
func (AppModuleBasic) RegisterRESTRoutes(client.Context, *mux.Router) {}
|
||||
|
||||
// RegisterGRPCRoutes registers the gRPC Gateway routes for the ibc module.
|
||||
func (a AppModuleBasic) RegisterGRPCRoutes(_ client.Context, _ *runtime.ServeMux) {
|
||||
func (AppModuleBasic) RegisterGRPCRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
|
||||
clienttypes.RegisterQueryHandlerClient(context.Background(), mux, clienttypes.NewQueryClient(clientCtx))
|
||||
connectiontypes.RegisterQueryHandlerClient(context.Background(), mux, connectiontypes.NewQueryClient(clientCtx))
|
||||
channeltypes.RegisterQueryHandlerClient(context.Background(), mux, channeltypes.NewQueryClient(clientCtx))
|
||||
}
|
||||
|
||||
// GetTxCmd returns the root tx command for the ibc module.
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package upgrade
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/gogo/protobuf/grpc"
|
||||
|
@ -53,7 +54,9 @@ func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, r *mux.Router
|
|||
}
|
||||
|
||||
// RegisterGRPCRoutes registers the gRPC Gateway routes for the upgrade module.
|
||||
func (AppModuleBasic) RegisterGRPCRoutes(_ client.Context, _ *runtime.ServeMux) {}
|
||||
func (AppModuleBasic) RegisterGRPCRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
|
||||
types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
|
||||
}
|
||||
|
||||
// GetQueryCmd returns the cli query commands for this module
|
||||
func (AppModuleBasic) GetQueryCmd() *cobra.Command {
|
||||
|
|
Loading…
Reference in New Issue