Skip to content

Detect use of block.timestamp and block.number in Solidity tests #717

@PaulRBerg

Description

@PaulRBerg

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 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

foundry-rs/foundry#11598 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions