-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Changes from 11 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
4036473
added unimplemeted code
atheeshp 1bc5e1e
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/59…
atheeshp 85dff4f
added a test for bank get balances
atheeshp 97d8cf1
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/59…
atheeshp db05541
fixed lint
atheeshp 7b19f97
Merge branch 'master' into atheesh/5921-grpc-gateway-x-auth-routes
atheeshp 3fbce47
Fix decode error
anilcse e831ef5
fixed tests
atheeshp 38f0daf
added missing gRPC tests for x/bank
atheeshp ad84c4a
added tests for params, rewards in x/distribution
atheeshp 3d3e697
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/59…
atheeshp c958956
added tests for x/distr grpc tests
atheeshp 3335a54
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/5…
atheeshp 9c0761e
Merge branch 'master' into atheesh/5921-grpc-gateway-x-auth-routes
atheeshp 68cf808
added todos
atheeshp 000c835
removed register grpc routes
atheeshp 2bb13af
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/59…
atheeshp 5bbf22b
Merge branch 'master' into atheesh/5921-grpc-gateway-x-auth-routes
alexanderbez 523cadf
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/59…
atheeshp 35fad50
registered x/ibc client handlers
atheeshp e91a8d1
updated todos
atheeshp 33cce01
fixed error
atheeshp dc419e1
fixed tests
atheeshp 7169fc1
review changes
atheeshp 9fee16c
review change
atheeshp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the
address
path in the URL is defined as bytes in the proto files, and grpc-gateway decodes bytes with base64.URLEncoding, we (actually, any HTTP client really) need to encode the address as base64 URLEncoding first.This has the unfortunate consequence of showing non-human-readable addresses in URLs:
What do people think here? Are you okay to use base64-encoded addresses in URLs?
If not, it's maybe worth to raise an issue on grpc-gateway to see if we can customize bytes decoding.