β Event
Setup
Target contract:
Test file:
Test event example 1
To test event, follow these 3 steps:
Tell Foundry which data to check
Emit the expected event
Call the function that should emit the event
In step 1, we call vm.expectEmit(). Here is its definition:
The checked event must be indexed. For example, our Transfer event has two indexed parameters:
Writing a test case:
Test event example 2
We can choose to only test some of the parameters:
In this case, if index 1 matches then the test will pass.
Test multiple events
To test multiple events emitted by a single function, we put step 1 and step 2 into a for loop, and then call the function outside the for loop:
Last updated
Was this helpful?