Skip to content

Commit

Permalink
add test query
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt committed Jan 12, 2025
1 parent ca2e802 commit 95ebdb9
Showing 1 changed file with 54 additions and 1 deletion.
55 changes: 54 additions & 1 deletion tests/systemtests/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
}

0 comments on commit 95ebdb9

Please sign in to comment.