Add failing testcase showing messages make it into reply block
This commit is contained in:
@@ -1080,6 +1080,7 @@ func (h DefaultWasmVMContractResponseHandler) Handle(ctx sdk.Context, contractAd
|
||||
case rsp != nil:
|
||||
result = rsp
|
||||
}
|
||||
// TODO: remove this - handled inside DispatchSubmessages
|
||||
// emit non message type events only
|
||||
for _, e := range em.Events() {
|
||||
if e.Type != sdk.EventTypeMessage {
|
||||
|
||||
@@ -85,6 +85,7 @@ func TestDispatchSubmessages(t *testing.T) {
|
||||
}},
|
||||
replyer: &mockReplyer{
|
||||
replyFn: func(ctx sdk.Context, contractAddress sdk.AccAddress, reply wasmvmtypes.Reply) ([]byte, error) {
|
||||
ctx.EventManager().EmitEvent(sdk.NewEvent("wasm-reply"))
|
||||
return []byte("myReplyData"), nil
|
||||
},
|
||||
},
|
||||
@@ -99,7 +100,9 @@ func TestDispatchSubmessages(t *testing.T) {
|
||||
expEvents: []sdk.Event{{
|
||||
Type: "myEvent",
|
||||
Attributes: []abci.EventAttribute{{Key: []byte("foo"), Value: []byte("bar")}},
|
||||
}},
|
||||
},
|
||||
sdk.NewEvent("wasm-reply"),
|
||||
},
|
||||
},
|
||||
"with context events - released on commit": {
|
||||
msgs: []wasmvmtypes.SubMsg{{
|
||||
@@ -266,6 +269,53 @@ func TestDispatchSubmessages(t *testing.T) {
|
||||
expData: []byte{},
|
||||
expCommits: []bool{false, false},
|
||||
},
|
||||
"reply gets proper events": {
|
||||
msgs: []wasmvmtypes.SubMsg{{ID: 1, ReplyOn: wasmvmtypes.ReplyAlways}},
|
||||
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)
|
||||
}
|
||||
res := reply.Result.Ok
|
||||
|
||||
// ensure the input events are what we expect
|
||||
// I didn't use require.Equal() to act more like a contract... but maybe that would be better
|
||||
if len(res.Events) != 2 {
|
||||
return nil, fmt.Errorf("event count: %#v", res.Events)
|
||||
}
|
||||
if res.Events[0].Type != "execute" {
|
||||
return nil, fmt.Errorf("event0: %#v", res.Events[0])
|
||||
}
|
||||
if res.Events[0].Type != "wasm" {
|
||||
return nil, fmt.Errorf("event1: %#v", res.Events[1])
|
||||
}
|
||||
|
||||
// let's add a custom event here and see if it makes it out
|
||||
ctx.EventManager().EmitEvent(sdk.NewEvent("wasm-reply"))
|
||||
|
||||
// update data from what we got in
|
||||
return res.Data, nil
|
||||
},
|
||||
},
|
||||
msgHandler: &wasmtesting.MockMessageHandler{
|
||||
DispatchMsgFn: func(ctx sdk.Context, contractAddr sdk.AccAddress, contractIBCPortID string, msg wasmvmtypes.CosmosMsg) (events []sdk.Event, data [][]byte, err error) {
|
||||
events = []sdk.Event{
|
||||
sdk.NewEvent("message", sdk.NewAttribute("_contract_address", contractAddr.String())),
|
||||
// we don't know what the contarctAddr will be so we can't use it in the final tests
|
||||
sdk.NewEvent("execute", sdk.NewAttribute("_contract_address", "placeholder-random-addr")),
|
||||
sdk.NewEvent("wasm", sdk.NewAttribute("random", "data")),
|
||||
}
|
||||
return events, [][]byte{[]byte("subData")}, nil
|
||||
},
|
||||
},
|
||||
expData: []byte("subData"),
|
||||
expCommits: []bool{true},
|
||||
expEvents: []sdk.Event{
|
||||
sdk.NewEvent("execute", sdk.NewAttribute("_contract_address", "placeholder-random-addr")),
|
||||
sdk.NewEvent("wasm", sdk.NewAttribute("random", "data")),
|
||||
sdk.NewEvent("wasm-reply"),
|
||||
},
|
||||
},
|
||||
}
|
||||
for name, spec := range specs {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user