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

Register gRPC Gateway routes #7173

Merged
merged 25 commits into from
Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4036473
added unimplemeted code
atheeshp Aug 26, 2020
1bc5e1e
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/59…
atheeshp Aug 26, 2020
85dff4f
added a test for bank get balances
atheeshp Aug 26, 2020
97d8cf1
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/59…
atheeshp Aug 26, 2020
db05541
fixed lint
atheeshp Aug 26, 2020
7b19f97
Merge branch 'master' into atheesh/5921-grpc-gateway-x-auth-routes
atheeshp Aug 26, 2020
3fbce47
Fix decode error
anilcse Aug 26, 2020
e831ef5
fixed tests
atheeshp Aug 27, 2020
38f0daf
added missing gRPC tests for x/bank
atheeshp Aug 27, 2020
ad84c4a
added tests for params, rewards in x/distribution
atheeshp Aug 27, 2020
3d3e697
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/59…
atheeshp Aug 27, 2020
c958956
added tests for x/distr grpc tests
atheeshp Aug 28, 2020
3335a54
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/5…
atheeshp Aug 28, 2020
9c0761e
Merge branch 'master' into atheesh/5921-grpc-gateway-x-auth-routes
atheeshp Aug 31, 2020
68cf808
added todos
atheeshp Sep 3, 2020
000c835
removed register grpc routes
atheeshp Sep 3, 2020
2bb13af
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/59…
atheeshp Sep 3, 2020
5bbf22b
Merge branch 'master' into atheesh/5921-grpc-gateway-x-auth-routes
alexanderbez Sep 3, 2020
523cadf
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/59…
atheeshp Sep 4, 2020
35fad50
registered x/ibc client handlers
atheeshp Sep 4, 2020
e91a8d1
updated todos
atheeshp Sep 4, 2020
33cce01
fixed error
atheeshp Sep 4, 2020
dc419e1
fixed tests
atheeshp Sep 4, 2020
7169fc1
review changes
atheeshp Sep 4, 2020
9fee16c
review change
atheeshp Sep 4, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion x/auth/module.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package auth

import (
"context"
"encoding/json"
"fmt"
"math/rand"
Expand Down Expand Up @@ -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.
Expand Down
75 changes: 75 additions & 0 deletions x/bank/client/rest/grpc_query_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package rest_test

import (
"encoding/base64"
"fmt"

"github.com/gogo/protobuf/proto"

"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"
)

Expand Down Expand Up @@ -93,3 +95,76 @@ 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
atheeshp marked this conversation as resolved.
Show resolved Hide resolved
accAddrBase64 := base64.URLEncoding.EncodeToString(val.Address)

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",
},
atheeshp marked this conversation as resolved.
Show resolved Hide resolved
&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),
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, accAddrBase64),
map[string]string{
grpctypes.GRPCBlockHeightHeader: "1",
},
&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 := 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())
})
}
}
2 changes: 1 addition & 1 deletion x/bank/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down
Loading