function getBlockTimestamp() external view returns (uint256 timestamp);
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 on every forge 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
.
assertEq(vm.getBlockTimestamp(), 1, "timestamp should be 1");
vm.warp(10);
assertEq(vm.getBlockTimestamp(), 10, "warp failed");