fix(server/v2/grpc): fix reflection (#23333)
This commit is contained in:
parent
8cdae287f7
commit
c79e19dfc9
@ -41,6 +41,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
Every module contains its own CHANGELOG.md. Please refer to the module you are interested in.
|
||||
|
||||
### Features
|
||||
|
||||
* (sims) [#23013](https://github.com/cosmos/cosmos-sdk/pull/23013) Integration with app v2
|
||||
* (baseapp) [#20291](https://github.com/cosmos/cosmos-sdk/pull/20291) Simulate nested messages.
|
||||
* (client/keys) [#21829](https://github.com/cosmos/cosmos-sdk/pull/21829) Add support for importing hex key using standard input.
|
||||
@ -62,9 +63,9 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i
|
||||
* (x/params) [#22995](https://github.com/cosmos/cosmos-sdk/pull/22995) Remove `x/params`. Migrate to the new params system introduced in `v0.47` as demonstrated [here](https://github.com/cosmos/cosmos-sdk/blob/main/UPGRADING.md#xparams).
|
||||
* (testutil) [#22392](https://github.com/cosmos/cosmos-sdk/pull/22392) Remove `testutil/network` package. Use the integration framework or systemtests framework instead.
|
||||
|
||||
#### Removal of v1 components
|
||||
#### Removal of v0 components
|
||||
|
||||
This subsection lists the API breaking changes that are [part of the removal of v1 components](https://github.com/cosmos/cosmos-sdk/issues/22904). The v1 components were deprecated in `v0.52` and are now removed.
|
||||
This subsection lists the API breaking changes that are [part of the removal of v0 components](https://github.com/cosmos/cosmos-sdk/issues/22904). The v0 components were deprecated in `v0.52` and are now removed.
|
||||
|
||||
* (simapp) [#23009](https://github.com/cosmos/cosmos-sdk/pull/23009) Simapp has been removed. Check-out Simapp/v2 instead.
|
||||
* (server) [#23018](https://github.com/cosmos/cosmos-sdk/pull/23018) [#23238](https://github.com/cosmos/cosmos-sdk/pull/23238) The server package has been removed. Use server/v2 instead
|
||||
|
||||
@ -44,7 +44,6 @@ import (
|
||||
"io"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
gogoproto "github.com/cosmos/gogoproto/proto"
|
||||
@ -55,6 +54,7 @@ import (
|
||||
"google.golang.org/grpc/status"
|
||||
"google.golang.org/protobuf/reflect/protodesc"
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
"google.golang.org/protobuf/reflect/protoregistry"
|
||||
|
||||
"cosmossdk.io/core/log"
|
||||
)
|
||||
@ -63,7 +63,7 @@ type serverReflectionServer struct {
|
||||
rpb.UnimplementedServerReflectionServer
|
||||
s *grpc.Server
|
||||
|
||||
methods []string
|
||||
messages []string
|
||||
|
||||
initSymbols sync.Once
|
||||
serviceNames []string
|
||||
@ -72,11 +72,11 @@ type serverReflectionServer struct {
|
||||
}
|
||||
|
||||
// Register registers the server reflection service on the given gRPC server.
|
||||
func Register(s *grpc.Server, methods []string, logger log.Logger) {
|
||||
func Register(s *grpc.Server, messages []string, logger log.Logger) {
|
||||
rpb.RegisterServerReflectionServer(s, &serverReflectionServer{
|
||||
s: s,
|
||||
methods: methods,
|
||||
log: logger,
|
||||
s: s,
|
||||
messages: messages,
|
||||
log: logger,
|
||||
})
|
||||
}
|
||||
|
||||
@ -91,7 +91,7 @@ type protoMessage interface {
|
||||
func (s *serverReflectionServer) getSymbols() (svcNames []string, symbolIndex map[string]*dpb.FileDescriptorProto) {
|
||||
s.initSymbols.Do(func() {
|
||||
s.symbols = map[string]*dpb.FileDescriptorProto{}
|
||||
services, fds := s.getServices(s.methods)
|
||||
services, fds := s.getServices(s.messages)
|
||||
s.serviceNames = services
|
||||
|
||||
processed := map[string]struct{}{}
|
||||
@ -458,26 +458,61 @@ func (s *serverReflectionServer) ServerReflectionInfo(stream rpb.ServerReflectio
|
||||
}
|
||||
|
||||
// getServices gets the unique list of services given a list of methods.
|
||||
func (s *serverReflectionServer) getServices(methods []string) (svcs []string, fds []*dpb.FileDescriptorProto) {
|
||||
func (s *serverReflectionServer) getServices(messages []string) (svcs []string, fds []*dpb.FileDescriptorProto) {
|
||||
registry, err := gogoproto.MergedRegistry()
|
||||
if err != nil {
|
||||
s.log.Error("unable to load merged registry", "err", err)
|
||||
return nil, nil
|
||||
}
|
||||
seenSvc := map[protoreflect.FullName]struct{}{}
|
||||
for _, methodName := range methods {
|
||||
methodName = strings.Join(strings.Split(methodName[1:], "/"), ".")
|
||||
md, err := registry.FindDescriptorByName(protoreflect.FullName(methodName))
|
||||
for _, messageName := range messages {
|
||||
md, err := registry.FindDescriptorByName(protoreflect.FullName(messageName))
|
||||
if err != nil {
|
||||
s.log.Error("unable to load method descriptor", "method", methodName, "err", err)
|
||||
s.log.Error("unable to load message descriptor", "message", messageName, "err", err)
|
||||
continue
|
||||
}
|
||||
svc := md.(protoreflect.MethodDescriptor).Parent()
|
||||
|
||||
svc, ok := findServiceForMessage(registry, md.(protoreflect.MessageDescriptor))
|
||||
if !ok {
|
||||
// if a service is not found for the message, simply skip
|
||||
// this is likely the message isn't part of a service and using appmodulev2.Handler instead.
|
||||
continue
|
||||
}
|
||||
|
||||
if _, seen := seenSvc[svc.FullName()]; !seen {
|
||||
svcs = append(svcs, string(svc.FullName()))
|
||||
file := svc.ParentFile()
|
||||
fds = append(fds, protodesc.ToFileDescriptorProto(file))
|
||||
}
|
||||
|
||||
seenSvc[svc.FullName()] = struct{}{}
|
||||
}
|
||||
return
|
||||
|
||||
return svcs, fds
|
||||
}
|
||||
|
||||
func findServiceForMessage(registry *protoregistry.Files, messageDesc protoreflect.MessageDescriptor) (protoreflect.ServiceDescriptor, bool) {
|
||||
var (
|
||||
service protoreflect.ServiceDescriptor
|
||||
found bool
|
||||
)
|
||||
|
||||
registry.RangeFiles(func(fileDescriptor protoreflect.FileDescriptor) bool {
|
||||
for i := 0; i < fileDescriptor.Services().Len(); i++ {
|
||||
serviceDesc := fileDescriptor.Services().Get(i)
|
||||
|
||||
for j := 0; j < serviceDesc.Methods().Len(); j++ {
|
||||
methodDesc := serviceDesc.Methods().Get(j)
|
||||
|
||||
if methodDesc.Input() == messageDesc || methodDesc.Output() == messageDesc {
|
||||
service = serviceDesc
|
||||
found = true
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
return service, found
|
||||
}
|
||||
|
||||
@ -1,127 +0,0 @@
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/cosmos/gogoproto/proto"
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
"google.golang.org/protobuf/reflect/protoregistry"
|
||||
"google.golang.org/protobuf/types/descriptorpb"
|
||||
"gotest.tools/v3/assert"
|
||||
|
||||
appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1"
|
||||
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
|
||||
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
|
||||
"cosmossdk.io/depinject"
|
||||
"cosmossdk.io/log"
|
||||
_ "cosmossdk.io/x/accounts"
|
||||
_ "cosmossdk.io/x/bank"
|
||||
_ "cosmossdk.io/x/consensus"
|
||||
_ "cosmossdk.io/x/staking"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/configurator"
|
||||
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
_ "github.com/cosmos/cosmos-sdk/x/auth"
|
||||
_ "github.com/cosmos/cosmos-sdk/x/auth/tx/config"
|
||||
)
|
||||
|
||||
type fixture struct {
|
||||
ctx sdk.Context
|
||||
appQueryClient appv1alpha1.QueryClient
|
||||
autocliInfoClient autocliv1.QueryClient
|
||||
reflectionClient reflectionv1.ReflectionServiceClient
|
||||
}
|
||||
|
||||
func initFixture(t assert.TestingT) *fixture {
|
||||
f := &fixture{}
|
||||
|
||||
var interfaceRegistry codectypes.InterfaceRegistry
|
||||
|
||||
app, err := simtestutil.Setup(
|
||||
depinject.Configs(
|
||||
configurator.NewAppConfig(
|
||||
configurator.AccountsModule(),
|
||||
configurator.AuthModule(),
|
||||
configurator.TxModule(),
|
||||
configurator.ValidateModule(),
|
||||
configurator.ConsensusModule(),
|
||||
configurator.BankModule(),
|
||||
configurator.StakingModule(),
|
||||
),
|
||||
depinject.Supply(log.NewNopLogger()),
|
||||
),
|
||||
&interfaceRegistry,
|
||||
)
|
||||
assert.NilError(t, err)
|
||||
|
||||
f.ctx = app.BaseApp.NewContext(false)
|
||||
queryHelper := &baseapp.QueryServiceTestHelper{
|
||||
GRPCQueryRouter: app.BaseApp.GRPCQueryRouter(),
|
||||
Ctx: f.ctx,
|
||||
}
|
||||
f.appQueryClient = appv1alpha1.NewQueryClient(queryHelper)
|
||||
f.autocliInfoClient = autocliv1.NewQueryClient(queryHelper)
|
||||
f.reflectionClient = reflectionv1.NewReflectionServiceClient(queryHelper)
|
||||
|
||||
return f
|
||||
}
|
||||
|
||||
func TestReflectionService(t *testing.T) {
|
||||
t.Parallel()
|
||||
f := initFixture(t)
|
||||
|
||||
res, err := f.reflectionClient.FileDescriptors(f.ctx, &reflectionv1.FileDescriptorsRequest{})
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, res != nil && res.Files != nil)
|
||||
|
||||
fdMap := map[string]*descriptorpb.FileDescriptorProto{}
|
||||
for _, descriptorProto := range res.Files {
|
||||
fdMap[*descriptorProto.Name] = descriptorProto
|
||||
}
|
||||
|
||||
// check all file descriptors from gogo are present
|
||||
for path := range proto.AllFileDescriptors() {
|
||||
if fdMap[path] == nil {
|
||||
t.Fatalf("missing %s", path)
|
||||
}
|
||||
}
|
||||
|
||||
// check all file descriptors from protoregistry are present
|
||||
protoregistry.GlobalFiles.RangeFiles(func(fileDescriptor protoreflect.FileDescriptor) bool {
|
||||
path := fileDescriptor.Path()
|
||||
if fdMap[path] == nil {
|
||||
t.Fatalf("missing %s", path)
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
func TestQueryAutoCLIAppOptions(t *testing.T) {
|
||||
t.Parallel()
|
||||
f := initFixture(t)
|
||||
|
||||
res, err := f.autocliInfoClient.AppOptions(f.ctx, &autocliv1.AppOptionsRequest{})
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, res != nil && res.ModuleOptions != nil)
|
||||
|
||||
// make sure we have x/auth autocli options which were configured manually
|
||||
authOpts := res.ModuleOptions["auth"]
|
||||
assert.Assert(t, authOpts != nil)
|
||||
assert.Assert(t, authOpts.Query != nil)
|
||||
assert.Equal(t, "cosmos.auth.v1beta1.Query", authOpts.Query.Service)
|
||||
// make sure we have some custom options
|
||||
assert.Assert(t, len(authOpts.Query.RpcCommandOptions) != 0)
|
||||
|
||||
// make sure we have x/staking autocli options which should have been auto-discovered
|
||||
stakingOpts := res.ModuleOptions["staking"]
|
||||
assert.Assert(t, stakingOpts != nil)
|
||||
assert.Assert(t, stakingOpts.Query != nil && stakingOpts.Tx != nil)
|
||||
assert.Equal(t, "cosmos.staking.v1beta1.Query", stakingOpts.Query.Service)
|
||||
assert.Equal(t, "cosmos.staking.v1beta1.Msg", stakingOpts.Tx.Service)
|
||||
|
||||
// make sure tx module has no autocli options because it has no services
|
||||
assert.Assert(t, res.ModuleOptions["tx"] == nil)
|
||||
}
|
||||
@ -6,6 +6,7 @@ require (
|
||||
cosmossdk.io/math v1.5.0
|
||||
cosmossdk.io/systemtests v1.0.0
|
||||
github.com/cosmos/cosmos-sdk v0.50.11
|
||||
github.com/fullstorydev/grpcurl v1.9.2
|
||||
)
|
||||
|
||||
require (
|
||||
@ -26,12 +27,14 @@ require (
|
||||
github.com/DataDog/zstd v1.5.6 // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/bgentry/speakeasy v0.2.0 // indirect
|
||||
github.com/bufbuild/protocompile v0.10.0 // indirect
|
||||
github.com/bytedance/sonic v1.12.6 // indirect
|
||||
github.com/bytedance/sonic/loader v0.2.1 // indirect
|
||||
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
github.com/cloudwego/base64x v0.1.4 // indirect
|
||||
github.com/cloudwego/iasm v0.2.0 // indirect
|
||||
github.com/cncf/xds/go v0.0.0-20240905190251-b4127c9b8d78 // indirect
|
||||
github.com/cockroachdb/apd/v3 v3.2.1 // indirect
|
||||
github.com/cockroachdb/errors v1.11.3 // indirect
|
||||
github.com/cockroachdb/fifo v0.0.0-20240816210425-c5d0cb0b6fc0 // indirect
|
||||
@ -61,6 +64,8 @@ require (
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
github.com/dvsekhvalnov/jose2go v1.6.0 // indirect
|
||||
github.com/emicklei/dot v1.6.2 // indirect
|
||||
github.com/envoyproxy/go-control-plane v0.13.1 // indirect
|
||||
github.com/envoyproxy/protoc-gen-validate v1.1.0 // indirect
|
||||
github.com/fatih/color v1.18.0 // indirect
|
||||
github.com/felixge/httpsnoop v1.0.4 // indirect
|
||||
github.com/fsnotify/fsnotify v1.8.0 // indirect
|
||||
@ -98,6 +103,7 @@ require (
|
||||
github.com/iancoleman/strcase v0.3.0 // indirect
|
||||
github.com/improbable-eng/grpc-web v0.15.0 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||
github.com/jhump/protoreflect v1.16.0
|
||||
github.com/jmhodges/levigo v1.0.0 // indirect
|
||||
github.com/klauspost/compress v1.17.11 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.2.9 // indirect
|
||||
@ -117,6 +123,7 @@ require (
|
||||
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
|
||||
github.com/petermattis/goid v0.0.0-20240813172612-4fcff4a6cae7 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
||||
github.com/prometheus/client_golang v1.20.5 // indirect
|
||||
github.com/prometheus/client_model v0.6.1 // indirect
|
||||
@ -161,7 +168,7 @@ require (
|
||||
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20241015192408-796eee8c2d53 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250106144421-5f5ef82da422 // indirect
|
||||
google.golang.org/grpc v1.69.2 // indirect
|
||||
google.golang.org/grpc v1.69.2
|
||||
google.golang.org/protobuf v1.36.2 // indirect
|
||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
|
||||
@ -81,8 +81,8 @@ github.com/btcsuite/btcd/btcec/v2 v2.3.4 h1:3EJjcN70HCu/mwqlUsGK8GcNVyLVxFDlWurT
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
|
||||
github.com/btcsuite/btcd/btcutil v1.1.6 h1:zFL2+c3Lb9gEgqKNzowKUPQNb8jV7v5Oaodi/AYFd6c=
|
||||
github.com/btcsuite/btcd/btcutil v1.1.6/go.mod h1:9dFymx8HpuLqBnsPELrImQeTQfKBQqzqGbbV3jK55aE=
|
||||
github.com/bufbuild/protocompile v0.6.0 h1:Uu7WiSQ6Yj9DbkdnOe7U4mNKp58y9WDMKDn28/ZlunY=
|
||||
github.com/bufbuild/protocompile v0.6.0/go.mod h1:YNP35qEYoYGme7QMtz5SBCoN4kL4g12jTtjuzRNdjpE=
|
||||
github.com/bufbuild/protocompile v0.10.0 h1:+jW/wnLMLxaCEG8AX9lD0bQ5v9h1RUiMKOBOT5ll9dM=
|
||||
github.com/bufbuild/protocompile v0.10.0/go.mod h1:G9qQIQo0xZ6Uyj6CMNz0saGmx2so+KONo8/KrELABiY=
|
||||
github.com/bytedance/sonic v1.12.6 h1:/isNmCUF2x3Sh8RAp/4mh4ZGkcFAX/hLrzrK3AvpRzk=
|
||||
github.com/bytedance/sonic v1.12.6/go.mod h1:B8Gt/XvtZ3Fqj+iSKMypzymZxw/FVwgIGKzMzT9r/rk=
|
||||
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
|
||||
@ -118,6 +118,8 @@ github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWH
|
||||
github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
|
||||
github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
|
||||
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
|
||||
github.com/cncf/xds/go v0.0.0-20240905190251-b4127c9b8d78 h1:QVw89YDxXxEe+l8gU8ETbOasdwEV+avkR75ZzsVV9WI=
|
||||
github.com/cncf/xds/go v0.0.0-20240905190251-b4127c9b8d78/go.mod h1:W+zGtBO5Y1IgJhy4+A9GOqVhqLpfZi+vwmdNXUehLA8=
|
||||
github.com/cockroachdb/apd/v2 v2.0.2 h1:weh8u7Cneje73dDh+2tEVLUvyBc89iwepWCD8b8034E=
|
||||
github.com/cockroachdb/apd/v2 v2.0.2/go.mod h1:DDxRlzC2lo3/vSlmSoS7JkqbbrARPuFOGr0B9pvN3Gw=
|
||||
github.com/cockroachdb/apd/v3 v3.2.1 h1:U+8j7t0axsIgvQUqthuNm82HIrYXodOV2iWLWtEaIwg=
|
||||
@ -220,7 +222,11 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
|
||||
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
|
||||
github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0=
|
||||
github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go.mod h1:KJwIaB5Mv44NWtYuAOFCVOjcI94vtpEz2JU/D2v6IjE=
|
||||
github.com/envoyproxy/go-control-plane v0.13.1 h1:vPfJZCkob6yTMEgS+0TwfTUfbHjfy/6vOJ8hUWX/uXE=
|
||||
github.com/envoyproxy/go-control-plane v0.13.1/go.mod h1:X45hY0mufo6Fd0KW3rqsGvQMw58jvjymeCzBU3mWyHw=
|
||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||
github.com/envoyproxy/protoc-gen-validate v1.1.0 h1:tntQDh69XqOCOZsDz0lVJQez/2L6Uu2PdjCQwWCJ3bM=
|
||||
github.com/envoyproxy/protoc-gen-validate v1.1.0/go.mod h1:sXRDRVmzEbkM7CVcM06s9shE/m23dg3wzjl0UWqJ2q4=
|
||||
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
|
||||
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
|
||||
@ -239,6 +245,8 @@ github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4
|
||||
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
|
||||
github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/8M=
|
||||
github.com/fsnotify/fsnotify v1.8.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
|
||||
github.com/fullstorydev/grpcurl v1.9.2 h1:ObqVQTZW7aFnhuqQoppUrvep2duMBanB0UYK2Mm8euo=
|
||||
github.com/fullstorydev/grpcurl v1.9.2/go.mod h1:jLfcF55HAz6TYIJY9xFFWgsl0D7o2HlxA5Z4lUG0Tdo=
|
||||
github.com/getsentry/sentry-go v0.30.0 h1:lWUwDnY7sKHaVIoZ9wYqRHJ5iEmoc0pqcRqFkosKzBo=
|
||||
github.com/getsentry/sentry-go v0.30.0/go.mod h1:WU9B9/1/sHDqeV8T+3VwwbjeR5MSXs/6aqG3mqZrezA=
|
||||
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
||||
@ -441,8 +449,8 @@ github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANyt
|
||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||
github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
|
||||
github.com/jhump/protoreflect v1.15.3 h1:6SFRuqU45u9hIZPJAoZ8c28T3nK64BNdp9w6jFonzls=
|
||||
github.com/jhump/protoreflect v1.15.3/go.mod h1:4ORHmSBmlCW8fh3xHmJMGyul1zNqZK4Elxc8qKP+p1k=
|
||||
github.com/jhump/protoreflect v1.16.0 h1:54fZg+49widqXYQ0b+usAFHbMkBGR4PpXrsHc8+TBDg=
|
||||
github.com/jhump/protoreflect v1.16.0/go.mod h1:oYPd7nPvcBw/5wlDfm/AVmU9zH9BgqGCI469pGxfj/8=
|
||||
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
|
||||
github.com/jmhodges/levigo v1.0.0 h1:q5EC36kV79HWeTBWsod3mG11EgStG3qArTKcvlksN1U=
|
||||
github.com/jmhodges/levigo v1.0.0/go.mod h1:Q6Qx+uH3RAqyK4rFQroq9RL7mdkABMcfhEI+nNuzMJQ=
|
||||
@ -609,6 +617,8 @@ github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA=
|
||||
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 h1:GFCKgmp0tecUJ0sJuv4pzYCqS9+RGSn52M3FUwPs+uo=
|
||||
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10/go.mod h1:t/avpk3KcrXxUnYOhZhMXJlSEyie6gQbtLq5NM3loB8=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
|
||||
76
tests/systemtests/grpc_test.go
Normal file
76
tests/systemtests/grpc_test.go
Normal file
@ -0,0 +1,76 @@
|
||||
//go:build system_test
|
||||
|
||||
package systemtests
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/fullstorydev/grpcurl" //nolint:staticcheck: input in grpcurl
|
||||
"github.com/jhump/protoreflect/grpcreflect"
|
||||
"github.com/stretchr/testify/require"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
|
||||
systest "cosmossdk.io/systemtests"
|
||||
)
|
||||
|
||||
func TestGRPC(t *testing.T) {
|
||||
systest.Sut.ResetChain(t)
|
||||
systest.Sut.StartChain(t)
|
||||
|
||||
ctx := context.Background()
|
||||
grpcClient, err := grpc.NewClient("localhost:9090", grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
require.NoError(t, err)
|
||||
defer grpcClient.Close()
|
||||
|
||||
// test grpc reflection
|
||||
descSource := grpcurl.DescriptorSourceFromServer(ctx, grpcreflect.NewClientAuto(ctx, grpcClient))
|
||||
services, err := grpcurl.ListServices(descSource)
|
||||
require.NoError(t, err)
|
||||
require.Greater(t, len(services), 0)
|
||||
require.Contains(t, services, "cosmos.staking.v1beta1.Query")
|
||||
|
||||
// test query invokation
|
||||
rf, formatter, err := grpcurl.RequestParserAndFormatter(grpcurl.FormatText, descSource, os.Stdin, grpcurl.FormatOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
h := &grpcurl.DefaultEventHandler{
|
||||
Out: buf,
|
||||
Formatter: formatter,
|
||||
VerbosityLevel: 0,
|
||||
}
|
||||
|
||||
err = grpcurl.InvokeRPC(ctx, descSource, grpcClient, "cosmos.staking.v1beta1.Query/Params", nil, h, rf.Next)
|
||||
require.NoError(t, err)
|
||||
require.Contains(t, buf.String(), "max_validators")
|
||||
}
|
||||
|
||||
func TestGRPCQueryAutoCLIOptions(t *testing.T) {
|
||||
t.Skip() // TODO(@julienrbrt): re-add autocli query in v2 in follow-up
|
||||
|
||||
systest.Sut.ResetChain(t)
|
||||
systest.Sut.StartChain(t)
|
||||
|
||||
ctx := context.Background()
|
||||
grpcClient, err := grpc.NewClient("localhost:9090", grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
require.NoError(t, err)
|
||||
|
||||
descSource := grpcurl.DescriptorSourceFromServer(ctx, grpcreflect.NewClientAuto(ctx, grpcClient))
|
||||
|
||||
rf, formatter, err := grpcurl.RequestParserAndFormatter(grpcurl.FormatText, descSource, os.Stdin, grpcurl.FormatOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
h := &grpcurl.DefaultEventHandler{
|
||||
Out: buf,
|
||||
Formatter: formatter,
|
||||
VerbosityLevel: 0,
|
||||
}
|
||||
|
||||
err = grpcurl.InvokeRPC(ctx, descSource, grpcClient, "cosmos.autocli.v1.Query/AppOptions", nil, h, rf.Next)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user