dapptools
dapptools copied to clipboard
Feature request: Test event emissions
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):
- First thought was a modifier similar to the
revertDatamodifier discussed above, e.g.expectEvent("MyEvent(uint)", 45)to look for the number 45, orexpectEvent("MyEvent(uint)")to consider anyuintvalue 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- Instead of
expectEventbeing 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- 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 neededmrchico 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 logmds1 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?
+1 it'd be great to have this feature back.
It seems like this was supported in dapple and DSTest but it was removed?
Yes I'd love to see this as well.