diff --git a/CHANGELOG.md b/CHANGELOG.md index 54aeafc0a989..9aaa3e584459 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/server/v2/api/grpc/gogoreflection/serverreflection.go b/server/v2/api/grpc/gogoreflection/serverreflection.go index 5bd26b467e00..9f27f5f583f0 100644 --- a/server/v2/api/grpc/gogoreflection/serverreflection.go +++ b/server/v2/api/grpc/gogoreflection/serverreflection.go @@ -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,60 @@ 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 { + s.log.Warn(fmt.Sprintf("unable to find service for message %s", messageName)) + 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 } + +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 +} diff --git a/tests/integration/runtime/query_test.go b/tests/integration/runtime/query_test.go deleted file mode 100644 index f1c2b82ab433..000000000000 --- a/tests/integration/runtime/query_test.go +++ /dev/null @@ -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) -} diff --git a/tests/systemtests/go.mod b/tests/systemtests/go.mod index 74ab28e6e5b9..4777957bce29 100644 --- a/tests/systemtests/go.mod +++ b/tests/systemtests/go.mod @@ -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 diff --git a/tests/systemtests/go.sum b/tests/systemtests/go.sum index c9a7afa7a1f6..e45c13db213c 100644 --- a/tests/systemtests/go.sum +++ b/tests/systemtests/go.sum @@ -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= diff --git a/tests/systemtests/grpc_test.go b/tests/systemtests/grpc_test.go new file mode 100644 index 000000000000..60745139237f --- /dev/null +++ b/tests/systemtests/grpc_test.go @@ -0,0 +1,84 @@ +//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 TestGRPCReflection(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) + + 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") +} + +func TestGRPCQuery(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) + + 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.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) +}