foundry-rs / foundry-rs/foundry

feature: make tests fail when some of the emitted events aren't explicitly "expected"

Open
#4,997 2 comments 0 reactions 0 assignees View on GitHub
A-cheatcodes A-config C-forge T-feature T-post-V1
Dominant language
Rust
Stars
10.6k
Forks
2.6k
Avg merge
18h 20m
Merged PRs (30d)
510

Description

### Component

Forge

### Describe the feature you would like

I'd like to be able to configure Foundry tests to fail if, during their execution, some other events have also been emitted besides the ones I've explicitly specified via `vm.expectEmit()`.

More precisely, if, in my test, all I do is call a function `f()` that successfully executes and emits an event `E()`, my test succeeds both when I "vm.expectEmit()" `E()` - and when I don't "expect" it.

Especially when Unit Testing, it's natural to want to know everything that is happening during a test, to make sure you're not overlooking some seemingly small things that might transform into more serious problems at Integration Testing - or, worse - in production.

Besides, if you do care about all of the events emitted during a test, but have forgotten to "expect" some of them, you, quite likely, also risk forgetting some extra use-cases related to the missed events that you would like to check for/verify in your test. The Foundry framework notifying you about these missed events would help with this, too.

I admit that this might not be a behaviour you'd like to have at all times (for example, it'd be too much to have to "expect" all of the events emitted during an Integration test). However, I think it's important to be able to get this behaviour (via a configuration setting or something) when you do want/need it!

### 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.