From b0885b03c907e36fb3c80913ed29d526164ade49 Mon Sep 17 00:00:00 2001 From: Alex Peters Date: Fri, 25 Jun 2021 10:44:39 +0200 Subject: [PATCH] Empty (non nil) reply data can overwrites response --- x/wasm/keeper/msg_dispatcher.go | 2 +- x/wasm/keeper/msg_dispatcher_test.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/x/wasm/keeper/msg_dispatcher.go b/x/wasm/keeper/msg_dispatcher.go index 0e3db65ca81..a81a57014e9 100644 --- a/x/wasm/keeper/msg_dispatcher.go +++ b/x/wasm/keeper/msg_dispatcher.go @@ -144,7 +144,7 @@ func (d MessageDispatcher) DispatchSubmessages(ctx sdk.Context, contractAddr sdk switch { case err != nil: return nil, sdkerrors.Wrap(err, "reply") - case len(rspData) != 0: + case rspData != nil: rsp = rspData } } diff --git a/x/wasm/keeper/msg_dispatcher_test.go b/x/wasm/keeper/msg_dispatcher_test.go index f152b4f2216..dde46773a08 100644 --- a/x/wasm/keeper/msg_dispatcher_test.go +++ b/x/wasm/keeper/msg_dispatcher_test.go @@ -166,7 +166,7 @@ func TestDispatchSubmessages(t *testing.T) { expData: []byte("myReplyData:2"), expCommits: []bool{false, false}, }, - "multiple msg - last reply with non nil": { + "multiple msg - last non nil reply to overwrite responose": { msgs: []wasmvmtypes.SubMsg{{ID: 1, ReplyOn: wasmvmtypes.ReplyError}, {ID: 2, ReplyOn: wasmvmtypes.ReplyError}}, replyer: &mockReplyer{ replyFn: func(ctx sdk.Context, contractAddress sdk.AccAddress, reply wasmvmtypes.Reply) ([]byte, error) { @@ -184,7 +184,7 @@ func TestDispatchSubmessages(t *testing.T) { expData: []byte("myReplyData:1"), expCommits: []bool{false, false}, }, - "multiple msg - last reply can be empty to overwrite": { + "multiple msg - empty reply can overwrite result": { msgs: []wasmvmtypes.SubMsg{{ID: 1, ReplyOn: wasmvmtypes.ReplyError}, {ID: 2, ReplyOn: wasmvmtypes.ReplyError}}, replyer: &mockReplyer{ replyFn: func(ctx sdk.Context, contractAddress sdk.AccAddress, reply wasmvmtypes.Reply) ([]byte, error) { @@ -199,7 +199,7 @@ func TestDispatchSubmessages(t *testing.T) { return nil, nil, errors.New("my error") }, }, - expData: []byte("myReplyData:1"), + expData: []byte{}, expCommits: []bool{false, false}, }, "empty replyOn rejected": {