Skip to content
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

Merged
merged 5 commits into from
Aug 11, 2021
Merged

Refactor events #586

merged 5 commits into from
Aug 11, 2021

Conversation

alpe
Copy link
Contributor

@alpe alpe commented Aug 10, 2021

Resolves #440

Implements EVENTS.md
Contains:

  • Filter out bank module event of type message when tokens are transferred to a contract
  • New event type gov_contract_result for contract execute and migrate in the gov proposal handler

Left to do:

  • test new events in keeper
  • fix TestIBCReflectContract by a new contract version that reads from the right event
  • order of events

@codecov
Copy link

codecov bot commented Aug 10, 2021

Codecov Report

Merging #586 (0e49169) into master (0d2b291) will increase coverage by 0.15%.
The diff coverage is 73.80%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
x/wasm/keeper/events.go 100.00% <ø> (ø)
x/wasm/keeper/msg_server.go 0.00% <0.00%> (ø)
x/wasm/keeper/keeper.go 87.05% <100.00%> (+1.47%) ⬆️
x/wasm/keeper/proposal_handler.go 63.10% <100.00%> (-8.33%) ⬇️
x/wasm/handler.go 70.00% <0.00%> (-7.50%) ⬇️

@ethanfrey
Copy link
Member

fix TestIBCReflectContract by a new contract version that reads from the right event

Uh oh... is this broken in cosmwasm-plus??? and I just tagged. I will fix that

Copy link
Member

@ethanfrey ethanfrey left a 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.

EVENTS.md Show resolved Hide resolved
x/wasm/keeper/keeper.go Show resolved Hide resolved
x/wasm/keeper/keeper.go Outdated Show resolved Hide resolved
x/wasm/keeper/keeper.go Outdated Show resolved Hide resolved
x/wasm/keeper/keeper.go Outdated Show resolved Hide resolved
x/wasm/keeper/keeper_test.go Outdated Show resolved Hide resolved
x/wasm/keeper/proposal_handler.go Show resolved Hide resolved
x/wasm/keeper/proposal_handler.go Show resolved Hide resolved
x/wasm/keeper/proposal_integration_test.go Outdated Show resolved Hide resolved
@@ -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(
Copy link
Member

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.

@ethanfrey
Copy link
Member

ethanfrey commented Aug 11, 2021

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)

@alpe alpe marked this pull request as ready for review August 11, 2021 12:47
Copy link
Member

@ethanfrey ethanfrey left a 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

x/wasm/keeper/keeper.go Show resolved Hide resolved
case err != nil:
return nil, sdkerrors.Wrap(err, "submessages")
case rsp != nil:
result = rsp
}
// emit non message type events only
Copy link
Member

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

Copy link
Member

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)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #587

x/wasm/keeper/keeper_test.go Show resolved Hide resolved
@@ -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",
Copy link
Member

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

x/wasm/keeper/keeper_test.go Show resolved Hide resolved
expEvt sdk.Events
}{
"all good": {
rsp: wasmvmtypes.Response{Data: []byte("foo")},
Copy link
Member

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...)

x/wasm/keeper/msg_server.go Show resolved Hide resolved
x/wasm/module_test.go Show resolved Hide resolved
@ethanfrey ethanfrey merged commit 7b2e84c into master Aug 11, 2021
@alpe alpe deleted the event_types_440 branch August 11, 2021 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Revisit event types
2 participants