ITADN

Detect use of `block.timestamp` and `block.number` in Solidity tests

#717OpenPaulRBerg 创建于 2025-09-10
P
PaulRBergcommented
## Problem `block.timestamp` is assumed to be constant when `--ir-minimum` (via IR) is enabled, and this leads to false negative failed tests when running Solidity tests that use the [`vm.warp` cheat](https://getfoundry.sh/reference/cheatcodes/warp) in Foundry. This can easily create hard-to-debug circumstances - tests that normally pass start failing, and debugging via IR-enabled code is not easy. ## Solution Detect the use of `block.timestamp` in the users' tests, and throw a bespoke warning about it. Recommend using `vm.getBlockTimestamp()` instead. Ditto for `block.number` and `vm.roll` and `vm.getBlockNumber()`. > [!NOTE] > The rule should be turned off by default so that users can turn it on in their `test/.solhint.json` file. ## Related https://github.com/foundry-rs/foundry/issues/11598#issuecomment-3273758558
4 条评论