Skip to content

Add support for most random cheatcodes#877

Merged
rv-jenkins merged 23 commits intomasterfrom
add-random-cheatcodes
Nov 20, 2024
Merged

Add support for most random cheatcodes#877
rv-jenkins merged 23 commits intomasterfrom
add-random-cheatcodes

Conversation

@palinatolmach
Copy link
Contributor

@palinatolmach palinatolmach commented Nov 7, 2024

This PR partially addresses #876.

This PR adds support for the following cheatcodes recently added to forge-std, and adds end-to-end tests for them:

    /// Returns a random `address`.
    function randomAddress() external returns (address);

    /// Returns a random `bool`.
    function randomBool() external view returns (bool);

    /// Returns a random byte array value of the given length.
    function randomBytes(uint256 len) external view returns (bytes memory);

    /// Returns a random fixed-size byte array of length 4.
    function randomBytes4() external view returns (bytes4);

    /// Returns a random fixed-size byte array of length 8.
    function randomBytes8() external view returns (bytes8);

    /// Returns a random uint256 value.
    function randomUint() external returns (uint256);

    /// Returns a random `uint256` value of given bits.
    function randomUint(uint256 bits) external view returns (uint256);

    /// Returns random uint256 value between the provided range (=min..=max).
    function randomUint(uint256 min, uint256 max) external returns (uint256);

The following cheatcodes will be added in a follow up PR; they're currently causing branching due to some signed ints specifics:

    /// Returns a random `int256` value.
    function randomInt() external view returns (int256);

    /// Returns a random `int256` value of given bits.
    function randomInt(uint256 bits) external view returns (int256);

@palinatolmach palinatolmach self-assigned this Nov 7, 2024
@palinatolmach palinatolmach changed the title Add support for random cheatcodes Add support for most random cheatcodes Nov 18, 2024
@palinatolmach palinatolmach marked this pull request as ready for review November 18, 2024 17:20
palinatolmach and others added 3 commits November 20, 2024 10:21
Co-authored-by: Andrei Văcaru <16517508+anvacaru@users.noreply.github.com>
Co-authored-by: Andrei Văcaru <16517508+anvacaru@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants