getBlockTimestamp
Signature
Section titled “Signature”function getBlockTimestamp() external view returns (uint256 timestamp);Description
Section titled “Description”Gets the current block.timestamp. This is useful in cases where vm.warp along with --via-ir compilation is used, as block.timestamp is assumed to be a constant during a transaction. This means that in every test, multiple calls to block.timestamp would get optimized to just returning a constant value, instead of actually accessing the current block.timestamp. vm.getBlockTimestamp() avoids this optimization and returns the current block.timestamp.
Examples
Section titled “Examples”assertEq(vm.getBlockTimestamp(), 1, "timestamp should be 1");vm.warp(10);assertEq(vm.getBlockTimestamp(), 10, "warp failed");