From 4695fac44b2934aaa6d7150e2eaf0256fdc566a7 Mon Sep 17 00:00:00 2001 From: grandizzy <38490174+grandizzy@users.noreply.github.com> Date: Thu, 29 Aug 2024 18:43:19 +0300 Subject: [PATCH] feat: add resetGasMetering and expectPartialRevert cheatcodes (#597) * Add resetGasMetering cheatcode * Add expectPartialRevert cheatcode --- src/Vm.sol | 8 +++++++- test/Vm.t.sol | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Vm.sol b/src/Vm.sol index 362bd739..ec495aaa 100644 --- a/src/Vm.sol +++ b/src/Vm.sol @@ -559,6 +559,9 @@ interface VmSafe { /// Record all the transaction logs. function recordLogs() external; + /// Reset gas metering (i.e. gas usage is set to gas limit). + function resetGasMetering() external; + /// Resumes gas metering (i.e. gas usage is counted again). Noop if already on. function resumeGasMetering() external; @@ -1865,10 +1868,13 @@ interface Vm is VmSafe { /// Same as the previous method, but also checks supplied address against emitting contract. function expectEmit(address emitter) external; + /// Expects an error on next call that starts with the revert data. + function expectPartialRevert(bytes4 revertData) external; + /// Expects an error on next call with any revert data. function expectRevert() external; - /// Expects an error on next call that starts with the revert data. + /// Expects an error on next call that exactly matches the revert data. function expectRevert(bytes4 revertData) external; /// Expects an error on next call that exactly matches the revert data. diff --git a/test/Vm.t.sol b/test/Vm.t.sol index 04786372..91cfcebf 100644 --- a/test/Vm.t.sol +++ b/test/Vm.t.sol @@ -9,7 +9,7 @@ contract VmTest is Test { // inadvertently moved between Vm and VmSafe. This test must be updated each time a function is // added to or removed from Vm or VmSafe. function test_interfaceId() public pure { - assertEq(type(VmSafe).interfaceId, bytes4(0x23e7dc1b), "VmSafe"); - assertEq(type(Vm).interfaceId, bytes4(0x1316b43e), "Vm"); + assertEq(type(VmSafe).interfaceId, bytes4(0x9dd1a1c8), "VmSafe"); + assertEq(type(Vm).interfaceId, bytes4(0x02edefa2), "Vm"); } }