-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat(cheatcodes
): decode and show mismatched params on expectEmit
#11098
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
Conversation
cheatcodes
): show mismatched params in events
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.
that's awesome, is there any way we could decode and show mismatched values?
I think we should be able to do it with |
cheatcodes
): show mismatched params in eventscheatcodes
): show mismatched params on expectEmit
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.
Much better! 👍
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.
thank you, left some initial nits / questions
crates/cheatcodes/src/test/expect.rs
Outdated
let event = foundry_common::block_on(identifier.identify_event(t0))?; | ||
|
||
// Check if event already has correct indexed flags | ||
let indexed_count = event.inputs.iter().filter(|p| p.indexed).count(); |
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.
isn't this logic already covered in get_indexed_event
fn so we could just do here
let event = foundry_common::block_on(identifier.identify_event(t0))?;
let indexed_event = get_indexed_event(event, log);
// Try to decode the event
if let Ok(decoded) = indexed_event.decode_log(log) {
...
?
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 because get_indexed_event
is using a heuristic which gives preference to an address
while categorizing whether a param is indexed
or not.
It incorrectly guesses the number of indexed
parameters for:
event MixedEventNumbering(
uint256 indexed param0,
address indexed param1,
uint256 param2,
uint256 param3,
address param4 // Marks this as `indexed` leading to decoding failure.
);
This is due to this if condition:
if num_inputs == indexed_params
|| (num_address_params == indexed_params && param.ty == "address") // 2nd condition is true for above event
{
param.indexed = true;
}
So, TL;DR don't use get_indexed_event
if we already know the indexed params
cheatcodes
): show mismatched params on expectEmitcheatcodes
): decode and show mismatched params on expectEmit
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, thank you, left one more optional nit
Motivation
Supersedes #8686
Closes #592
Closes #8506
Solution
log != expected log
has been replaced with the named event variant:ComplexEvent != expected SimpleEvent
if decoding is successfulexpected
andgot
(actual) data. For example, consider the following test:This test will fail with:
log.topics
and also the non-indexed params which are part of thelog.data
.0
.emitter
mismatch: thelog emitter mismatch: expected=0x..., got=0x...
error is thrownSignaturesIdentifier
has now been added to theCheatcodes
struct -Decoding only works over local selectors cache.PR Checklist