foundry-rs / foundry

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
https://getfoundry.sh
Apache License 2.0
8.17k stars 1.7k forks source link

feat(`tracing`): log failed `expectEmit` events as error traces #8506

Open topocount opened 2 months ago

topocount commented 2 months ago

Component

Forge

Describe the feature you would like

Currently, the tracer and error logger aren't very helpful when a matching event is not caught. I'd like to attempt to highlight the mismatched event(s) in red instead of white (or neutral) as they they are currently displayed by the tracer.

I'd like to contribute this small feature myself.

Additional context

This seems like a superficial improvement, but digging through large stack traces of emitted logs, trying to manually pick out the one that failed can be quite time consuming during development and integration testing.

zerosnacks commented 2 months ago

Hi @topocount thanks for your suggestion, any stylistic changes to traces are to be applied in https://github.com/paradigmxyz/revm-inspectors/blob/main/src/tracing/writer.rs and changes to indicating whether something is an error is to be done in Foundry (it may be the case that it requires that).

zerosnacks commented 2 months ago

Assigned this to you @topocount, please let me know if you need any pointers or have any questions along the way

topocount commented 2 months ago

Hey @zerosnacks I think I have a bead on an implementation path. Thanks for your guidance

please let me know if you need any pointers or have any questions along the way

don't you mean "borrows?" :sunglasses:

topocount commented 1 month ago

@zerosnacks is it okay if I create a new error in the cheatcodes package that that holds the abi-encoded bytestring of the unmatched event? I'd also like to capture the index of the event in the expected_events Deque in case multiple events with same exact parameters are expected, so something like:

error UnmatchedEvent(uint256 positionExpected, bytes rawLog);
zerosnacks commented 1 month ago

I'm not sure if I understand it completely but it makes sense to me to pass the reverted error in a structured manner.

Perhaps using an error with two structs holding an Expected case and a Result case makes this format more generalizable. Feel free to open a draft PR, that way others can chime in more easily as well.