diff --git a/app/app.go b/app/app.go index 6b94c57684..97d4dbab9c 100644 --- a/app/app.go +++ b/app/app.go @@ -310,8 +310,8 @@ func NewAxelarApp( // TODO: fix this // messageRouter := nexusTypes.NewMessageRouter(). - // AddRoute(evmTypes.ModuleName, evmKeeper.NewMessageRouter()). - // AddRoute(axelarnetTypes.ModuleName, axelarnetKeeper.NewMessageRouter(ibcK, axelarnetK, feegrantK, axelarbankkeeper.NewBankKeeper(bankK), nexusK, accountK)) + // AddRoute(evmTypes.ModuleName, evmKeeper.NewMessageRoute()). + // AddRoute(axelarnetTypes.ModuleName, axelarnetKeeper.NewMessageRoute(ibcK, axelarnetK, feegrantK, axelarbankkeeper.NewBankKeeper(bankK), nexusK, accountK)) // nexusK.SetMessageRouter(messageRouter) // Create static IBC router, add axelarnet module as the IBC transfer route, and seal it diff --git a/x/axelarnet/keeper/genesis_test.go b/x/axelarnet/keeper/genesis_test.go index 8539518020..334ed7420b 100644 --- a/x/axelarnet/keeper/genesis_test.go +++ b/x/axelarnet/keeper/genesis_test.go @@ -138,10 +138,6 @@ func randomChains() []types.CosmosChain { return chains } -func randomNormalizedStr(min, max int) string { - return strings.ReplaceAll(utils.NormalizeString(rand.StrBetween(min, max)), utils.DefaultDelimiter, "-") -} - // randomTransferQueue returns a random (valid) transfer queue state for testing func randomTransferQueue(cdc codec.Codec, transfers []types.IBCTransfer) utils.QueueState { qs := utils.QueueState{Items: make(map[string]utils.QueueState_Item)} diff --git a/x/axelarnet/keeper/message_router.go b/x/axelarnet/keeper/message_route.go similarity index 97% rename from x/axelarnet/keeper/message_router.go rename to x/axelarnet/keeper/message_route.go index 7ad870960b..1666d14cbb 100644 --- a/x/axelarnet/keeper/message_router.go +++ b/x/axelarnet/keeper/message_route.go @@ -14,14 +14,14 @@ import ( const gasCost = storetypes.Gas(1000000) -func NewMessageRouter( - ibcK IBCKeeper, +func NewMessageRoute( keeper Keeper, + ibcK types.IBCKeeper, feegrantK types.FeegrantKeeper, bankK types.BankKeeper, nexusK types.Nexus, accountK types.AccountKeeper, -) nexus.MessageRouter { +) nexus.MessageRoute { return func(ctx sdk.Context, routingCtx nexus.RoutingContext, msg nexus.GeneralMessage) error { if routingCtx.Payload == nil { return fmt.Errorf("payload is required for routing messages to a cosmos chain") diff --git a/x/axelarnet/keeper/message_route_test.go b/x/axelarnet/keeper/message_route_test.go new file mode 100644 index 0000000000..3a681fd1af --- /dev/null +++ b/x/axelarnet/keeper/message_route_test.go @@ -0,0 +1,16 @@ +package keeper_test + +import ( + "testing" + + . "github.com/axelarnetwork/utils/test" +) + +func TestNewMessageRoute(t *testing.T) { + // var ( + // route nexus.MessageRoute + // ) + + // givenMessageRoute := Given("the message route", func() { + // }) +} diff --git a/x/axelarnet/keeper/msg_server_test.go b/x/axelarnet/keeper/msg_server_test.go index edf2e57c85..cbf7803c08 100644 --- a/x/axelarnet/keeper/msg_server_test.go +++ b/x/axelarnet/keeper/msg_server_test.go @@ -1,11 +1,8 @@ package keeper_test import ( - "bytes" - "context" "crypto/sha256" "encoding/hex" - "encoding/json" "fmt" mathRand "math/rand" "strings" @@ -17,8 +14,6 @@ import ( ibctypes "github.com/cosmos/ibc-go/v4/modules/apps/transfer/types" clienttypes "github.com/cosmos/ibc-go/v4/modules/core/02-client/types" ibcclient "github.com/cosmos/ibc-go/v4/modules/core/exported" - "github.com/ethereum/go-ethereum/accounts/abi" - "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/crypto" "github.com/stretchr/testify/assert" tmbytes "github.com/tendermint/tendermint/libs/bytes" @@ -37,7 +32,6 @@ import ( "github.com/axelarnetwork/utils/funcs" "github.com/axelarnetwork/utils/slices" . "github.com/axelarnetwork/utils/test" - rand2 "github.com/axelarnetwork/utils/test/rand" ) func TestHandleMsgLink(t *testing.T) { @@ -970,249 +964,44 @@ func TestAddCosmosBasedChain(t *testing.T) { func TestRouteMessage(t *testing.T) { var ( - server types.MsgServiceServer - k keeper.Keeper - nexusK *mock.NexusMock - feegrantK *mock.FeegrantKeeperMock - ctx sdk.Context - req *types.RouteMessageRequest - msg nexus.GeneralMessage + server types.MsgServiceServer + nexusK *mock.NexusMock + ctx sdk.Context ) - chain := nexustestutils.RandomChain() - chain.Module = evmtypes.ModuleName - id := rand.StrBetween(5, 100) - payload := randPayload() - coin := rand.Coin() - - msg = nexus.GeneralMessage{ - Sender: nexus.CrossChainAddress{ - Chain: nexustestutils.RandomChain(), - Address: evmtestutils.RandomAddress().Hex(), - }, - Recipient: nexus.CrossChainAddress{ - Chain: chain, - Address: rand.AccAddr().String(), - }, - PayloadHash: crypto.Keccak256Hash(payload).Bytes(), - Asset: &coin, + req := types.RouteMessageRequest{ + ID: rand.Str(10), + Sender: rand.AccAddr(), + Feegranter: rand.AccAddr(), + Payload: rand.BytesBetween(5, 100), } givenMsgServer := Given("an axelarnet msg server", func() { - ctx, k, _, feegrantK = setup() - k.InitGenesis(ctx, types.DefaultGenesisState()) - funcs.MustNoErr(k.SetCosmosChain(ctx, types.CosmosChain{ - Name: chain.Name, - AddrPrefix: rand.StrBetween(1, 10), - IBCPath: axelartestutils.RandomIBCPath(), - })) - nexusK = &mock.NexusMock{ - GetChainByNativeAssetFunc: func(sdk.Context, string) (nexus.Chain, bool) { - return chain, true - }, - SetMessageProcessingFunc: func(sdk.Context, string) error { - return nil - }, - } - ibcK := keeper.NewIBCKeeper(k, &mock.IBCTransferKeeperMock{ - TransferFunc: func(context.Context, *ibctypes.MsgTransfer) (*ibctypes.MsgTransferResponse, error) { - return &ibctypes.MsgTransferResponse{Sequence: uint64(rand2.I64Between(1, 100000))}, nil - }, - }, &mock.ChannelKeeperMock{ - GetChannelClientStateFunc: func(sdk.Context, string, string) (string, ibcclient.ClientState, error) { - return "07-tendermint-0", axelartestutils.ClientState(), nil - }, - }) - bankK := &mock.BankKeeperMock{ - MintCoinsFunc: func(sdk.Context, string, sdk.Coins) error { return nil }, - SendCoinsFunc: func(sdk.Context, sdk.AccAddress, sdk.AccAddress, sdk.Coins) error { return nil }, - } - accountK := &mock.AccountKeeperMock{ - GetModuleAddressFunc: func(moduleName string) sdk.AccAddress { - return rand.AccAddr() - }, - } - server = keeper.NewMsgServerImpl(k, nexusK, bankK, accountK, ibcK) - }) - - isMessageFound := func(isFound bool, status nexus.GeneralMessage_Status) func() { - return func() { - nexusK.GetMessageFunc = func(ctx sdk.Context, messageID string) (nexus.GeneralMessage, bool) { - if !isFound { - return nexus.GeneralMessage{}, false - } - msg.Status = status - return msg, true + c, k, _, _ := setup() + ctx = c - } - } - } - - whenMessageIsFromEVM := When("message is from evm", func() { - isMessageFound(true, nexus.Approved)() - msg.Sender.Chain.Module = evmtypes.ModuleName - }) - whenMessageIsFromCosmos := When("message is from cosmos", func() { - isMessageFound(true, nexus.Approved)() - msg.Sender.Chain.Module = exported.ModuleName - }) - whenMessageIsToEVM := When("message is to evm", func() { - msg.Recipient.Chain.Module = evmtypes.ModuleName - }) - whenMessageIsToCosmos := When("message is to cosmos", func() { - msg.Recipient.Chain.Module = exported.ModuleName - }) - - requestIsMade := When("an execute message request is made", func() { - req = types.NewRouteMessage( - rand.AccAddr(), - nil, - id, - payload, - ) + nexusK = &mock.NexusMock{} + ibcK := keeper.NewIBCKeeper(k, &mock.IBCTransferKeeperMock{}, &mock.ChannelKeeperMock{}) + bankK := &mock.BankKeeperMock{} + accountK := &mock.AccountKeeperMock{} + server = keeper.NewMsgServerImpl(k, nexusK, bankK, accountK, ibcK) }) - routeFailsWithError := func(msg string) func(t *testing.T) { - return func(t *testing.T) { - _, err := server.RouteMessage(sdk.WrapSDKContext(ctx), req) - assert.ErrorContains(t, err, msg) - } - } - - t.Run("route message", func(t *testing.T) { - givenMsgServer. - Branch( - When("general message is not found", isMessageFound(false, nexus.NonExistent)). - When2(requestIsMade). - Then("should fail", routeFailsWithError("not found")), - - whenMessageIsFromEVM. - When2(whenMessageIsToCosmos). - When("payload does not match", func() { - req = types.NewRouteMessage( - rand.AccAddr(), - nil, - id, - rand.BytesBetween(100, 500), - ) - }). - Then("should fail", routeFailsWithError("payload hash does not match")), - - whenMessageIsFromEVM. - When2(whenMessageIsToCosmos). - When("payload with version is invalid", func() { - payload = rand.Bytes(4) - msg.PayloadHash = crypto.Keccak256Hash(payload).Bytes() - }). - When2(requestIsMade). - Then("should fail", routeFailsWithError("invalid versioned payload")), - - whenMessageIsFromEVM. - When2(whenMessageIsToCosmos). - When("payload is invalid", func() { - payload = axelartestutils.PackPayloadWithVersion(types.CosmWasmV1, rand.BytesBetween(100, 500)) - msg.PayloadHash = crypto.Keccak256Hash(payload).Bytes() - }). - When2(requestIsMade). - Then("should fail", routeFailsWithError("invalid payload")), - - whenMessageIsFromCosmos. - When2(whenMessageIsToCosmos). - When("payload is invalid", func() { - payload = rand.BytesBetween(100, 500) - msg.PayloadHash = crypto.Keccak256Hash(payload).Bytes() - }). - When2(requestIsMade). - Then("should fail", routeFailsWithError("invalid payload")), - - whenMessageIsFromEVM. - When2(whenMessageIsToCosmos). - When("payload is valid", func() { - payload = randWasmPayload() - msg.PayloadHash = crypto.Keccak256Hash(payload).Bytes() - }). - When2(requestIsMade). - When("feegranter is set with no allowance", func() { - req.Feegranter = rand.AccAddr() - msg.Asset = nil - feegrantK.UseGrantedFeesFunc = func(ctx sdk.Context, granter sdk.AccAddress, addr sdk.AccAddress, amt sdk.Coins, msgs []sdk.Msg) error { - return fmt.Errorf("feegrant error") - } - }). - Then("should fail", routeFailsWithError("feegrant error")), - - whenMessageIsFromEVM. - When2(whenMessageIsToCosmos). - When("payload is valid", func() { - payload = randPayload() - msg.PayloadHash = crypto.Keccak256Hash(payload).Bytes() - }). - When2(requestIsMade). - Then("should success", func(t *testing.T) { - _, err := server.RouteMessage(sdk.WrapSDKContext(ctx), req) - assert.NoError(t, err) - }), - - whenMessageIsFromCosmos. - When2(whenMessageIsToEVM). - When("payload is valid", func() { - payload = rand.BytesBetween(100, 500) - msg.PayloadHash = crypto.Keccak256Hash(payload).Bytes() - }). - When2(requestIsMade). - Then("should success", func(t *testing.T) { - _, err := server.RouteMessage(sdk.WrapSDKContext(ctx), req) - assert.NoError(t, err) - }), - - whenMessageIsFromCosmos. - When2(whenMessageIsToCosmos). - When("payload is valid", func() { - payload = randPayload() - msg.PayloadHash = crypto.Keccak256Hash(payload).Bytes() - }). - When2(requestIsMade). - Then("should success", func(t *testing.T) { - _, err := server.RouteMessage(sdk.WrapSDKContext(ctx), req) - assert.NoError(t, err) - }), - - whenMessageIsFromCosmos. - When2(whenMessageIsToCosmos). - When("payload is valid", func() { - payload = randWasmPayload() - msg.PayloadHash = crypto.Keccak256Hash(payload).Bytes() - }). - When2(requestIsMade). - Then("should success", func(t *testing.T) { - _, err := server.RouteMessage(sdk.WrapSDKContext(ctx), req) - assert.NoError(t, err) - }), - - whenMessageIsFromEVM. - When2(whenMessageIsToCosmos). - When("payload is valid", func() { - payload = randWasmPayload() - msg.PayloadHash = crypto.Keccak256Hash(payload).Bytes() - }). - When2(requestIsMade). - When("feegranter is set with no allowance", func() { - req.Feegranter = rand.AccAddr() - msg.Asset = nil - feegrantK.UseGrantedFeesFunc = func(ctx sdk.Context, granter sdk.AccAddress, addr sdk.AccAddress, amt sdk.Coins, msgs []sdk.Msg) error { - if !bytes.Equal(req.Sender, addr) || !amt[0].Equal(sdk.NewCoin("uaxl", sdk.NewInt(1))) { - return fmt.Errorf("invalid %s %s", addr, amt) - } + givenMsgServer. + When("route message successfully", func() { + nexusK.RouteMessageFunc = func(_ sdk.Context, _ nexus.RoutingContext, _ string) error { return nil } + }). + Then("should route the correct message", func(t *testing.T) { + _, err := server.RouteMessage(sdk.WrapSDKContext(ctx), &req) - return nil - } - }). - Then("should success", func(t *testing.T) { - _, err := server.RouteMessage(sdk.WrapSDKContext(ctx), req) - assert.NoError(t, err) - }), - ).Run(t) - }) + assert.NoError(t, err) + assert.Len(t, nexusK.RouteMessageCalls(), 1) + assert.Equal(t, nexusK.RouteMessageCalls()[0].RoutingCtx.Sender, req.Sender) + assert.Equal(t, nexusK.RouteMessageCalls()[0].RoutingCtx.FeeGranter, req.Feegranter) + assert.Equal(t, nexusK.RouteMessageCalls()[0].RoutingCtx.Payload, req.Payload) + assert.Equal(t, nexusK.RouteMessageCalls()[0].ID, req.ID) + }). + Run(t) } func TestHandleCallContract(t *testing.T) { @@ -1430,45 +1219,3 @@ func randomTransfer(asset string, chain nexus.ChainName) nexus.CrossChainTransfe sdk.NewInt64Coin(asset, rand.I64Between(1, 10000000000)), ) } - -func randPayload() []byte { - bytesType := funcs.Must(abi.NewType("bytes", "bytes", nil)) - stringType := funcs.Must(abi.NewType("string", "string", nil)) - stringArrayType := funcs.Must(abi.NewType("string[]", "string[]", nil)) - - argNum := int(rand2.I64Between(1, 10)) - - var args abi.Arguments - for i := 0; i < argNum; i += 1 { - args = append(args, abi.Argument{Type: stringType}) - } - - schema := abi.Arguments{{Type: stringType}, {Type: stringArrayType}, {Type: stringArrayType}, {Type: bytesType}} - payload := funcs.Must( - schema.Pack( - rand.StrBetween(5, 10), - slices.Expand2(func() string { return rand.Str(5) }, argNum), - slices.Expand2(func() string { return "string" }, argNum), - funcs.Must(args.Pack(slices.Expand2(func() interface{} { return "string" }, argNum)...)), - ), - ) - - return append(funcs.Must(hexutil.Decode(types.CosmWasmV1)), payload...) -} - -func randWasmPayload() []byte { - args := make(map[string]string) - - randStr := func() string { return rand.Str(int(rand.I64Between(1, 32))) } - - argNum := int(rand2.I64Between(1, 10)) - - for i := 0; i < argNum; i += 1 { - args[randStr()] = randStr() - } - msg := make(map[string]map[string]string) - msg[randStr()] = args - payload := funcs.Must(json.Marshal(msg)) - - return axelartestutils.PackPayloadWithVersion(types.CosmWasmV2, payload) -} diff --git a/x/axelarnet/types/expected_keepers.go b/x/axelarnet/types/expected_keepers.go index 0c637b4cc4..b6183de0fd 100644 --- a/x/axelarnet/types/expected_keepers.go +++ b/x/axelarnet/types/expected_keepers.go @@ -20,7 +20,7 @@ import ( nexus "github.com/axelarnetwork/axelar-core/x/nexus/exported" ) -//go:generate moq -out ./mock/expected_keepers.go -pkg mock . BaseKeeper Nexus BankKeeper IBCTransferKeeper ChannelKeeper AccountKeeper PortKeeper GovKeeper FeegrantKeeper +//go:generate moq -out ./mock/expected_keepers.go -pkg mock . BaseKeeper Nexus BankKeeper IBCTransferKeeper ChannelKeeper AccountKeeper PortKeeper GovKeeper FeegrantKeeper IBCKeeper // BaseKeeper is implemented by this module's base keeper type BaseKeeper interface { @@ -127,3 +127,8 @@ type GovKeeper interface { type FeegrantKeeper interface { UseGrantedFees(ctx sdk.Context, granter, grantee sdk.AccAddress, fee sdk.Coins, msgs []sdk.Msg) error } + +// IBCKeeper defines the expected IBC keeper +type IBCKeeper interface { + SendMessage(c context.Context, recipient nexus.CrossChainAddress, asset sdk.Coin, payload string, id string) error +} diff --git a/x/axelarnet/types/mock/expected_keepers.go b/x/axelarnet/types/mock/expected_keepers.go index 8c8bcac984..280c075420 100644 --- a/x/axelarnet/types/mock/expected_keepers.go +++ b/x/axelarnet/types/mock/expected_keepers.go @@ -611,6 +611,9 @@ var _ axelarnettypes.Nexus = &NexusMock{} // RegisterAssetFunc: func(ctx cosmossdktypes.Context, chain github_com_axelarnetwork_axelar_core_x_nexus_exported.Chain, asset github_com_axelarnetwork_axelar_core_x_nexus_exported.Asset, limit cosmossdktypes.Uint, window time.Duration) error { // panic("mock out the RegisterAsset method") // }, +// RouteMessageFunc: func(ctx cosmossdktypes.Context, routingCtx github_com_axelarnetwork_axelar_core_x_nexus_exported.RoutingContext, id string) error { +// panic("mock out the RouteMessage method") +// }, // SetChainFunc: func(ctx cosmossdktypes.Context, chain github_com_axelarnetwork_axelar_core_x_nexus_exported.Chain) { // panic("mock out the SetChain method") // }, @@ -687,6 +690,9 @@ type NexusMock struct { // RegisterAssetFunc mocks the RegisterAsset method. RegisterAssetFunc func(ctx cosmossdktypes.Context, chain github_com_axelarnetwork_axelar_core_x_nexus_exported.Chain, asset github_com_axelarnetwork_axelar_core_x_nexus_exported.Asset, limit cosmossdktypes.Uint, window time.Duration) error + // RouteMessageFunc mocks the RouteMessage method. + RouteMessageFunc func(ctx cosmossdktypes.Context, routingCtx github_com_axelarnetwork_axelar_core_x_nexus_exported.RoutingContext, id string) error + // SetChainFunc mocks the SetChain method. SetChainFunc func(ctx cosmossdktypes.Context, chain github_com_axelarnetwork_axelar_core_x_nexus_exported.Chain) @@ -842,6 +848,15 @@ type NexusMock struct { // Window is the window argument value. Window time.Duration } + // RouteMessage holds details about calls to the RouteMessage method. + RouteMessage []struct { + // Ctx is the ctx argument value. + Ctx cosmossdktypes.Context + // RoutingCtx is the routingCtx argument value. + RoutingCtx github_com_axelarnetwork_axelar_core_x_nexus_exported.RoutingContext + // ID is the id argument value. + ID string + } // SetChain holds details about calls to the SetChain method. SetChain []struct { // Ctx is the ctx argument value. @@ -908,6 +923,7 @@ type NexusMock struct { lockLinkAddresses sync.RWMutex lockRateLimitTransfer sync.RWMutex lockRegisterAsset sync.RWMutex + lockRouteMessage sync.RWMutex lockSetChain sync.RWMutex lockSetMessageExecuted sync.RWMutex lockSetMessageFailed sync.RWMutex @@ -1533,6 +1549,46 @@ func (mock *NexusMock) RegisterAssetCalls() []struct { return calls } +// RouteMessage calls RouteMessageFunc. +func (mock *NexusMock) RouteMessage(ctx cosmossdktypes.Context, routingCtx github_com_axelarnetwork_axelar_core_x_nexus_exported.RoutingContext, id string) error { + if mock.RouteMessageFunc == nil { + panic("NexusMock.RouteMessageFunc: method is nil but Nexus.RouteMessage was just called") + } + callInfo := struct { + Ctx cosmossdktypes.Context + RoutingCtx github_com_axelarnetwork_axelar_core_x_nexus_exported.RoutingContext + ID string + }{ + Ctx: ctx, + RoutingCtx: routingCtx, + ID: id, + } + mock.lockRouteMessage.Lock() + mock.calls.RouteMessage = append(mock.calls.RouteMessage, callInfo) + mock.lockRouteMessage.Unlock() + return mock.RouteMessageFunc(ctx, routingCtx, id) +} + +// RouteMessageCalls gets all the calls that were made to RouteMessage. +// Check the length with: +// +// len(mockedNexus.RouteMessageCalls()) +func (mock *NexusMock) RouteMessageCalls() []struct { + Ctx cosmossdktypes.Context + RoutingCtx github_com_axelarnetwork_axelar_core_x_nexus_exported.RoutingContext + ID string +} { + var calls []struct { + Ctx cosmossdktypes.Context + RoutingCtx github_com_axelarnetwork_axelar_core_x_nexus_exported.RoutingContext + ID string + } + mock.lockRouteMessage.RLock() + calls = mock.calls.RouteMessage + mock.lockRouteMessage.RUnlock() + return calls +} + // SetChain calls SetChainFunc. func (mock *NexusMock) SetChain(ctx cosmossdktypes.Context, chain github_com_axelarnetwork_axelar_core_x_nexus_exported.Chain) { if mock.SetChainFunc == nil { diff --git a/x/evm/keeper/message_router.go b/x/evm/keeper/message_route.go similarity index 89% rename from x/evm/keeper/message_router.go rename to x/evm/keeper/message_route.go index 59e69c6eea..f68163d48f 100644 --- a/x/evm/keeper/message_router.go +++ b/x/evm/keeper/message_route.go @@ -9,7 +9,7 @@ import ( const gasCost = storetypes.Gas(10000000) -func NewMessageRouter() nexus.MessageRouter { +func NewMessageRoute() nexus.MessageRoute { return func(ctx sdk.Context, _ nexus.RoutingContext, _ nexus.GeneralMessage) error { ctx.GasMeter().ConsumeGas(gasCost, "execute-message") diff --git a/x/evm/keeper/message_route_test.go b/x/evm/keeper/message_route_test.go new file mode 100644 index 0000000000..f326e007a3 --- /dev/null +++ b/x/evm/keeper/message_route_test.go @@ -0,0 +1,24 @@ +package keeper_test + +import ( + "testing" + + "github.com/axelarnetwork/axelar-core/testutils/fake" + "github.com/axelarnetwork/axelar-core/x/evm/keeper" + nexus "github.com/axelarnetwork/axelar-core/x/nexus/exported" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/assert" + "github.com/tendermint/tendermint/libs/log" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" +) + +func TestNewMessageRoute(t *testing.T) { + route := keeper.NewMessageRoute() + + t.Run("should increment the gas meter", func(t *testing.T) { + ctx := sdk.NewContext(fake.NewMultiStore(), tmproto.Header{}, false, log.TestingLogger()) + + assert.NoError(t, route(ctx, nexus.RoutingContext{}, nexus.GeneralMessage{})) + assert.Positive(t, ctx.GasMeter().GasConsumed()) + }) +} diff --git a/x/nexus/exported/types.go b/x/nexus/exported/types.go index 1af2d45faf..2aec97b507 100644 --- a/x/nexus/exported/types.go +++ b/x/nexus/exported/types.go @@ -26,8 +26,8 @@ type RoutingContext struct { Payload []byte } -// MessageRouter defines a function that implements message routing -type MessageRouter func(ctx sdk.Context, routingCtx RoutingContext, msg GeneralMessage) error +// MessageRoute defines a function that implements message routing +type MessageRoute func(ctx sdk.Context, routingCtx RoutingContext, msg GeneralMessage) error // TransferStateFromString converts a describing state string to the corresponding TransferState func TransferStateFromString(s string) TransferState { diff --git a/x/nexus/types/message_router.go b/x/nexus/types/message_router.go index 722c5464cb..d9fb6194ef 100644 --- a/x/nexus/types/message_router.go +++ b/x/nexus/types/message_router.go @@ -3,14 +3,15 @@ package types import ( "fmt" - exported "github.com/axelarnetwork/axelar-core/x/nexus/exported" sdk "github.com/cosmos/cosmos-sdk/types" + + exported "github.com/axelarnetwork/axelar-core/x/nexus/exported" ) // MessageRouter implements a message router based on the message's destination // chain's module name type MessageRouter interface { - AddRoute(module string, router exported.MessageRouter) MessageRouter + AddRoute(module string, router exported.MessageRoute) MessageRouter Route(ctx sdk.Context, routingCtx exported.RoutingContext, msg exported.GeneralMessage) error Seal() } @@ -18,19 +19,19 @@ type MessageRouter interface { var _ MessageRouter = (*messageRouter)(nil) type messageRouter struct { - routes map[string]exported.MessageRouter + routes map[string]exported.MessageRoute sealed bool } // NewMessageRouter creates a new MessageRouter interface instance func NewMessageRouter() MessageRouter { return &messageRouter{ - routes: make(map[string]exported.MessageRouter), + routes: make(map[string]exported.MessageRoute), sealed: false, } } -func (r *messageRouter) AddRoute(module string, router exported.MessageRouter) MessageRouter { +func (r *messageRouter) AddRoute(module string, router exported.MessageRoute) MessageRouter { if r.sealed { panic("cannot add handler (router sealed)") }