From 051fb65fc46013dff64e46ca410445d63ea5620a Mon Sep 17 00:00:00 2001 From: "A.L." Date: Thu, 5 Dec 2024 02:15:24 +0800 Subject: [PATCH 1/2] fix: use `vm.getBlockTimestamp` for `skip` and `rewind` (#634) Given that during `via-ir` compilations, the `block.timestamp` variable might be distorted due to optimizations, the more correct way to obtain the block timestamp. See [this discussion](https://github.com/foundry-rs/foundry/issues/1373#issuecomment-2485290776) --- src/StdCheats.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/StdCheats.sol b/src/StdCheats.sol index 95850d118..051ef71be 100644 --- a/src/StdCheats.sol +++ b/src/StdCheats.sol @@ -645,11 +645,11 @@ abstract contract StdCheats is StdCheatsSafe { // Skip forward or rewind time by the specified number of seconds function skip(uint256 time) internal virtual { - vm.warp(block.timestamp + time); + vm.warp(vm.getBlockTimestamp() + time); } function rewind(uint256 time) internal virtual { - vm.warp(block.timestamp - time); + vm.warp(vm.getBlockTimestamp() - time); } // Setup a prank from an address that has some ether From d3db4ef90a72b7d24aa5a2e5c649593eaef7801d Mon Sep 17 00:00:00 2001 From: Yash Atreya <44857776+yash-atreya@users.noreply.github.com> Date: Fri, 6 Dec 2024 13:10:59 +0530 Subject: [PATCH 2/2] feat: `count` assertion for `expectRevert` (#638) Ref: https://github.com/foundry-rs/foundry/pull/9484 ```solidity /// Expects `count` number of reverts from the upcoming calls with any revert data or reverter. function expectRevert(uint64 count) external; /// Expects `count` number of reverts from the upcoming calls that match the revert data. function expectRevert(bytes4 revertData, uint64 count) external; /// Expects `count` number of reverts from the upcoming calls that exactly match the revert data. function expectRevert(bytes calldata revertData, uint64 count) external; /// Expects `count` number of reverts from the upcoming calls from the reverter address. function expectRevert(address reverter, uint64 count) external; /// Expects `count` number of reverts from the upcoming calls from the reverter address that match the revert data. function expectRevert(bytes4 revertData, address reverter, uint64 count) external; /// Expects `count` number of reverts from the upcoming calls from the reverter address that exactly match the revert data. function expectRevert(bytes calldata revertData, address reverter, uint64 count) external; ``` --- src/Vm.sol | 18 ++++++++++++++++++ test/Vm.t.sol | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Vm.sol b/src/Vm.sol index 92163691b..ce3f3564e 100644 --- a/src/Vm.sol +++ b/src/Vm.sol @@ -2182,6 +2182,24 @@ interface Vm is VmSafe { /// Expects an error from reverter address on next call, that exactly matches the revert data. function expectRevert(bytes calldata revertData, address reverter) external; + /// Expects `count` number of reverts from the upcoming calls with any revert data or reverter. + function expectRevert(uint64 count) external; + + /// Expects `count` number of reverts from the upcoming calls that match the revert data. + function expectRevert(bytes4 revertData, uint64 count) external; + + /// Expects `count` number of reverts from the upcoming calls that exactly match the revert data. + function expectRevert(bytes calldata revertData, uint64 count) external; + + /// Expects `count` number of reverts from the upcoming calls from the reverter address. + function expectRevert(address reverter, uint64 count) external; + + /// Expects `count` number of reverts from the upcoming calls from the reverter address that match the revert data. + function expectRevert(bytes4 revertData, address reverter, uint64 count) external; + + /// Expects `count` number of reverts from the upcoming calls from the reverter address that exactly match the revert data. + function expectRevert(bytes calldata revertData, address reverter, uint64 count) external; + /// Only allows memory writes to offsets [0x00, 0x60) ∪ [min, max) in the current subcontext. If any other /// memory is written to, the test will fail. Can be called multiple times to add more ranges to the set. function expectSafeMemory(uint64 min, uint64 max) external; diff --git a/test/Vm.t.sol b/test/Vm.t.sol index f1c37bdc8..7958a6d3c 100644 --- a/test/Vm.t.sol +++ b/test/Vm.t.sol @@ -9,7 +9,7 @@ import {Vm, VmSafe} from "../src/Vm.sol"; // added to or removed from Vm or VmSafe. contract VmTest is Test { function test_VmInterfaceId() public pure { - assertEq(type(Vm).interfaceId, bytes4(0x21af9696), "Vm"); + assertEq(type(Vm).interfaceId, bytes4(0xbe425eb2), "Vm"); } function test_VmSafeInterfaceId() public pure {