dapptools icon indicating copy to clipboard operation
dapptools copied to clipboard

Feature request: Test event emissions

Open mds1 opened this issue 4 years ago • 2 comments
trafficstars

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?

mds1 avatar Jul 08 '21 15:07 mds1

+1 it'd be great to have this feature back.

It seems like this was supported in dapple and DSTest but it was removed?

gakonst avatar Sep 04 '21 11:09 gakonst

Yes I'd love to see this as well.

lucas-manuel avatar Sep 06 '21 01:09 lucas-manuel