From cd2c8cf1f3735d2888784bad3273aac833ded68f Mon Sep 17 00:00:00 2001 From: Paul Razvan Berg Date: Fri, 3 Mar 2023 13:41:08 +0200 Subject: [PATCH 1/2] feat: add simple "expectEmit" --- src/StdCheats.sol | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/StdCheats.sol b/src/StdCheats.sol index 126d831c9..4ecfd60f3 100644 --- a/src/StdCheats.sol +++ b/src/StdCheats.sol @@ -479,6 +479,11 @@ abstract contract StdCheats is StdCheatsSafe { StdStorage private stdstore; Vm private constant vm = Vm(address(uint160(uint256(keccak256("hevm cheat code"))))); + // Expects an event to be emitted by checking all three topics and the data. + function expectEmit() internal { + vm.expectEmit({ checkTopic1: true, checkTopic2: true, checkTopic3: true, checkData: true }); + } + // Skip forward or rewind time by the specified number of seconds function skip(uint256 time) internal virtual { vm.warp(block.timestamp + time); From f9cdad242423eb04aafd1526087074287aad73b1 Mon Sep 17 00:00:00 2001 From: Matt Solomon Date: Sun, 5 Mar 2023 09:21:55 -0700 Subject: [PATCH 2/2] style: forge fmt --- src/StdCheats.sol | 5 ----- src/Vm.sol | 12 +++++++++++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/StdCheats.sol b/src/StdCheats.sol index 4ecfd60f3..126d831c9 100644 --- a/src/StdCheats.sol +++ b/src/StdCheats.sol @@ -479,11 +479,6 @@ abstract contract StdCheats is StdCheatsSafe { StdStorage private stdstore; Vm private constant vm = Vm(address(uint160(uint256(keccak256("hevm cheat code"))))); - // Expects an event to be emitted by checking all three topics and the data. - function expectEmit() internal { - vm.expectEmit({ checkTopic1: true, checkTopic2: true, checkTopic3: true, checkData: true }); - } - // Skip forward or rewind time by the specified number of seconds function skip(uint256 time) internal virtual { vm.warp(block.timestamp + time); diff --git a/src/Vm.sol b/src/Vm.sol index 99d54e07d..1ce49f1b8 100644 --- a/src/Vm.sol +++ b/src/Vm.sol @@ -326,12 +326,22 @@ interface Vm is VmSafe { function expectRevert(bytes calldata revertData) external; function expectRevert(bytes4 revertData) external; function expectRevert() external; + + // Prepare an expected log with all four checks enabled. + // Call this function, then emit an event, then call a function. Internally after the call, we check if + // logs were emitted in the expected order with the expected topics and data. + // Second form also checks supplied address against emitting contract. + function expectEmit() external; + function expectEmit(address) external; + // Prepare an expected log with (bool checkTopic1, bool checkTopic2, bool checkTopic3, bool checkData). // Call this function, then emit an event, then call a function. Internally after the call, we check if - // logs were emitted in the expected order with the expected topics and data (as specified by the booleans) + // logs were emitted in the expected order with the expected topics and data (as specified by the booleans). + // Second form also checks supplied address against emitting contract. function expectEmit(bool checkTopic1, bool checkTopic2, bool checkTopic3, bool checkData) external; function expectEmit(bool checkTopic1, bool checkTopic2, bool checkTopic3, bool checkData, address emitter) external; + // Mocks a call to an address, returning specified data. // Calldata can either be strict or a partial match, e.g. if you only // pass a Solidity selector to the expected calldata, then the entire Solidity