diff --git a/crates/cheatcodes/src/inspector.rs b/crates/cheatcodes/src/inspector.rs index 42be1688c..e5a6a2ee8 100644 --- a/crates/cheatcodes/src/inspector.rs +++ b/crates/cheatcodes/src/inspector.rs @@ -1738,13 +1738,20 @@ impl Inspector for Cheatcodes { &mut data.journaled_state, ccx, ) { - self.combined_logs.extend(result.logs.into_iter().map(|log| { + self.combined_logs.extend(result.logs.clone().into_iter().map(|log| { Some(Log { address: log.address, data: LogData::new_unchecked(log.topics, log.data), }) })); + // for each log in cloned logs call handle_expect_emit + if !self.expected_emits.is_empty() { + for log in result.logs { + expect::handle_expect_emit(self, &log.address, &log.topics, &log.data); + } + } + return match result.execution_result { ExecutionResult::Success { output, .. } => match output { Output::Create(bytes, address) => { diff --git a/zk-tests/src/Cheatcodes.t.sol b/zk-tests/src/Cheatcodes.t.sol index 0763d106a..e7f586d13 100644 --- a/zk-tests/src/Cheatcodes.t.sol +++ b/zk-tests/src/Cheatcodes.t.sol @@ -36,6 +36,7 @@ interface IMyProxyCaller { contract MyProxyCaller { address inner; + constructor(address _inner) { inner = _inner; } @@ -45,7 +46,22 @@ contract MyProxyCaller { } } +contract Emitter { + event EventConstructor(string message); + event EventFunction(string message); + + constructor() { + emit EventConstructor("constructor"); + } + + function functionEmit() public { + emit EventFunction("function"); + } +} + contract ZkCheatcodesTest is Test { + event EventConstructor(string message); + event EventFunction(string message); uint256 testSlot = 0; //0x000000000000000000000000000000000000000000000000000000000000001e slot uint256 constant ERA_FORK_BLOCK = 19579636; uint256 constant ERA_FORK_BLOCK_TS = 1700601590; @@ -143,6 +159,19 @@ contract ZkCheatcodesTest is Test { assertEq(writes[0], keySlot0); } + function testExpectEmit() public { + vm.expectEmit(true, true, true, true); + emit EventFunction("function"); + Emitter emitter = new Emitter(); + emitter.functionEmit(); + } + + function testExpectEmitOnCreate() public { + vm.expectEmit(true, true, true, true); + emit EventConstructor("constructor"); + new Emitter(); + } + function testZkCheatcodesValueFunctionMockReturn() public { InnerMock inner = new InnerMock(); // Send some funds to so it can pay for the inner call