From 95ebdb9669d0f7d122fa84a2465d0f3e66fb00be Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Sun, 12 Jan 2025 15:00:26 +0100 Subject: [PATCH] add test query --- tests/systemtests/grpc_test.go | 55 +++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/tests/systemtests/grpc_test.go b/tests/systemtests/grpc_test.go index ecd14e78304..60745139237 100644 --- a/tests/systemtests/grpc_test.go +++ b/tests/systemtests/grpc_test.go @@ -3,10 +3,12 @@ package systemtests import ( + "bytes" "context" + "os" "testing" - "github.com/fullstorydev/grpcurl" + "github.com/fullstorydev/grpcurl" //nolint:staticcheck: input in grpcurl "github.com/jhump/protoreflect/grpcreflect" "github.com/stretchr/testify/require" "google.golang.org/grpc" @@ -29,3 +31,54 @@ func TestGRPCReflection(t *testing.T) { 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) +}