foundry-rs / foundry-rs/foundry

feat(cheatcodes): Add option in `vm.recordLogs` to filter by topic and/or emitter address

Open
#7,321 0 comments 2 reactions 0 assignees View on GitHub
A-cheatcodes T-feature
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

It would be very useful to be able to filter the logs that get recorded by `recordLogs()` via their topic (event selector) or emitted address.

I would love to see an overload of the `recordLogs` cheatcode which would accept as input a list of event selectors (either as a single array, or maybe separate arguments, up to X different topics for ease of use).
Another overload could likewise allow to filter by a list of emitter addresses.

Some API suggestions:

```solidity
function recordLogs() external;
function recordLogs(bytes32[] memory selectors) external;
function recordLogs(address[] memory emitters) external;

function recordLogs(bytes32 selector) external;
function recordLogs(bytes32 selector1, bytes32 selector2) external;
function recordLogs(bytes32 selector1, bytes32 selector2, bytes32 selector3) external;
// ...

function recordLogs(address emitter) external;
function recordLogs(address emitter1, address emitter2) external;
function recordLogs(address emitter1, address emitter2, address emitter3) external;
// ...

function recordLogs(address emitter, bytes32 selector) external;
```
Alternatively, these parameters could be added to the `getRecordedLogs` function.

### Additional context

This would make it trivial to retrieve a particular log and be sure that its position in the `Vm.Log[]` array is at the index 0. Likewise, checking that a particular event is or is not present in the logs emitted by a function call could be simplified by simply looking at the length of the returned array, instead of checking all emitted logs one by one.

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.