Add GRPCBlockHeightHeader in clientCtx gRPC requests (#7021)

* Add header in client context grpc

* Second try

* Make headers work

* Use QueryABCI

* Put header in types

Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
This commit is contained in:
Amaury Martiny
2020-08-12 14:42:10 +00:00
committed by GitHub
co-authored by Alexander Bezobchuk
parent 4891cc0748
commit b08f160adb
7 changed files with 121 additions and 18 deletions
-5
View File
@@ -11,11 +11,6 @@ import (
"github.com/cosmos/cosmos-sdk/server/types"
)
const (
// GRPCBlockHeightHeader is the gRPC header for block height.
GRPCBlockHeightHeader = "x-cosmos-block-height"
)
// StartGRPCServer starts a gRPC server on the given address.
func StartGRPCServer(app types.Application, address string) (*grpc.Server, error) {
grpcSrv := grpc.NewServer()
+5 -5
View File
@@ -11,10 +11,10 @@ import (
rpb "google.golang.org/grpc/reflection/grpc_reflection_v1alpha"
servergrpc "github.com/cosmos/cosmos-sdk/server/grpc"
"github.com/cosmos/cosmos-sdk/testutil/network"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
grpctypes "github.com/cosmos/cosmos-sdk/types/grpc"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
)
@@ -39,7 +39,7 @@ func (s *IntegrationTestSuite) TearDownSuite() {
s.network.Cleanup()
}
func (s *IntegrationTestSuite) TestGRPC() {
func (s *IntegrationTestSuite) TestGRPCServer() {
val0 := s.network.Validators[0]
conn, err := grpc.Dial(
val0.AppConfig.GRPC.Address,
@@ -67,16 +67,16 @@ func (s *IntegrationTestSuite) TestGRPC() {
sdk.NewCoin(denom, s.network.Config.AccountTokens),
*bankRes.GetBalance(),
)
blockHeight := header.Get(servergrpc.GRPCBlockHeightHeader)
blockHeight := header.Get(grpctypes.GRPCBlockHeightHeader)
s.Require().NotEmpty(blockHeight[0]) // Should contain the block height
// Request metadata should work
bankRes, err = bankClient.Balance(
metadata.AppendToOutgoingContext(context.Background(), servergrpc.GRPCBlockHeightHeader, "1"), // Add metadata to request
metadata.AppendToOutgoingContext(context.Background(), grpctypes.GRPCBlockHeightHeader, "1"), // Add metadata to request
&banktypes.QueryBalanceRequest{Address: val0.Address, Denom: denom},
grpc.Header(&header),
)
blockHeight = header.Get(servergrpc.GRPCBlockHeightHeader)
blockHeight = header.Get(grpctypes.GRPCBlockHeightHeader)
s.Require().Equal([]string{"1"}, blockHeight)
// Test server reflection