-
Notifications
You must be signed in to change notification settings - Fork 354
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
Test token hooks #1198
Test token hooks #1198
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1198 +/- ##
==========================================
- Coverage 91.57% 91.56% -0.02%
==========================================
Files 47 47
Lines 1223 1233 +10
==========================================
+ Hits 1120 1129 +9
- Misses 103 104 +1 see 6 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
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.
LGTM!
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.
LGTM!
Co-authored-by: immrsd <103599616+immrsd@users.noreply.github.com>
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.
Good call on using events to test the hooks! I left a question and some minor suggestions. Also, I think we should apply the same tests to erc1155 as well so all token hooks are tested before we close out the issue
fn assert_event_before_update( | ||
ref self: EventSpy, | ||
contract: ContractAddress, | ||
from: ContractAddress, | ||
recipient: ContractAddress, | ||
amount: u256 | ||
) { | ||
let expected = ERC20MockWithHooks::Event::BeforeUpdate( | ||
ERC20MockWithHooks::BeforeUpdate { from, recipient, amount } | ||
); | ||
self.assert_emitted_single(contract, expected); | ||
} | ||
|
||
fn assert_event_after_update( | ||
ref self: EventSpy, | ||
contract: ContractAddress, | ||
from: ContractAddress, | ||
recipient: ContractAddress, | ||
amount: u256 | ||
) { | ||
let expected = ERC20MockWithHooks::Event::AfterUpdate( |
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.
What do you think about adding assert_no_events_left_from(contract)
to these?
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.
If you agree, I'd apply this to erc721 as well
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.
update
itself emits a Transfer
event, so I think this would only make sense on the after hook. But not sure how valuable it is?
I'll prioritize the other comments + adding the tests to ERC1155
and then see if I can add this
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.
update itself emits a Transfer event, so I think this would only make sense on the after hook
To be comprehensive, my thinking is to test that only the target hook is executed and only once. I suppose you can argue that we know it works as expected through the myriad other tests we have...your call if you think it's worth it
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.
Since we are getting the release today I'll go ahead and merge. Will try to add this to a next PR. Thanks!
Comments have been incorporated + renamed the new mocks to |
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.
LGTM! Left a final non-blocking comment
Fixes #1062
PR Checklist