foundry-rs / foundry-rs/foundry

feat(`debugger`): improve debugger experience when tests fail due to event mismatch

Open
#10,342 6 comments 0 reactions 0 assignees View on GitHub
A-debugger C-cast C-forge T-feature
Dominant language
Rust
Stars
10.6k
Forks
2.6k
Avg merge
16h 38m
Merged PRs (30d)
511

Description

### Component

Forge, Foundryup

### Describe the feature you would like

### Problem

When a test fails due to event mismatch, Foundry logs `FAIL: log != expected log; counterexample calldata=0x1234....1234` without specifying which event parameter did not match.

Though this is fine for simple tests, in case of fuzz testing, it becomes very problematic. This is because Foundry prints lengthy `calldata` forcing to scroll extensively to trace down the error.

![Image](https://github.com/user-attachments/assets/b3f53f09-0f8f-4207-bc0e-993c3943f03a)

👾 [Link to warp block](https://app.warp.dev/block/LO8P0XzdGwbeHxToZdRhp7)

### Solution 1

Log the first mismatched event parameter in the failure message:

```bash
FAIL: log != expected log event_name:event_parameter expectedValue != actualValue; counterexample calldata=0x1234..1234
```

This would make it easier to identify which event parameter did not match with the expected value without having to scroll down so much.

### Solution 2

Add a Foundry cheat code to enable/disable `calldata` logs. It can be called `display_calldata`

Most of the times, having `calldata` printed is of little value. This is because, use of `bound` can change the value of the input parameters. Thus, having a cheatcode to enable `calldata` logging can be more useful than having it enabled by default.

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.