Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt committed Feb 29, 2024
1 parent e8f8d24 commit 64a92c4
Showing 1 changed file with 47 additions and 13 deletions.
60 changes: 47 additions & 13 deletions runtime/router_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package runtime_test

import (
"context"
"testing"

bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1"
counterv1 "cosmossdk.io/api/cosmos/counter/v1"
"cosmossdk.io/log"
storetypes "cosmossdk.io/store/types"
"github.com/cosmos/cosmos-sdk/baseapp"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/runtime"
"github.com/cosmos/cosmos-sdk/testutil"
counterkeeper "github.com/cosmos/cosmos-sdk/x/counter/keeper"
countertypes "github.com/cosmos/cosmos-sdk/x/counter/types"
"github.com/stretchr/testify/require"
Expand All @@ -23,20 +25,52 @@ func TestMsgRouterService(t *testing.T) {
counterKeeper := counterkeeper.NewKeeper(runtime.NewEnvironment(storeService, log.NewNopLogger()))
countertypes.RegisterInterfaces(interfaceRegistry)
countertypes.RegisterMsgServer(router, counterKeeper)
// countertypes.RegisterQueryServer(router, counterKeeper)
countertypes.RegisterQueryServer(router, counterKeeper)

routerService := runtime.NewMsgRouterService(storeService, router)
testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test"))

resp, err := routerService.InvokeUntyped(context.Background(), &countertypes.MsgIncreaseCounter{
Signer: "cosmos1",
Count: 42,
t.Run("invalid msg", func(t *testing.T) {
_, err := routerService.InvokeUntyped(testCtx.Ctx, &bankv1beta1.MsgSend{})
require.ErrorContains(t, err, "could not find response type for message /cosmos.bank.v1beta1.MsgSend")
})

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

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

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

t.Run("valid query (proto v1)", func(t *testing.T) {
resp := &countertypes.QueryGetCountResponse{}
err := routerService.InvokeTyped(testCtx.Ctx, &countertypes.QueryGetCountRequest{}, resp)
require.NoError(t, err)
require.NotNil(t, resp)
require.Equal(t, &countertypes.QueryGetCountResponse{TotalCount: 42}, resp)
})

t.Run("valid query (proto v2)", func(t *testing.T) {
resp := &counterv1.QueryGetCountResponse{}
err := routerService.InvokeTyped(testCtx.Ctx, &counterv1.QueryGetCountRequest{}, resp)
require.NoError(t, err)
require.NotNil(t, resp)
require.Equal(t, &counterv1.QueryGetCountResponse{TotalCount: 42}, resp)
})
require.NoError(t, err)
require.NotNil(t, resp)

resp = &countertypes.QueryGetCountResponse{}
err = routerService.InvokeTyped(context.Background(), &countertypes.QueryGetCountRequest{}, &countertypes.QueryGetCountResponse{})
require.NoError(t, err)
require.NotNil(t, resp)
require.Equal(t, &countertypes.QueryGetCountResponse{TotalCount: 42}, resp)
}

0 comments on commit 64a92c4

Please sign in to comment.