getBlockNumber

Signature

function getBlockNumber() external view returns (uint256 timestamp);

Description

Gets the current block.number. This is useful in cases where vm.roll along with --via-ir compilation is used, as block.number is assumed to be a constant during a transaction. This means that on every forge test, multiple calls to block.number would get optimized to just returning a constant value, instead of actually accessing the current block.number. vm.getBlockNumber() avoids this optimization and returns the current block.number.

Examples

uint256 height = vm.getBlockNumber(); assertEq(height, uint256(block.number)); vm.roll(10); assertEq(vm.getBlockNumber(), 10);