reason of error [FAIL. Reason: log != expected log]
contract RaffleTest is Test {
/** */
event EnterRaffle(address indexed player);
function testEmitsEventOnEntrance() public {
// Arrange
vm.prank(PLAYER);
// Act / Assert
vm.expectEmit(true, false, false, false, address(raffle));
emit EnterRaffle(PLAYER);
raffle.enterRaffle{value: entranceFee}();
}
}
contract Raffle is VRFConsumerBaseV2 {
/**Event */
event EnterRaffle(address player);
function enterRaffle() public payable {
s_players.push(payable(msg.sender));
emit EnterRaffle(msg.sender);
}
}
when run the code above with forge test –match-test testEmitsEventOnEntrance
the test will fail and throw alarm like this
[⠊] Compiling...
[⠃] Compiling 38 files with Solc 0.8.19
[⠒] Solc 0.8.19 finished in 1.93s
Compiler run successful!
Ran 1 test for test/RaffleTest.t.sol:RaffleTest
[FAIL. Reason: log != expected log] testEmitsEventOnEntrance() (gas: 68450)
Suite result: FAILED. 0 passed; 1 failed; 0 skipped; finished in 6.44ms (506.96µs CPU time)
the reason is that event in RaffleTest is
event EnterRaffle(address indexed player);
event in Raffle is
event EnterRaffle(address player);
this two event with indexed param and without indexed param was considered as different events.
so i remove the indexed and then pass the test case.