dapphub / dapphub/dapptools

Feature request: Test event emissions

Open
#696 2 comments 5 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
2.1k
Forks
320
PR merge metrics
No merged PRs in 30d

Description

It would be great if we could test for certain events and parameter to be emitted. Quoting from the chat on possible syntaxes: https://dapphub.chat/channel/dev?msg=GisKDrLJtiAGzznyE

> mds1 12:04 PM
> There's a few options I can think of (no idea how implementation of these compares):
> 1. First thought was a modifier similar to the `revertData` modifier discussed above, e.g. `expectEvent("MyEvent(uint)", 45)` to look for the number 45, or `expectEvent("MyEvent(uint)")` to consider any `uint` value passing (or pass the event hash instead of it's signature as a string). One problem with this syntax is you can't specify which call in your test should emit the event
> 2. Instead of `expectEvent` being a modifier, it could just be a method, and when called (with the same syntax as above) it checks the most recent transaction for the event
> 3. Last idea is that it could take the target and calldata and execute the call for you, e.g. `expectEvent(address target, bytes calldata, string eventSignature, bytes optionalExpectedValues)`. This would method would need to surface the call's return data so you can still access it if needed
> > mrchico 3:10 AM
> > these are good ideas. I think option 2 is my favorite. This could also be done in a cheat code kind of way, perhaps. Like `hevm.getLog(index)(bytes)`, giving the bytestring of the latest-index emitted log
> > > mds1 6:16 AM
> > > Agreed, of those option 2 was my favorite as well. The cheat code approach seems comparable, so no objections there from me. Only question is how would you get the log's bytestring from within your test?

Contributor guide

No contributing guide indexed for this repository

Research direction

No file, test, or entry point is named. Start by resolving whether event assertions should be a modifier, a method for the latest transaction, or a cheat code, then define how logs and expected values are exposed and what tests would demonstrate completion.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
testing, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.