Skip to content

Commit

Permalink
allow to failed with invalid message
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 committed Oct 11, 2024
1 parent 8414620 commit f1155ac
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
10 changes: 5 additions & 5 deletions x/move/keeper/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,16 +480,16 @@ func (k Keeper) dispatchMessage(parentCtx sdk.Context, message vmtypes.CosmosMes

var msg proto.Message
if stargateMsg, ok := message.(*vmtypes.CosmosMessage__Stargate); ok {
// callback only exists in stargate message
allowFailure = stargateMsg.Value.AllowFailure
callback = stargateMsg.Value.Callback
callbackSender = stargateMsg.Value.Sender

// validate basic & signer check is done in HandleVMStargateMsg
msg, err = k.HandleVMStargateMsg(ctx, &stargateMsg.Value)
if err != nil {
return
}

// callback only exists in stargate message
allowFailure = stargateMsg.Value.AllowFailure
callback = stargateMsg.Value.Callback
callbackSender = stargateMsg.Value.Sender
} else {
// signer check had been done in moveVM
msg, err = types.ConvertToSDKMessage(ctx, NewMoveBankKeeper(&k), NewNftKeeper(&k), message, k.ac, k.vc)
Expand Down
25 changes: 23 additions & 2 deletions x/move/keeper/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,13 +604,13 @@ func TestSubmsgCallback(t *testing.T) {
msgData, err := input.EncodingConfig.Codec.MarshalInterfaceJSON(msg)
require.NoError(t, err)

// 1. callback without signer
// 0. invalid message should not failed
err = input.MoveKeeper.ExecuteEntryFunctionJSON(ctx, senderAddr, vmtypes.TestAddress,
"submsg",
"stargate",
[]vmtypes.TypeTag{},
[]string{
fmt.Sprintf("\"%s\"", hex.EncodeToString(msgData)),
"\"abcd\"",
"true",
"\"123\"",
fmt.Sprintf("\"%s::submsg::callback_without_signer\"", vmtypes.TestAddress),
Expand All @@ -625,6 +625,27 @@ func TestSubmsgCallback(t *testing.T) {
sdk.NewAttribute("data", "{\"id\":\"123\",\"success\":false}"),
), event)

// 1. callback without signer
err = input.MoveKeeper.ExecuteEntryFunctionJSON(ctx, senderAddr, vmtypes.TestAddress,
"submsg",
"stargate",
[]vmtypes.TypeTag{},
[]string{
fmt.Sprintf("\"%s\"", hex.EncodeToString(msgData)),
"true",
"\"123\"",
fmt.Sprintf("\"%s::submsg::callback_without_signer\"", vmtypes.TestAddress),
})
require.NoError(t, err)

events = ctx.EventManager().Events()
event = events[len(events)-1]

require.Equal(t, sdk.NewEvent("move",
sdk.NewAttribute("type_tag", "0x2::submsg::ResultEvent"),
sdk.NewAttribute("data", "{\"id\":\"123\",\"success\":false}"),
), event)

// events should not be committed
for _, e := range events {
require.NotEqual(t, e.Type, "move_execute_with_json")
Expand Down

0 comments on commit f1155ac

Please sign in to comment.