-
Notifications
You must be signed in to change notification settings - Fork 608
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
x/lockup: ensure events are emitted and tests added #2391
Conversation
} | ||
|
||
// Question: Any way we can make this private method? | ||
func BeginUnlockEvent(lock *types.PeriodLock) sdk.Event { |
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.
We use this Event to append here
It would be ideal to make this a private method, but i dont want to repeat code
2c55587
to
9120a4a
Compare
) | ||
} | ||
|
||
// EmitLockToken returns a new event when user lock tokens. |
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.
// EmitLockToken returns a new event when user lock tokens. | |
// EmitExtendLockToken returns a new event when user locks tokens. |
x/lockup/keeper/msg_server.go
Outdated
sdk.NewAttribute(types.AttributePeriodLockAmount, msg.Coins.String()), | ||
), | ||
}) | ||
events.EmitAddTokenToLock(ctx, lockID, msg.Owner, msg.Coins.String()) |
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 we should move this inside keeper so that if another module ends up calling AddToExistingLock
, the event does not get missed
x/lockup/keeper/msg_server.go
Outdated
), | ||
}) | ||
|
||
events.EmitLockToken(ctx, &lock) |
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.
ditto for moving this inside the keeper's CreateLock
Can we also add the event info to docs (README), please? |
I didn't add README.md following @alexanderbez comment here Didn't know what the final verdict was |
I think Bez is right that these tend to get out of sync and are difficult to maintain. However, these docs get auto-uploaded to our docs.osmosis.zone website. Currently, there is no information about events on the docs site. I think that this information could be useful for integrators. So, in my opinion, we should still have it |
Gotchu i'll definitely add it then |
@@ -0,0 +1,264 @@ | |||
package events_test |
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 entire test file seems like useless boilerplate, its questionable that we even needed these different EmitEvent
functions, we definitely don't need tests ensuring that the call to the emit function works correctly.
What tests are useful for is ensuring events are emitted after the actual.execution of relevant messages.
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 makes sense, the entire boilerplate tests definitely seems like an overkill. I will remove this so that we can test messages that emit these events directly in msg_server_test.go
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.
In my eyes, the goal at this level of abstraction is to test that attributes are set correctly. This is achieved by the tests here.
Then, it is possible to simply focus that a certain event kind is emitted at the keeper/message server layer. Given that we have already tested the attributes here in emit_test.go
, we can reduce the boilerplate in tests for keeper and simply call for testing the fact that an event has been emitted:
osmosis/app/apptesting/events.go
Line 7 in a1dc694
func (s *KeeperTestHelper) AssertEventEmitted(ctx sdk.Context, eventTypeExpected string, numEventsExpected int) { |
Otherwise, we would have to validate the attributes in keeper and message server tests which goes against the separation of concerns
I don't really like this entire direction. Every event here seems like we could derive it automatically from the message response, and these tests aren't actually helping check that we are emitting things correctly post message execution. At most extracting building an event to its own function makes sense to me. The |
if ctx.EventManager() == nil { | ||
return | ||
} |
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.
Why are we doing all these nil guards? Seems fine to me if it panics with NPE, this is misconfiguration that should get caught in testing, not be graceful no-op
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.
While I agree that no-op is probably not the way to go, I think it is worth having a check for nil event manager somewhere since ctx
is injected into Osmosis's message server by its dependency - cosmos-sdk
. I don't think we should be spending time on this right now though so it should be fine if we just remove the check
We should definitely make a decision on how we should structure events + test events as we've followed this structure in x/gamm and x/superfluid EPIC 2195 @p0mvn what do you think? |
actualEvents = append(actualEvents, event) | ||
} | ||
} | ||
|
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.
line [413-421] will be moved to app/apptesting/events.go
once i receive approach ack
x/lockup/keeper/msg_server_test.go
Outdated
} | ||
|
||
if tc.expectPass { | ||
suite.Require().Equal(expectedEvents[0], actualEvents[0]) |
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.
Tests the events type as well as its attributes
How can events be derived from the message response? I don't think it is possible in the example here. First, some messages emit events based on conditions. For example, Second, these should really not be in the message server but in keeper. Other modules can call
That's the goal of the
That's fine because we can do incremental refactorings. I think changing the direction now when there is a relevant PR merged and 2 more are in progress, leading to inconsistent designs would be difficult to manage. I also don't see how most of these events can be generated right now due to the reasons mentioned above.
I mentioned the original thinking for the To summarize my thinking:
@ValarDragon @stackman27 please let me know what you think |
Hi @stackman27 Just wanted to follow up here as well. Dev and I discussed this offline. Let's move the events to keeper please but not use the internal/events logic. Please feel free to add tests like you were doing before. We’ll not pursue the events QA further unless asked for by integrators and wait for improvements from the SDK Sorry for having this blocked for quite some time |
Gotchu! Thank you for sorting this out. I will continue adding new tests |
94898bf
to
abaa467
Compare
This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Thank you! |
Closes: #2270
What is the purpose of the change
Currently, our tests are missing assertions about events. Moreover, it seems that some of our events are missing based on
1939
The lockup module emits the following events:
There are 4 types of events that exist in lockup module:
types.TypeEvtLockTokens
- "lock_tokens"types.TypeEvtAddTokensToLock
- "add_tokens_to_lock"types.TypeEvtBeginUnlockAll
- "begin_unlock_all"types.TypeEvtBeginUnlock
- "begin_unlock"Testing and Verifying
Documentation and Release Note
Unreleased
section inCHANGELOG.md
? (no)x/<module>/spec/
) / Osmosis docs repo / not documented)