-
Notifications
You must be signed in to change notification settings - Fork 410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor events #586
Refactor events #586
Conversation
Codecov Report
@@ Coverage Diff @@
## master #586 +/- ##
==========================================
+ Coverage 59.74% 59.89% +0.15%
==========================================
Files 45 45
Lines 5212 5197 -15
==========================================
- Hits 3114 3113 -1
+ Misses 1873 1861 -12
+ Partials 225 223 -2
|
Uh oh... is this broken in cosmwasm-plus??? and I just tagged. I will fix that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice start.
Most of my comments are about ordering.
The other issue is it seems the message events aren't all stripped (or only stripped at the msg_server level). We need to strip them inside the keeper, especially before passing the events into reply
, so we don't expose it.
I just saw one test case below with 2 message type events and was quite surprised these were not already removed.
x/wasm/keeper/keeper.go
Outdated
@@ -299,6 +311,11 @@ func (k Keeper) instantiate(ctx sdk.Context, codeID uint64, creator, admin sdk.A | |||
return nil, nil, sdkerrors.Wrap(err, "dispatch") | |||
} | |||
|
|||
ctx.EventManager().EmitEvent(sdk.NewEvent( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please emit this before calling k.wasmVM.Instantiate
.
We have all needed info there, and this is the ordering from the spec.
I fixed the ibc reflect contract in CosmWasm/cosmwasm#1046 and copied it here so the test now works. With my review comments above, this is ready to merge in my eyes. You can also download the "official" contract builds here: https://github.com/CosmWasm/cosmwasm/releases/tag/v0.16.0%2Bcontracts (not just the one I built locally) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is good to merge. And we can do a follow-up PR to look into any little issues left.
I think it is 98% correct, just one issue about message event and reply
case err != nil: | ||
return nil, sdkerrors.Wrap(err, "submessages") | ||
case rsp != nil: | ||
result = rsp | ||
} | ||
// emit non message type events only |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good to clear, but in the spec, we need to clear the messages before we possibly place them inside reply.
I believe you need to do that inside DispatchSubmessages
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: I will raise this as a new issue (and to add tests if it works or not)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #587
@@ -530,6 +545,12 @@ func TestExecute(t *testing.T) { | |||
require.NotNil(t, contractAcct) | |||
assert.Equal(t, sdk.Coins(nil), bankKeeper.GetAllBalances(ctx, contractAcct.GetAddress())) | |||
|
|||
// and events emitted | |||
require.Len(t, em.Events(), 5) | |||
expEvt := sdk.NewEvent("execute", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
event 0 is the message and the other ones?
I find it nice to test all the types at least, makes it clear what is (expected to) happen
expEvt sdk.Events | ||
}{ | ||
"all good": { | ||
rsp: wasmvmtypes.Response{Data: []byte("foo")}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add a case where reply returns an attribute or event and ensure those get returned as well (I am sure they are, but if you want to write table tests to cover the use cases...)
Resolves #440
Implements EVENTS.md
Contains:
bank
module event of typemessage
when tokens are transferred to a contractgov_contract_result
for contractexecute
andmigrate
in the gov proposal handlerLeft to do:
TestIBCReflectContract
by a new contract version that reads from the right event