From 40364733e349b8265c09976e4ffd96114b88e7ba Mon Sep 17 00:00:00 2001 From: atheesh Date: Wed, 26 Aug 2020 15:43:49 +0530 Subject: [PATCH 01/16] added unimplemeted code --- x/auth/module.go | 4 +++- x/bank/module.go | 2 +- x/distribution/module.go | 6 +++++- x/evidence/module.go | 4 +++- x/gov/module.go | 4 +++- x/ibc-transfer/module.go | 4 +++- x/ibc/module.go | 2 +- x/mint/module.go | 4 +++- x/slashing/module.go | 4 +++- x/upgrade/module.go | 5 ++++- 10 files changed, 29 insertions(+), 10 deletions(-) diff --git a/x/auth/module.go b/x/auth/module.go index 78b84bb228b..46cb7e9c4e9 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -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. diff --git a/x/bank/module.go b/x/bank/module.go index 0d7e33b1c8a..738bf675801 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -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)) } diff --git a/x/distribution/module.go b/x/distribution/module.go index d33fc0ef384..4a70ef333b7 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -1,6 +1,7 @@ package distribution import ( + "context" "encoding/json" "fmt" "math/rand" @@ -12,6 +13,7 @@ import ( "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" + "github.com/cosmos/cosmos-sdk/client" sdkclient "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -69,7 +71,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 client.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 { diff --git a/x/evidence/module.go b/x/evidence/module.go index e9997a5e256..f84694a0e61 100644 --- a/x/evidence/module.go +++ b/x/evidence/module.go @@ -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. diff --git a/x/gov/module.go b/x/gov/module.go index 7616eaee60c..d30d822dcc9 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -3,6 +3,7 @@ package gov // DONTCOVER import ( + "context" "encoding/json" "fmt" "math/rand" @@ -85,7 +86,8 @@ func (a AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Ro } // RegisterGRPCRoutes registers the gRPC Gateway routes for the gov 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 root tx command for the gov module. diff --git a/x/ibc-transfer/module.go b/x/ibc-transfer/module.go index 6ec3d81f411..8ac1125c349 100644 --- a/x/ibc-transfer/module.go +++ b/x/ibc-transfer/module.go @@ -1,6 +1,7 @@ package transfer import ( + "context" "encoding/json" "fmt" "math/rand" @@ -68,7 +69,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 diff --git a/x/ibc/module.go b/x/ibc/module.go index fc15814e458..57364f231f8 100644 --- a/x/ibc/module.go +++ b/x/ibc/module.go @@ -65,7 +65,7 @@ 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(_ client.Context, _ *runtime.ServeMux) { } // GetTxCmd returns the root tx command for the ibc module. diff --git a/x/mint/module.go b/x/mint/module.go index e7b18307dd5..cbcb97e4afe 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -1,6 +1,7 @@ package mint import ( + "context" "encoding/json" "fmt" "math/rand" @@ -70,7 +71,8 @@ func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Rout } // RegisterGRPCRoutes registers the gRPC Gateway routes for the mint 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)) } // GetTxCmd returns no root tx command for the mint module. diff --git a/x/slashing/module.go b/x/slashing/module.go index 0adc2ee92f6..abade66535a 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -1,6 +1,7 @@ package slashing import ( + "context" "encoding/json" "fmt" "math/rand" @@ -77,7 +78,8 @@ func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Rout } // RegisterGRPCRoutes registers the gRPC Gateway routes for the slashig 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)) } // GetTxCmd returns the root tx command for the slashing module. diff --git a/x/upgrade/module.go b/x/upgrade/module.go index 650715ae468..2902274f6a9 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -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 { From 85dff4fa6ba4a24729216867ea1eee30eda20266 Mon Sep 17 00:00:00 2001 From: atheesh Date: Wed, 26 Aug 2020 23:12:01 +0530 Subject: [PATCH 02/16] added a test for bank get balances --- x/bank/client/rest/grpc_query_test.go | 39 +++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/x/bank/client/rest/grpc_query_test.go b/x/bank/client/rest/grpc_query_test.go index e1b4384ef9c..bf7952b1232 100644 --- a/x/bank/client/rest/grpc_query_test.go +++ b/x/bank/client/rest/grpc_query_test.go @@ -93,3 +93,42 @@ func (s *IntegrationTestSuite) TestTotalSupplyGRPCHandler() { }) } } + +func (s *IntegrationTestSuite) TestBalancesGRPCHandler() { + val := s.network.Validators[0] + baseURL := val.APIAddress + + testCases := []struct { + name string + url string + headers map[string]string + respType proto.Message + expected proto.Message + }{ + { + "total account balance grpc", + fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s?height=1", baseURL, val.Address.String()), + map[string]string{ + grpctypes.GRPCBlockHeightHeader: "1", + }, + &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)), + ), + }, + }, + } + + for _, tc := range testCases { + tc := tc + s.Run(tc.name, func() { + resp, err := testutil.GetRequestWithHeaders(tc.url, tc.headers) + s.Require().NoError(err) + + s.Require().NoError(val.ClientCtx.JSONMarshaler.UnmarshalJSON(resp, tc.respType)) + s.Require().Equal(tc.expected.String(), tc.respType.String()) + }) + } +} From db05541c67efb30bd55d4fe1f0496032cde3e45c Mon Sep 17 00:00:00 2001 From: atheesh Date: Wed, 26 Aug 2020 23:27:46 +0530 Subject: [PATCH 03/16] fixed lint --- x/distribution/module.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/x/distribution/module.go b/x/distribution/module.go index dc2bc6d0bec..2b896fe8418 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -13,7 +13,6 @@ import ( "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" - "github.com/cosmos/cosmos-sdk/client" sdkclient "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -71,7 +70,7 @@ func (AppModuleBasic) RegisterRESTRoutes(clientCtx sdkclient.Context, rtr *mux.R } // RegisterGRPCRoutes registers the gRPC Gateway routes for the distribution module. -func (AppModuleBasic) RegisterGRPCRoutes(clientCtx client.Context, mux *runtime.ServeMux) { +func (AppModuleBasic) RegisterGRPCRoutes(clientCtx sdkclient.Context, mux *runtime.ServeMux) { types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) } From 3fbce4787e3164d1f394bd03e1c07d0958d81004 Mon Sep 17 00:00:00 2001 From: anilCSE Date: Thu, 27 Aug 2020 03:16:00 +0530 Subject: [PATCH 04/16] Fix decode error --- x/bank/client/rest/grpc_query_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x/bank/client/rest/grpc_query_test.go b/x/bank/client/rest/grpc_query_test.go index bf7952b1232..9fd27abc0f4 100644 --- a/x/bank/client/rest/grpc_query_test.go +++ b/x/bank/client/rest/grpc_query_test.go @@ -1,6 +1,7 @@ package rest_test import ( + "encoding/base64" "fmt" "github.com/gogo/protobuf/proto" @@ -107,7 +108,7 @@ func (s *IntegrationTestSuite) TestBalancesGRPCHandler() { }{ { "total account balance grpc", - fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s?height=1", baseURL, val.Address.String()), + fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s?height=1", baseURL, base64.URLEncoding.EncodeToString(val.Address)), map[string]string{ grpctypes.GRPCBlockHeightHeader: "1", }, From e831ef54f11e75ba51fadd9bb4279d6dd52aa1de Mon Sep 17 00:00:00 2001 From: atheesh Date: Thu, 27 Aug 2020 12:25:56 +0530 Subject: [PATCH 05/16] fixed tests --- x/bank/client/rest/grpc_query_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/x/bank/client/rest/grpc_query_test.go b/x/bank/client/rest/grpc_query_test.go index 9fd27abc0f4..5b1b2b7ecfa 100644 --- a/x/bank/client/rest/grpc_query_test.go +++ b/x/bank/client/rest/grpc_query_test.go @@ -9,6 +9,7 @@ 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/x/bank/types" ) @@ -118,6 +119,9 @@ func (s *IntegrationTestSuite) TestBalancesGRPCHandler() { 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, + }, }, }, } From 38f0daf940dc684998c08d039c7ae7f0991e31d3 Mon Sep 17 00:00:00 2001 From: atheesh Date: Thu, 27 Aug 2020 15:15:40 +0530 Subject: [PATCH 06/16] added missing gRPC tests for x/bank --- x/bank/client/rest/grpc_query_test.go | 32 +++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/x/bank/client/rest/grpc_query_test.go b/x/bank/client/rest/grpc_query_test.go index 5b1b2b7ecfa..105fcd5b4ba 100644 --- a/x/bank/client/rest/grpc_query_test.go +++ b/x/bank/client/rest/grpc_query_test.go @@ -108,8 +108,8 @@ func (s *IntegrationTestSuite) TestBalancesGRPCHandler() { expected proto.Message }{ { - "total account balance grpc", - fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s?height=1", baseURL, base64.URLEncoding.EncodeToString(val.Address)), + "gRPC total account balance", + fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s", baseURL, base64.URLEncoding.EncodeToString(val.Address)), map[string]string{ grpctypes.GRPCBlockHeightHeader: "1", }, @@ -124,6 +124,34 @@ func (s *IntegrationTestSuite) TestBalancesGRPCHandler() { }, }, }, + { + "gPRC account balance of a denom", + fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s/%s", baseURL, base64.URLEncoding.EncodeToString(val.Address), s.cfg.BondDenom), + map[string]string{ + grpctypes.GRPCBlockHeightHeader: "1", + }, + &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, base64.URLEncoding.EncodeToString(val.Address)), + map[string]string{ + grpctypes.GRPCBlockHeightHeader: "1", + }, + &types.QueryBalanceResponse{}, + &types.QueryBalanceResponse{ + Balance: &sdk.Coin{ + Denom: "foobar", + Amount: sdk.NewInt(0), + }, + }, + }, } for _, tc := range testCases { From ad84c4ab3d35eb82c18a090846b19c5430129565 Mon Sep 17 00:00:00 2001 From: atheesh Date: Thu, 27 Aug 2020 20:03:26 +0530 Subject: [PATCH 07/16] added tests for params, rewards in x/distribution --- x/distribution/client/rest/grpc_query_test.go | 126 ++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 x/distribution/client/rest/grpc_query_test.go diff --git a/x/distribution/client/rest/grpc_query_test.go b/x/distribution/client/rest/grpc_query_test.go new file mode 100644 index 00000000000..1e7b2607723 --- /dev/null +++ b/x/distribution/client/rest/grpc_query_test.go @@ -0,0 +1,126 @@ +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/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 + + rewards, _ := sdk.ParseDecCoins("19.6stake") + + 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{ + grpctypes.GRPCBlockHeightHeader: "1", + }, + false, + &types.QueryValidatorOutstandingRewardsResponse{}, + &types.QueryValidatorOutstandingRewardsResponse{}, + }, + { + "gRPC request params valid address", + fmt.Sprintf("%s/cosmos/distribution/v1beta1/validators/%s/outstanding_rewards", baseURL, base64.URLEncoding.EncodeToString(val.ValAddress)), + 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(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)) +} From c95895668c521740cbfcea4fbc7163711bc83b95 Mon Sep 17 00:00:00 2001 From: atheesh Date: Fri, 28 Aug 2020 22:27:12 +0530 Subject: [PATCH 08/16] added tests for x/distr grpc tests --- x/distribution/client/rest/grpc_query_test.go | 369 +++++++++++++++++- 1 file changed, 368 insertions(+), 1 deletion(-) diff --git a/x/distribution/client/rest/grpc_query_test.go b/x/distribution/client/rest/grpc_query_test.go index 1e7b2607723..50325284758 100644 --- a/x/distribution/client/rest/grpc_query_test.go +++ b/x/distribution/client/rest/grpc_query_test.go @@ -9,6 +9,7 @@ import ( "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" @@ -70,7 +71,8 @@ func (s *IntegrationTestSuite) TestQueryOutstandingRewardsGRPC() { val := s.network.Validators[0] baseURL := val.APIAddress - rewards, _ := sdk.ParseDecCoins("19.6stake") + rewards, err := sdk.ParseDecCoins("19.6stake") + s.Require().NoError(err) testCases := []struct { name string @@ -109,6 +111,371 @@ func (s *IntegrationTestSuite) TestQueryOutstandingRewardsGRPC() { 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 + + 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{ + grpctypes.GRPCBlockHeightHeader: "1", + }, + false, + &types.QueryValidatorCommissionResponse{}, + &types.QueryValidatorCommissionResponse{}, + }, + { + "gRPC request params valid address", + fmt.Sprintf("%s/cosmos/distribution/v1beta1/validators/%s/commission", baseURL, base64.URLEncoding.EncodeToString(val.ValAddress)), + 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 + valAddressBase64 := base64.URLEncoding.EncodeToString(val.Address) + + testCases := []struct { + name string + url string + headers map[string]string + expErr bool + respType proto.Message + expected proto.Message + }{ + { + "invalid validator address", + fmt.Sprintf("%s/cosmos/distribution/v1beta1/validators/%s/slashes", baseURL, ""), + map[string]string{ + grpctypes.GRPCBlockHeightHeader: "4", + }, + 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"), + map[string]string{ + grpctypes.GRPCBlockHeightHeader: "4", + }, + 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"), + map[string]string{ + grpctypes.GRPCBlockHeightHeader: "4", + }, + 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"), + map[string]string{ + grpctypes.GRPCBlockHeightHeader: "4", + }, + false, + &types.QueryValidatorSlashesResponse{}, + &types.QueryValidatorSlashesResponse{ + Pagination: &query.PageResponse{}, + }, + }, + } + + 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) TestQueryDelegatorRewardsGRPC() { + val := s.network.Validators[0] + baseUrl := val.APIAddress + + 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{ + grpctypes.GRPCBlockHeightHeader: "2", + }, + true, + &types.QueryDelegationTotalRewardsResponse{}, + nil, + }, + { + "wrong delegator address", + 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{ + grpctypes.GRPCBlockHeightHeader: "2", + }, + 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 + + 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 + + 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) From 68cf8085ae2f23fb32877840f61a8f6f2fd01597 Mon Sep 17 00:00:00 2001 From: atheesh Date: Thu, 3 Sep 2020 15:54:40 +0530 Subject: [PATCH 09/16] added todos --- x/bank/client/rest/grpc_query_test.go | 9 ++++++--- x/distribution/client/rest/grpc_query_test.go | 8 ++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/x/bank/client/rest/grpc_query_test.go b/x/bank/client/rest/grpc_query_test.go index 105fcd5b4ba..4abf33e8c6c 100644 --- a/x/bank/client/rest/grpc_query_test.go +++ b/x/bank/client/rest/grpc_query_test.go @@ -100,6 +100,9 @@ func (s *IntegrationTestSuite) TestBalancesGRPCHandler() { val := s.network.Validators[0] baseURL := val.APIAddress + // TODO: need to pass bech32 string instead of base64 encoding string + accAddrBase64 := base64.URLEncoding.EncodeToString(val.Address) + testCases := []struct { name string url string @@ -109,7 +112,7 @@ func (s *IntegrationTestSuite) TestBalancesGRPCHandler() { }{ { "gRPC total account balance", - fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s", baseURL, base64.URLEncoding.EncodeToString(val.Address)), + fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s", baseURL, accAddrBase64), map[string]string{ grpctypes.GRPCBlockHeightHeader: "1", }, @@ -126,7 +129,7 @@ func (s *IntegrationTestSuite) TestBalancesGRPCHandler() { }, { "gPRC account balance of a denom", - fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s/%s", baseURL, base64.URLEncoding.EncodeToString(val.Address), s.cfg.BondDenom), + fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s/%s", baseURL, accAddrBase64, s.cfg.BondDenom), map[string]string{ grpctypes.GRPCBlockHeightHeader: "1", }, @@ -140,7 +143,7 @@ func (s *IntegrationTestSuite) TestBalancesGRPCHandler() { }, { "gPRC account balance of a bogus denom", - fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s/foobar", baseURL, base64.URLEncoding.EncodeToString(val.Address)), + fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s/foobar", baseURL, accAddrBase64), map[string]string{ grpctypes.GRPCBlockHeightHeader: "1", }, diff --git a/x/distribution/client/rest/grpc_query_test.go b/x/distribution/client/rest/grpc_query_test.go index 50325284758..a1dc0c45842 100644 --- a/x/distribution/client/rest/grpc_query_test.go +++ b/x/distribution/client/rest/grpc_query_test.go @@ -71,6 +71,8 @@ func (s *IntegrationTestSuite) TestQueryOutstandingRewardsGRPC() { val := s.network.Validators[0] baseURL := val.APIAddress + valAddrBase64 := base64.URLEncoding.EncodeToString(val.ValAddress) + rewards, err := sdk.ParseDecCoins("19.6stake") s.Require().NoError(err) @@ -94,7 +96,7 @@ func (s *IntegrationTestSuite) TestQueryOutstandingRewardsGRPC() { }, { "gRPC request params valid address", - fmt.Sprintf("%s/cosmos/distribution/v1beta1/validators/%s/outstanding_rewards", baseURL, base64.URLEncoding.EncodeToString(val.ValAddress)), + fmt.Sprintf("%s/cosmos/distribution/v1beta1/validators/%s/outstanding_rewards", baseURL, valAddrBase64), map[string]string{ grpctypes.GRPCBlockHeightHeader: "2", }, @@ -127,6 +129,8 @@ func (s *IntegrationTestSuite) TestQueryValidatorCommissionGRPC() { val := s.network.Validators[0] baseURL := val.APIAddress + valAddrBase64 := base64.URLEncoding.EncodeToString(val.ValAddress) + commission, err := sdk.ParseDecCoins("9.8stake") s.Require().NoError(err) @@ -150,7 +154,7 @@ func (s *IntegrationTestSuite) TestQueryValidatorCommissionGRPC() { }, { "gRPC request params valid address", - fmt.Sprintf("%s/cosmos/distribution/v1beta1/validators/%s/commission", baseURL, base64.URLEncoding.EncodeToString(val.ValAddress)), + fmt.Sprintf("%s/cosmos/distribution/v1beta1/validators/%s/commission", baseURL, valAddrBase64), map[string]string{ grpctypes.GRPCBlockHeightHeader: "2", }, From 000c835c978d0f7bbecd83d8d86a070faf62f1cd Mon Sep 17 00:00:00 2001 From: atheesh Date: Thu, 3 Sep 2020 15:58:09 +0530 Subject: [PATCH 10/16] removed register grpc routes --- x/gov/module.go | 4 +--- x/mint/module.go | 4 +--- x/slashing/module.go | 4 +--- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/x/gov/module.go b/x/gov/module.go index 1e9991f1a01..b0f43fb6e92 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -3,7 +3,6 @@ package gov // DONTCOVER import ( - "context" "encoding/json" "fmt" "math/rand" @@ -86,8 +85,7 @@ func (a AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Ro } // RegisterGRPCRoutes registers the gRPC Gateway routes for the gov module. -func (a AppModuleBasic) RegisterGRPCRoutes(clientCtx client.Context, mux *runtime.ServeMux) { - types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) +func (a AppModuleBasic) RegisterGRPCRoutes(_ client.Context, _ *runtime.ServeMux) { } // GetTxCmd returns the root tx command for the gov module. diff --git a/x/mint/module.go b/x/mint/module.go index 530c3f4ffb5..431504b561c 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -1,7 +1,6 @@ package mint import ( - "context" "encoding/json" "fmt" "math/rand" @@ -71,8 +70,7 @@ func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Rout } // RegisterGRPCRoutes registers the gRPC Gateway routes for the mint module. -func (AppModuleBasic) RegisterGRPCRoutes(clientCtx client.Context, mux *runtime.ServeMux) { - types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) +func (AppModuleBasic) RegisterGRPCRoutes(_ client.Context, _ *runtime.ServeMux) { } // GetTxCmd returns no root tx command for the mint module. diff --git a/x/slashing/module.go b/x/slashing/module.go index b653e38decb..6a0a2b29ff9 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -1,7 +1,6 @@ package slashing import ( - "context" "encoding/json" "fmt" "math/rand" @@ -78,8 +77,7 @@ func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Rout } // RegisterGRPCRoutes registers the gRPC Gateway routes for the slashig module. -func (AppModuleBasic) RegisterGRPCRoutes(clientCtx client.Context, mux *runtime.ServeMux) { - types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) +func (AppModuleBasic) RegisterGRPCRoutes(_ client.Context, _ *runtime.ServeMux) { } // GetTxCmd returns the root tx command for the slashing module. From 35fad50b84e513102b2b3049de98e50cd0b94f81 Mon Sep 17 00:00:00 2001 From: atheesh Date: Fri, 4 Sep 2020 12:40:17 +0530 Subject: [PATCH 11/16] registered x/ibc client handlers --- x/ibc/module.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/x/ibc/module.go b/x/ibc/module.go index 247695581d8..9a73c33758b 100644 --- a/x/ibc/module.go +++ b/x/ibc/module.go @@ -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 (AppModuleBasic) RegisterGRPCRoutes(_ client.Context, _ *runtime.ServeMux) { +func (AppModuleBasic) RegisterGRPCRoutes(clientCtx sdkclient.Context, mux *runtime.ServeMux) { + clienttypes.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) + connectiontypes.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) + channeltypes.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) } // GetTxCmd returns the root tx command for the ibc module. From e91a8d18bb89cebb52d8e703b9db9a4cab3734f0 Mon Sep 17 00:00:00 2001 From: atheesh Date: Fri, 4 Sep 2020 12:44:51 +0530 Subject: [PATCH 12/16] updated todos --- x/bank/client/rest/grpc_query_test.go | 1 + x/distribution/client/rest/grpc_query_test.go | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/x/bank/client/rest/grpc_query_test.go b/x/bank/client/rest/grpc_query_test.go index 4abf33e8c6c..db3de59d97d 100644 --- a/x/bank/client/rest/grpc_query_test.go +++ b/x/bank/client/rest/grpc_query_test.go @@ -101,6 +101,7 @@ func (s *IntegrationTestSuite) TestBalancesGRPCHandler() { 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 { diff --git a/x/distribution/client/rest/grpc_query_test.go b/x/distribution/client/rest/grpc_query_test.go index a1dc0c45842..39bf4df0f50 100644 --- a/x/distribution/client/rest/grpc_query_test.go +++ b/x/distribution/client/rest/grpc_query_test.go @@ -71,6 +71,8 @@ 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") @@ -129,6 +131,8 @@ 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") @@ -186,6 +190,9 @@ func (s *IntegrationTestSuite) TestQueryValidatorCommissionGRPC() { 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 { @@ -260,6 +267,8 @@ 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) @@ -343,6 +352,8 @@ 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 { @@ -397,6 +408,8 @@ 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 { From 33cce01903558b24621b612cbe20379e0e936f70 Mon Sep 17 00:00:00 2001 From: atheesh Date: Fri, 4 Sep 2020 12:49:08 +0530 Subject: [PATCH 13/16] fixed error --- x/ibc/module.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x/ibc/module.go b/x/ibc/module.go index 9a73c33758b..9c5bccb5d47 100644 --- a/x/ibc/module.go +++ b/x/ibc/module.go @@ -70,9 +70,9 @@ func (AppModuleBasic) RegisterRESTRoutes(client.Context, *mux.Router) {} // RegisterGRPCRoutes registers the gRPC Gateway routes for the ibc module. func (AppModuleBasic) RegisterGRPCRoutes(clientCtx sdkclient.Context, mux *runtime.ServeMux) { - clienttypes.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) - connectiontypes.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) - channeltypes.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) + 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. From dc419e11637c40e2d5c0f32f67c66fd47f450555 Mon Sep 17 00:00:00 2001 From: atheesh Date: Fri, 4 Sep 2020 12:53:47 +0530 Subject: [PATCH 14/16] fixed tests --- x/ibc/module.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/ibc/module.go b/x/ibc/module.go index 9c5bccb5d47..f6489b9d1fd 100644 --- a/x/ibc/module.go +++ b/x/ibc/module.go @@ -69,7 +69,7 @@ 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 (AppModuleBasic) RegisterGRPCRoutes(clientCtx sdkclient.Context, mux *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)) From 7169fc15c13a82ad06a092725d53bc1955f13b8b Mon Sep 17 00:00:00 2001 From: atheesh Date: Fri, 4 Sep 2020 13:05:34 +0530 Subject: [PATCH 15/16] review changes --- x/bank/client/rest/grpc_query_test.go | 13 ++------ x/distribution/client/rest/grpc_query_test.go | 33 ++++--------------- 2 files changed, 8 insertions(+), 38 deletions(-) diff --git a/x/bank/client/rest/grpc_query_test.go b/x/bank/client/rest/grpc_query_test.go index db3de59d97d..ccfe06d112d 100644 --- a/x/bank/client/rest/grpc_query_test.go +++ b/x/bank/client/rest/grpc_query_test.go @@ -10,6 +10,7 @@ import ( 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" ) @@ -107,16 +108,12 @@ func (s *IntegrationTestSuite) TestBalancesGRPCHandler() { testCases := []struct { name string url string - headers map[string]string respType proto.Message expected proto.Message }{ { "gRPC total account balance", fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s", baseURL, accAddrBase64), - map[string]string{ - grpctypes.GRPCBlockHeightHeader: "1", - }, &types.QueryAllBalancesResponse{}, &types.QueryAllBalancesResponse{ Balances: sdk.NewCoins( @@ -131,9 +128,6 @@ func (s *IntegrationTestSuite) TestBalancesGRPCHandler() { { "gPRC account balance of a denom", fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s/%s", baseURL, accAddrBase64, s.cfg.BondDenom), - map[string]string{ - grpctypes.GRPCBlockHeightHeader: "1", - }, &types.QueryBalanceResponse{}, &types.QueryBalanceResponse{ Balance: &sdk.Coin{ @@ -145,9 +139,6 @@ func (s *IntegrationTestSuite) TestBalancesGRPCHandler() { { "gPRC account balance of a bogus denom", fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s/foobar", baseURL, accAddrBase64), - map[string]string{ - grpctypes.GRPCBlockHeightHeader: "1", - }, &types.QueryBalanceResponse{}, &types.QueryBalanceResponse{ Balance: &sdk.Coin{ @@ -161,7 +152,7 @@ func (s *IntegrationTestSuite) TestBalancesGRPCHandler() { for _, tc := range testCases { tc := tc s.Run(tc.name, func() { - resp, err := testutil.GetRequestWithHeaders(tc.url, tc.headers) + resp, err := rest.GetRequest(tc.url) s.Require().NoError(err) s.Require().NoError(val.ClientCtx.JSONMarshaler.UnmarshalJSON(resp, tc.respType)) diff --git a/x/distribution/client/rest/grpc_query_test.go b/x/distribution/client/rest/grpc_query_test.go index 39bf4df0f50..785c17c7b5b 100644 --- a/x/distribution/client/rest/grpc_query_test.go +++ b/x/distribution/client/rest/grpc_query_test.go @@ -89,9 +89,7 @@ func (s *IntegrationTestSuite) TestQueryOutstandingRewardsGRPC() { { "gRPC request params with wrong validator address", fmt.Sprintf("%s/cosmos/distribution/v1beta1/validators/%s/outstanding_rewards", baseURL, "wrongAddress"), - map[string]string{ - grpctypes.GRPCBlockHeightHeader: "1", - }, + map[string]string{}, false, &types.QueryValidatorOutstandingRewardsResponse{}, &types.QueryValidatorOutstandingRewardsResponse{}, @@ -149,9 +147,7 @@ func (s *IntegrationTestSuite) TestQueryValidatorCommissionGRPC() { { "gRPC request params with wrong validator address", fmt.Sprintf("%s/cosmos/distribution/v1beta1/validators/%s/commission", baseURL, "wrongAddress"), - map[string]string{ - grpctypes.GRPCBlockHeightHeader: "1", - }, + map[string]string{}, false, &types.QueryValidatorCommissionResponse{}, &types.QueryValidatorCommissionResponse{}, @@ -198,7 +194,6 @@ func (s *IntegrationTestSuite) TestQuerySlashesGRPC() { testCases := []struct { name string url string - headers map[string]string expErr bool respType proto.Message expected proto.Message @@ -206,9 +201,6 @@ func (s *IntegrationTestSuite) TestQuerySlashesGRPC() { { "invalid validator address", fmt.Sprintf("%s/cosmos/distribution/v1beta1/validators/%s/slashes", baseURL, ""), - map[string]string{ - grpctypes.GRPCBlockHeightHeader: "4", - }, true, &types.QueryValidatorSlashesResponse{}, nil, @@ -216,9 +208,6 @@ func (s *IntegrationTestSuite) TestQuerySlashesGRPC() { { "invalid start height", fmt.Sprintf("%s/cosmos/distribution/v1beta1/validators/%s/slashes?starting_height=%s&ending_height=%s", baseURL, valAddressBase64, "-1", "3"), - map[string]string{ - grpctypes.GRPCBlockHeightHeader: "4", - }, true, &types.QueryValidatorSlashesResponse{}, nil, @@ -226,9 +215,6 @@ func (s *IntegrationTestSuite) TestQuerySlashesGRPC() { { "invalid start height", fmt.Sprintf("%s/cosmos/distribution/v1beta1/validators/%s/slashes?starting_height=%s&ending_height=%s", baseURL, valAddressBase64, "1", "-3"), - map[string]string{ - grpctypes.GRPCBlockHeightHeader: "4", - }, true, &types.QueryValidatorSlashesResponse{}, nil, @@ -236,9 +222,6 @@ func (s *IntegrationTestSuite) TestQuerySlashesGRPC() { { "valid request get slashes", fmt.Sprintf("%s/cosmos/distribution/v1beta1/validators/%s/slashes?starting_height=%s&ending_height=%s", baseURL, valAddressBase64, "1", "3"), - map[string]string{ - grpctypes.GRPCBlockHeightHeader: "4", - }, false, &types.QueryValidatorSlashesResponse{}, &types.QueryValidatorSlashesResponse{ @@ -249,7 +232,7 @@ func (s *IntegrationTestSuite) TestQuerySlashesGRPC() { for _, tc := range testCases { tc := tc - resp, err := testutil.GetRequestWithHeaders(tc.url, tc.headers) + resp, err := rest.GetRequest(tc.url) s.Run(tc.name, func() { if tc.expErr { @@ -286,15 +269,13 @@ func (s *IntegrationTestSuite) TestQueryDelegatorRewardsGRPC() { { "wrong delegator address", fmt.Sprintf("%s/cosmos/distribution/v1beta1/delegators/%s/rewards", baseUrl, "wrongDelegatorAddress"), - map[string]string{ - grpctypes.GRPCBlockHeightHeader: "2", - }, + map[string]string{}, true, &types.QueryDelegationTotalRewardsResponse{}, nil, }, { - "wrong delegator address", + "valid request", fmt.Sprintf("%s/cosmos/distribution/v1beta1/delegators/%s/rewards", baseUrl, delAddrBase64), map[string]string{ grpctypes.GRPCBlockHeightHeader: "2", @@ -311,9 +292,7 @@ func (s *IntegrationTestSuite) TestQueryDelegatorRewardsGRPC() { { "wrong validator address(specific validator rewards)", fmt.Sprintf("%s/cosmos/distribution/v1beta1/delegators/%s/rewards/%s", baseUrl, delAddrBase64, "wrongValAddress"), - map[string]string{ - grpctypes.GRPCBlockHeightHeader: "2", - }, + map[string]string{}, true, &types.QueryDelegationTotalRewardsResponse{}, nil, From 9fee16c608d530d9ddc6ac0df9939303aeb4b79b Mon Sep 17 00:00:00 2001 From: atheesh Date: Fri, 4 Sep 2020 13:08:19 +0530 Subject: [PATCH 16/16] review change --- x/bank/client/rest/grpc_query_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/bank/client/rest/grpc_query_test.go b/x/bank/client/rest/grpc_query_test.go index ccfe06d112d..589adca53f4 100644 --- a/x/bank/client/rest/grpc_query_test.go +++ b/x/bank/client/rest/grpc_query_test.go @@ -101,7 +101,7 @@ func (s *IntegrationTestSuite) TestBalancesGRPCHandler() { val := s.network.Validators[0] baseURL := val.APIAddress - // TODO: need to pass bech32 string instead of base64 encoding string + // 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)