Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt committed Mar 2, 2024
1 parent 59f1727 commit c58a930
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
4 changes: 2 additions & 2 deletions runtime/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ func (m *queryRouterService) InvokeUntyped(ctx context.Context, req protoiface.M
// msgTypeURL returns the TypeURL of a proto message.
func msgTypeURL(msg proto.Message) string {
if m, ok := msg.(protov2.Message); ok {
return "/" + string(m.ProtoReflect().Descriptor().FullName())
return string(m.ProtoReflect().Descriptor().FullName())
}

return "/" + proto.MessageName(msg)
return proto.MessageName(msg)
}
34 changes: 13 additions & 21 deletions runtime/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestRouterService(t *testing.T) {

t.Run("invalid msg", func(t *testing.T) {
_, err := routerService.MessageRouterService().InvokeUntyped(testCtx.Ctx, &bankv1beta1.MsgSend{})
require.ErrorContains(t, err, "could not find response type for message /cosmos.bank.v1beta1.MsgSend")
require.ErrorContains(t, err, "could not find response type for message cosmos.bank.v1beta1.MsgSend")
})

t.Run("invoke untyped: valid msg (proto v1)", func(t *testing.T) {
Expand All @@ -50,15 +50,6 @@ func TestRouterService(t *testing.T) {
require.NotNil(t, resp)
})

t.Run("invoke untyped: valid msg (proto v2)", func(t *testing.T) {
resp, err := routerService.MessageRouterService().InvokeUntyped(testCtx.Ctx, &counterv1.MsgIncreaseCounter{
Signer: "cosmos1",
Count: 42,
})
require.NoError(t, err)
require.NotNil(t, resp)
})

t.Run("invoke typed: valid msg (proto v1)", func(t *testing.T) {
resp := &countertypes.MsgIncreaseCountResponse{}
err := routerService.MessageRouterService().InvokeTyped(testCtx.Ctx, &countertypes.MsgIncreaseCounter{
Expand All @@ -83,36 +74,37 @@ func TestRouterService(t *testing.T) {

t.Run("invalid query", func(t *testing.T) {
err := routerService.QueryRouterService().InvokeTyped(testCtx.Ctx, &bankv1beta1.QueryBalanceRequest{}, &bankv1beta1.QueryBalanceResponse{})
require.ErrorContains(t, err, "unknown request: /cosmos.bank.v1beta1.QueryBalanceRequest")
require.ErrorContains(t, err, "unknown request: cosmos.bank.v1beta1.QueryBalanceRequest")
})

t.Run("invoke typed: valid query (proto v1)", func(t *testing.T) {
_ = counterKeeper.CountStore.Set(testCtx.Ctx, 42)

resp := &countertypes.QueryGetCountResponse{}
err := routerService.QueryRouterService().InvokeTyped(testCtx.Ctx, &countertypes.QueryGetCountRequest{}, resp)
require.NoError(t, err)
require.NotNil(t, resp)
require.Equal(t, &countertypes.QueryGetCountResponse{TotalCount: 42}, resp)
require.Equal(t, int64(42), resp.TotalCount)
})

t.Run("invoke typed: valid query (proto v2)", func(t *testing.T) {
_ = counterKeeper.CountStore.Set(testCtx.Ctx, 42)

resp := &counterv1.QueryGetCountResponse{}
err := routerService.QueryRouterService().InvokeTyped(testCtx.Ctx, &counterv1.QueryGetCountRequest{}, resp)
require.NoError(t, err)
require.NotNil(t, resp)
require.Equal(t, &counterv1.QueryGetCountResponse{TotalCount: 42}, resp)
require.Equal(t, int64(42), resp.TotalCount)
})

t.Run("invoke untyped: valid query (proto v1)", func(t *testing.T) {
resp, err := routerService.QueryRouterService().InvokeUntyped(testCtx.Ctx, &countertypes.QueryGetCountRequest{})
require.NoError(t, err)
require.NotNil(t, resp)
require.Equal(t, &countertypes.QueryGetCountResponse{TotalCount: 42}, resp)
})
_ = counterKeeper.CountStore.Set(testCtx.Ctx, 42)

t.Run("invoke untyped: valid query (proto v2)", func(t *testing.T) {
resp, err := routerService.QueryRouterService().InvokeUntyped(testCtx.Ctx, &counterv1.QueryGetCountRequest{})
resp, err := routerService.QueryRouterService().InvokeUntyped(testCtx.Ctx, &countertypes.QueryGetCountRequest{})
require.NoError(t, err)
require.NotNil(t, resp)
require.Equal(t, &counterv1.QueryGetCountResponse{TotalCount: 42}, resp)
respVal, ok := resp.(*countertypes.QueryGetCountResponse)
require.True(t, ok)
require.Equal(t, int64(42), respVal.TotalCount)
})
}

0 comments on commit c58a930

Please sign in to comment.