48 lines
1.3 KiB
Go
48 lines
1.3 KiB
Go
package baseapp
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/cosmos/cosmos-sdk/codec/types"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/cosmos/cosmos-sdk/testutil/testdata"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
)
|
|
|
|
func TestGRPCRouter(t *testing.T) {
|
|
qr := NewGRPCQueryRouter()
|
|
interfaceRegistry := testdata.NewTestInterfaceRegistry()
|
|
qr.SetInterfaceRegistry(interfaceRegistry)
|
|
testdata.RegisterTestServiceServer(qr, testdata.TestServiceImpl{})
|
|
helper := &QueryServiceTestHelper{
|
|
GRPCQueryRouter: qr,
|
|
ctx: sdk.Context{},
|
|
}
|
|
client := testdata.NewTestServiceClient(helper)
|
|
|
|
res, err := client.Echo(context.Background(), &testdata.EchoRequest{Message: "hello"})
|
|
require.Nil(t, err)
|
|
require.NotNil(t, res)
|
|
require.Equal(t, "hello", res.Message)
|
|
|
|
require.Panics(t, func() {
|
|
_, _ = client.Echo(context.Background(), nil)
|
|
})
|
|
|
|
res2, err := client.SayHello(context.Background(), &testdata.SayHelloRequest{Name: "Foo"})
|
|
require.Nil(t, err)
|
|
require.NotNil(t, res)
|
|
require.Equal(t, "Hello Foo!", res2.Greeting)
|
|
|
|
spot := &testdata.Dog{Name: "Spot", Size_: "big"}
|
|
any, err := types.NewAnyWithValue(spot)
|
|
require.NoError(t, err)
|
|
res3, err := client.TestAny(context.Background(), &testdata.TestAnyRequest{AnyAnimal: any})
|
|
require.NoError(t, err)
|
|
require.NotNil(t, res3)
|
|
require.Equal(t, spot, res3.HasAnimal.Animal.GetCachedValue())
|
|
}
|