cosmos-sdk/client/grpc/reflection/reflection_test.go
Aaron Craelius 3f81c0a18d
gRPC interface reflection. (#6722)
* WIP on gRPC interface reflection.

* Update docs in proto

* Add tests

* Add test

* Add route inside router

* Address nits

* ListInterfaces -> ListAllInterfaces

* Fix proto lint

* Remove stray println

* Update proto/cosmos/base/reflection/v1beta1/reflection.proto

Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>

* Update codec/types/interface_registry.go

Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>

* Update codec/types/interface_registry.go

Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>

* Add godoc

Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com>
Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
2020-08-17 17:02:13 +00:00

61 lines
1.7 KiB
Go

package reflection_test
import (
"context"
"testing"
"github.com/stretchr/testify/suite"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client/grpc/reflection"
"github.com/cosmos/cosmos-sdk/simapp"
)
type IntegrationTestSuite struct {
suite.Suite
queryClient reflection.ReflectionServiceClient
}
func (s *IntegrationTestSuite) SetupSuite() {
app := simapp.Setup(false)
srv := reflection.NewReflectionServiceServer(app.InterfaceRegistry())
sdkCtx := app.BaseApp.NewContext(false, tmproto.Header{})
queryHelper := baseapp.NewQueryServerTestHelper(sdkCtx, app.InterfaceRegistry())
reflection.RegisterReflectionServiceServer(queryHelper, srv)
queryClient := reflection.NewReflectionServiceClient(queryHelper)
s.queryClient = queryClient
}
func (s IntegrationTestSuite) TestSimulateService() {
// We will test the following interface for testing.
var iface = "cosmos.evidence.v1beta1.Evidence"
// Test that "cosmos.evidence.v1beta1.Evidence" is included in the
// interfaces.
resIface, err := s.queryClient.ListAllInterfaces(
context.Background(),
&reflection.ListAllInterfacesRequest{},
)
s.Require().NoError(err)
s.Require().Contains(resIface.GetInterfaceNames(), iface)
// Test that "cosmos.evidence.v1beta1.Evidence" has at least the
// Equivocation implementations.
resImpl, err := s.queryClient.ListImplementations(
context.Background(),
&reflection.ListImplementationsRequest{InterfaceName: iface},
)
s.Require().NoError(err)
s.Require().Contains(resImpl.GetImplementationMessageNames(), "/cosmos.evidence.v1beta1.Equivocation")
}
func TestSimulateTestSuite(t *testing.T) {
suite.Run(t, new(IntegrationTestSuite))
}