Skip to content

Commit 8a7881f

Browse files
test: Added ICheatCodes for testing
1 parent 8026bb5 commit 8a7881f

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed

contracts/test/ICheatCodes.sol

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.0;
3+
4+
interface ICheatCodes {
5+
// Set block.timestamp (newTimestamp)
6+
function warp(uint256) external;
7+
8+
// Set block.height (newHeight)
9+
function roll(uint256) external;
10+
11+
// Set block.basefee (newBasefee)
12+
function fee(uint256) external;
13+
14+
// Loads a storage slot from an address (who, slot)
15+
function load(address, bytes32) external returns (bytes32);
16+
17+
// Stores a value to an address' storage slot, (who, slot, value)
18+
function store(
19+
address,
20+
bytes32,
21+
bytes32
22+
) external;
23+
24+
// Signs data, (privateKey, digest) => (v, r, s)
25+
function sign(uint256, bytes32)
26+
external
27+
returns (
28+
uint8,
29+
bytes32,
30+
bytes32
31+
);
32+
33+
// Gets address for a given private key, (privateKey) => (address)
34+
function addr(uint256) external returns (address);
35+
36+
// Performs a foreign function call via terminal, (stringInputs) => (result)
37+
function ffi(string[] calldata) external returns (bytes memory);
38+
39+
// Sets the *next* call's msg.sender to be the input address
40+
function prank(address) external;
41+
42+
// Sets all subsequent calls' msg.sender to be the input address until `stopPrank` is called
43+
function startPrank(address) external;
44+
45+
// Sets the *next* call's msg.sender to be the input address, and the tx.origin to be the second input
46+
function prank(address, address) external;
47+
48+
// Sets all subsequent calls' msg.sender to be the input address until `stopPrank` is called, and the tx.origin to be the second input
49+
function startPrank(address, address) external;
50+
51+
// Resets subsequent calls' msg.sender to be `address(this)`
52+
function stopPrank() external;
53+
54+
// Sets an address' balance, (who, newBalance)
55+
function deal(address, uint256) external;
56+
57+
// Sets an address' code, (who, newCode)
58+
function etch(address, bytes calldata) external;
59+
60+
// Expects an error on next call
61+
function expectRevert(bytes calldata) external;
62+
63+
function expectRevert(bytes4) external;
64+
65+
// Record all storage reads and writes
66+
function record() external;
67+
68+
// Gets all accessed reads and write slot from a recording session, for a given address
69+
function accesses(address)
70+
external
71+
returns (bytes32[] memory reads, bytes32[] memory writes);
72+
73+
// Prepare an expected log with (bool checkTopic1, bool checkTopic2, bool checkTopic3, bool checkData).
74+
// Call this function, then emit an event, then call a function. Internally after the call, we check if
75+
// logs were emitted in the expected order with the expected topics and data (as specified by the booleans)
76+
function expectEmit(
77+
bool,
78+
bool,
79+
bool,
80+
bool
81+
) external;
82+
83+
// Mocks a call to an address, returning specified data.
84+
// Calldata can either be strict or a partial match, e.g. if you only
85+
// pass a Solidity selector to the expected calldata, then the entire Solidity
86+
// function will be mocked.
87+
function mockCall(
88+
address,
89+
bytes calldata,
90+
bytes calldata
91+
) external;
92+
93+
// Clears all mocked calls
94+
function clearMockedCalls() external;
95+
96+
// Expect a call to an address with the specified calldata.
97+
// Calldata can either be strict or a partial match
98+
function expectCall(address, bytes calldata) external;
99+
100+
// Fetches the contract bytecode from its artifact file
101+
function getCode(string calldata) external returns (bytes memory);
102+
}

0 commit comments

Comments
 (0)