How does the testEnteringRaffleEmitsEvent
function work?
#3519
-
Hi everyone, Here is the function I have questions about: function testEnteringRaffleEmitsEvent() public funded {
// Arrange
vm.prank(PLAYER);
// Act
vm.expectEmit(true, false, false, false, address(raffle));
emit RaffleEntered(PLAYER);
// Assert
raffle.enterRaffle{value: entranceFee}();
} I do not understand why we need to emit the event within the test, because then we are not testing I was thinking it should be like this, because function testEnteringRaffleEmitsEvent() public funded {
// Arrange
vm.prank(PLAYER);
// Act
vm.expectEmit(true, false, false, false, address(raffle));
// Assert
raffle.enterRaffle{value: entranceFee}();
} Can someone clarify it for me? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Bro
We write this part above because the expectEmit function is defined in this way:
In fact, we are saying that we expect an event with these parameters to be emitted, but something is still missing.
Here, we manually (mock) emit the event that we expect and event name and value are specified.
Then by calling the function, the actual event is emitted and compared with our expectations. |
Beta Was this translation helpful? Give feedback.
Bro
We write this part above because the expectEmit function is defined in this way:
In fact, we are saying that we expect an event with these parameters to be emitted, but something is still missing.
We haven't specified the name and value of the event, so we need to add the following line as well :
Here, we manually (mock) emit the event that we expect and event name and value are specified.
Think of it this way: it’s like saying, “Wait, an event is going to be emitted. O…