Skip to content

Commit

Permalink
Pass Payload from submsg to reply
Browse files Browse the repository at this point in the history
  • Loading branch information
chipshort committed Feb 19, 2024
1 parent 7f88c95 commit 0ca56bd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
5 changes: 3 additions & 2 deletions x/wasm/keeper/msg_dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,9 @@ func (d MessageDispatcher) DispatchSubmessages(ctx sdk.Context, contractAddr sdk

// now handle the reply, we use the parent context, and abort on error
reply := wasmvmtypes.Reply{
ID: msg.ID,
Result: result,
ID: msg.ID,
Result: result,
Payload: msg.Payload,
}

// we can ignore any result returned as there is nothing to do with the data
Expand Down
26 changes: 26 additions & 0 deletions x/wasm/keeper/msg_dispatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper
import (
"errors"
"fmt"
"reflect"
"testing"

wasmvmtypes "github.com/CosmWasm/wasmvm/v2/types"
Expand Down Expand Up @@ -347,6 +348,31 @@ func TestDispatchSubmessages(t *testing.T) {
sdk.NewEvent("wasm-reply"),
},
},
"wasm reply gets payload": {
// put fake wasmmsg in here to show where it comes from
msgs: []wasmvmtypes.SubMsg{{ID: 1, ReplyOn: wasmvmtypes.ReplyAlways, Payload: []byte("payloadData"), Msg: wasmvmtypes.CosmosMsg{Wasm: &wasmvmtypes.WasmMsg{}}}},
replyer: &mockReplyer{
replyFn: func(ctx sdk.Context, contractAddress sdk.AccAddress, reply wasmvmtypes.Reply) ([]byte, error) {
if reply.Result.Err != "" {
return nil, errors.New(reply.Result.Err)
}

// ensure we got the payload
if !reflect.DeepEqual(reply.Payload, []byte("payloadData")) {
return nil, fmt.Errorf("payload mismatch: %s != 'payloadData'", reply.Payload)
}

// update data from what we got in
return reply.Result.Ok.Data, nil
},
},
msgHandler: &wasmtesting.MockMessageHandler{
DispatchMsgFn: func(ctx sdk.Context, contractAddr sdk.AccAddress, contractIBCPortID string, msg wasmvmtypes.CosmosMsg) (events []sdk.Event, data [][]byte, msgResponses [][]*codectypes.Any, err error) {
return nil, nil, [][]*codectypes.Any{}, nil
},
},
expCommits: []bool{true},
},
"non-wasm reply events get filtered": {
// show events from a stargate message gets filtered out
msgs: []wasmvmtypes.SubMsg{{ID: 1, ReplyOn: wasmvmtypes.ReplyAlways, Msg: wasmvmtypes.CosmosMsg{Any: &wasmvmtypes.AnyMsg{}}}},
Expand Down

0 comments on commit 0ca56bd

Please sign in to comment.