-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
feat: add count to expectCall
cheatcodes
#4833
Conversation
696a99b
to
2e85835
Compare
Adding cheatcodes 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.
wdyt @mds1
/// The number of times the call is expected to be made | ||
pub count: u64, |
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 can see how this could be useful
Yep in favor of this, per #509 (comment). We should also add a similar overload for Also @reubenr0d two questions:
|
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,
tests look great
It looks like the regular I'm not sure if this was intentional, but personally I'm ok with this change. Curious to hear your thoughts here @reubenr0d @mattsse. If we keep it, @reubenr0d do you mind getting another PR in to forge-std to update the code comments in |
Just to chime in: we were using expectCall to generically verify all functions from our ABI had been called in a test with code similar to:
With the new API we cannot do this entirely generically since some functions will be invoked multiple times. I am OK with the change, just wanted to mention it :) |
Hmm, on second thought and on seeing that other might have issues with this, I think it's best we preserve compatibility. I'll push a fix for this shortly. |
If I put 10 expectCalls, would it expect 10 calls? I.e. do they sum up if I add more expectCall lines? Cause that's what I was thinking how it works and had several expectCalls lines if I expected several (identical) calls. But now it fails after I've upgraded. So should I just leave one expectCall put a number there now? |
It should definitely work like this. See @reubenr0d's comment here: |
Closes #4513
Motivation
Currently we can only assert that a call is made to a function using expectCall(), it would be nice to have another cheatcode to check the number of time a call was made, which can also be useful to assert if a call is not made.
Solution
Overriding the
expectCall
cheatcodes to also accept the number of times it is expected to be called and enforce the same.