Skip to content

Latest commit

 

History

History
37 lines (28 loc) · 982 Bytes

File metadata and controls

37 lines (28 loc) · 982 Bytes

prank

Description

The prank cheatcode will set the msg.sender for only the next call to the specified input address. Note that, contrary to prank in Foundry, calling the cheatcode contract will count as a valid "next call"

Example

contract TestContract {
    address owner = address(123);
    function transferOwnership(address _newOwner) public {
        require(msg.sender == owner);

        // Change ownership
        owner = _newOwner;
    }

    function test() public {
        // Obtain our cheat code contract reference.
        IStdCheats cheats = IStdCheats(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);

        // Prank, change ownership, and verify
        address newOwner = address(456);
        cheats.prank(owner);
        transferOwnership(newOwner);
        assert(owner == newOwner);
    }

Function Signature

function prank(address) external;