Skip to content

Commit 95ebdb9

Browse files
committed
add test query
1 parent ca2e802 commit 95ebdb9

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

tests/systemtests/grpc_test.go

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
package systemtests
44

55
import (
6+
"bytes"
67
"context"
8+
"os"
79
"testing"
810

9-
"github.com/fullstorydev/grpcurl"
11+
"github.com/fullstorydev/grpcurl" //nolint:staticcheck: input in grpcurl
1012
"github.com/jhump/protoreflect/grpcreflect"
1113
"github.com/stretchr/testify/require"
1214
"google.golang.org/grpc"
@@ -29,3 +31,54 @@ func TestGRPCReflection(t *testing.T) {
2931
require.Greater(t, len(services), 0)
3032
require.Contains(t, services, "cosmos.staking.v1beta1.Query")
3133
}
34+
35+
func TestGRPCQuery(t *testing.T) {
36+
systest.Sut.ResetChain(t)
37+
systest.Sut.StartChain(t)
38+
39+
ctx := context.Background()
40+
grpcClient, err := grpc.NewClient("localhost:9090", grpc.WithTransportCredentials(insecure.NewCredentials()))
41+
require.NoError(t, err)
42+
43+
descSource := grpcurl.DescriptorSourceFromServer(ctx, grpcreflect.NewClientAuto(ctx, grpcClient))
44+
45+
rf, formatter, err := grpcurl.RequestParserAndFormatter(grpcurl.FormatText, descSource, os.Stdin, grpcurl.FormatOptions{})
46+
require.NoError(t, err)
47+
48+
buf := &bytes.Buffer{}
49+
h := &grpcurl.DefaultEventHandler{
50+
Out: buf,
51+
Formatter: formatter,
52+
VerbosityLevel: 0,
53+
}
54+
55+
err = grpcurl.InvokeRPC(ctx, descSource, grpcClient, "cosmos.staking.v1beta1.Query/Params", nil, h, rf.Next)
56+
require.NoError(t, err)
57+
require.Contains(t, buf.String(), "max_validators")
58+
}
59+
60+
func TestGRPCQueryAutoCLIOptions(t *testing.T) {
61+
t.Skip() // TODO(@julienrbrt): re-add autocli query in v2 in follow-up
62+
63+
systest.Sut.ResetChain(t)
64+
systest.Sut.StartChain(t)
65+
66+
ctx := context.Background()
67+
grpcClient, err := grpc.NewClient("localhost:9090", grpc.WithTransportCredentials(insecure.NewCredentials()))
68+
require.NoError(t, err)
69+
70+
descSource := grpcurl.DescriptorSourceFromServer(ctx, grpcreflect.NewClientAuto(ctx, grpcClient))
71+
72+
rf, formatter, err := grpcurl.RequestParserAndFormatter(grpcurl.FormatText, descSource, os.Stdin, grpcurl.FormatOptions{})
73+
require.NoError(t, err)
74+
75+
buf := &bytes.Buffer{}
76+
h := &grpcurl.DefaultEventHandler{
77+
Out: buf,
78+
Formatter: formatter,
79+
VerbosityLevel: 0,
80+
}
81+
82+
err = grpcurl.InvokeRPC(ctx, descSource, grpcClient, "cosmos.autocli.v1.Query/AppOptions", nil, h, rf.Next)
83+
require.NoError(t, err)
84+
}

0 commit comments

Comments
 (0)