1

I have the following function:

function doStuff() external {
        emit MyEvent();
    }

And in my foundry tests, I want to check to make sure this event was NOT emitted. How do I do that?

1 Answer 1

2

There isn't way to check if an event is NOT emitted, but for your purpose you can use vm.getRecordedLogs(); and assert that the length of the logs array is 0.

function testDoesNotEmit() public {
Vm.Log[] memory entries = vm.getRecordedLogs();
 
//
// Code that does not emit event
// 

assertEq(entries.length, 0); 
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.