Skip to content

Commit 447ef28

Browse files
authored
fix(forge): do not revert if event with count 0 not emitted (#10534)
1 parent fb9904b commit 447ef28

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

crates/cheatcodes/src/inspector.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,8 +1656,9 @@ impl Inspector<&mut dyn DatabaseExt> for Cheatcodes {
16561656
})
16571657
.collect::<Vec<_>>();
16581658

1659-
// Not all emits were matched.
1660-
if self.expected_emits.iter().any(|(expected, _)| !expected.found) {
1659+
// Revert if not all emits expected were matched.
1660+
if self.expected_emits.iter().any(|(expected, _)| !expected.found && expected.count > 0)
1661+
{
16611662
outcome.result.result = InstructionResult::Revert;
16621663
outcome.result.output = "log != expected log".abi_encode().into();
16631664
return outcome;

crates/forge/tests/it/repros.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,3 +404,6 @@ test_repro!(10302);
404404

405405
// https://github.com/foundry-rs/foundry/issues/10477
406406
test_repro!(10477);
407+
408+
// https://github.com/foundry-rs/foundry/issues/10527
409+
test_repro!(10527);
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// SPDX-License-Identifier: MIT OR Apache-2.0
2+
pragma solidity ^0.8.18;
3+
4+
import "ds-test/test.sol";
5+
import "cheats/Vm.sol";
6+
7+
contract A {
8+
event Event1();
9+
event Event2();
10+
11+
function foo() public {
12+
emit Event1();
13+
}
14+
15+
function bar() public {
16+
emit Event2();
17+
}
18+
}
19+
20+
contract Issue10527Test is DSTest {
21+
Vm constant vm = Vm(HEVM_ADDRESS);
22+
23+
A a;
24+
25+
function setUp() public {
26+
a = new A();
27+
}
28+
29+
function test_foo_Event1() public {
30+
vm.expectEmit(address(a));
31+
emit A.Event1();
32+
33+
a.foo();
34+
}
35+
36+
function test_foo_Event2() public {
37+
vm.expectEmit({emitter: address(a), count: 0});
38+
emit A.Event2();
39+
40+
a.foo();
41+
}
42+
}

0 commit comments

Comments
 (0)