diff --git a/crates/cheatcodes/assets/cheatcodes.json b/crates/cheatcodes/assets/cheatcodes.json index 5d46978a4fdb9..7024fedc3d428 100644 --- a/crates/cheatcodes/assets/cheatcodes.json +++ b/crates/cheatcodes/assets/cheatcodes.json @@ -754,9 +754,9 @@ "func": { "id": "accesses", "description": "Gets all accessed reads and write slot from a `vm.record` session, for a given address.", - "declaration": "function accesses(address target) external returns (bytes32[] memory readSlots, bytes32[] memory writeSlots);", + "declaration": "function accesses(address target) external view returns (bytes32[] memory readSlots, bytes32[] memory writeSlots);", "visibility": "external", - "mutability": "", + "mutability": "view", "signature": "accesses(address)", "selector": "0x65bc9481", "selectorBytes": [ @@ -3594,9 +3594,9 @@ "func": { "id": "contains", "description": "Returns true if `search` is found in `subject`, false otherwise.", - "declaration": "function contains(string calldata subject, string calldata search) external returns (bool result);", + "declaration": "function contains(string calldata subject, string calldata search) external pure returns (bool result);", "visibility": "external", - "mutability": "", + "mutability": "pure", "signature": "contains(string,string)", "selector": "0x3fb18aec", "selectorBytes": [ @@ -4898,9 +4898,9 @@ "func": { "id": "eth_getLogs", "description": "Gets all the logs according to specified filter.", - "declaration": "function eth_getLogs(uint256 fromBlock, uint256 toBlock, address target, bytes32[] calldata topics) external returns (EthGetLogs[] memory logs);", + "declaration": "function eth_getLogs(uint256 fromBlock, uint256 toBlock, address target, bytes32[] calldata topics) external view returns (EthGetLogs[] memory logs);", "visibility": "external", - "mutability": "", + "mutability": "view", "signature": "eth_getLogs(uint256,uint256,address,bytes32[])", "selector": "0x35e1349b", "selectorBytes": [ @@ -6158,9 +6158,9 @@ "func": { "id": "getMappingKeyAndParentOf", "description": "Gets the map key and parent of a mapping at a given slot, for a given address.", - "declaration": "function getMappingKeyAndParentOf(address target, bytes32 elementSlot) external returns (bool found, bytes32 key, bytes32 parent);", + "declaration": "function getMappingKeyAndParentOf(address target, bytes32 elementSlot) external view returns (bool found, bytes32 key, bytes32 parent);", "visibility": "external", - "mutability": "", + "mutability": "view", "signature": "getMappingKeyAndParentOf(address,bytes32)", "selector": "0x876e24e6", "selectorBytes": [ @@ -6178,9 +6178,9 @@ "func": { "id": "getMappingLength", "description": "Gets the number of elements in the mapping at the given slot, for a given address.", - "declaration": "function getMappingLength(address target, bytes32 mappingSlot) external returns (uint256 length);", + "declaration": "function getMappingLength(address target, bytes32 mappingSlot) external view returns (uint256 length);", "visibility": "external", - "mutability": "", + "mutability": "view", "signature": "getMappingLength(address,bytes32)", "selector": "0x2f2fd63f", "selectorBytes": [ @@ -6198,9 +6198,9 @@ "func": { "id": "getMappingSlotAt", "description": "Gets the elements at index idx of the mapping at the given slot, for a given address. The\nindex must be less than the length of the mapping (i.e. the number of keys in the mapping).", - "declaration": "function getMappingSlotAt(address target, bytes32 mappingSlot, uint256 idx) external returns (bytes32 value);", + "declaration": "function getMappingSlotAt(address target, bytes32 mappingSlot, uint256 idx) external view returns (bytes32 value);", "visibility": "external", - "mutability": "", + "mutability": "view", "signature": "getMappingSlotAt(address,bytes32,uint256)", "selector": "0xebc73ab4", "selectorBytes": [ @@ -6238,9 +6238,9 @@ "func": { "id": "getNonce_1", "description": "Get the nonce of a `Wallet`.", - "declaration": "function getNonce(Wallet calldata wallet) external returns (uint64 nonce);", + "declaration": "function getNonce(Wallet calldata wallet) external view returns (uint64 nonce);", "visibility": "external", - "mutability": "", + "mutability": "view", "signature": "getNonce((address,uint256,uint256,uint256))", "selector": "0xa5748aad", "selectorBytes": [ @@ -6258,9 +6258,9 @@ "func": { "id": "getRecordedLogs", "description": "Gets all the recorded logs.", - "declaration": "function getRecordedLogs() external returns (Log[] memory logs);", + "declaration": "function getRecordedLogs() external view returns (Log[] memory logs);", "visibility": "external", - "mutability": "", + "mutability": "view", "signature": "getRecordedLogs()", "selector": "0x191553a4", "selectorBytes": [ @@ -6318,9 +6318,9 @@ "func": { "id": "getWallets", "description": "Returns addresses of available unlocked wallets in the script environment.", - "declaration": "function getWallets() external returns (address[] memory wallets);", + "declaration": "function getWallets() external view returns (address[] memory wallets);", "visibility": "external", - "mutability": "", + "mutability": "view", "signature": "getWallets()", "selector": "0xdb7a4605", "selectorBytes": [ @@ -6900,9 +6900,9 @@ "func": { "id": "noAccessList", "description": "Utility cheatcode to remove any EIP-2930 access list set by `accessList` cheatcode.", - "declaration": "function noAccessList() external;", + "declaration": "function noAccessList() external view;", "visibility": "external", - "mutability": "", + "mutability": "view", "signature": "noAccessList()", "selector": "0x238ad778", "selectorBytes": [ @@ -8340,9 +8340,9 @@ "func": { "id": "readCallers", "description": "Reads the current `msg.sender` and `tx.origin` from state and reports if there is any active caller modification.", - "declaration": "function readCallers() external returns (CallerMode callerMode, address msgSender, address txOrigin);", + "declaration": "function readCallers() external view returns (CallerMode callerMode, address msgSender, address txOrigin);", "visibility": "external", - "mutability": "", + "mutability": "view", "signature": "readCallers()", "selector": "0x4ad0bac9", "selectorBytes": [ diff --git a/crates/cheatcodes/spec/src/vm.rs b/crates/cheatcodes/spec/src/vm.rs index afb687894f863..5825e4c9922e0 100644 --- a/crates/cheatcodes/spec/src/vm.rs +++ b/crates/cheatcodes/spec/src/vm.rs @@ -372,7 +372,7 @@ interface Vm { /// Get the nonce of a `Wallet`. #[cheatcode(group = Evm, safety = Safe)] - function getNonce(Wallet calldata wallet) external returns (uint64 nonce); + function getNonce(Wallet calldata wallet) external view returns (uint64 nonce); /// Loads a storage slot from an address. #[cheatcode(group = Evm, safety = Safe)] @@ -410,7 +410,7 @@ interface Vm { /// Gets all accessed reads and write slot from a `vm.record` session, for a given address. #[cheatcode(group = Evm, safety = Safe)] - function accesses(address target) external returns (bytes32[] memory readSlots, bytes32[] memory writeSlots); + function accesses(address target) external view returns (bytes32[] memory readSlots, bytes32[] memory writeSlots); /// Record all account accesses as part of CREATE, CALL or SELFDESTRUCT opcodes in order, /// along with the context of the calls @@ -441,17 +441,18 @@ interface Vm { /// Gets the number of elements in the mapping at the given slot, for a given address. #[cheatcode(group = Evm, safety = Safe)] - function getMappingLength(address target, bytes32 mappingSlot) external returns (uint256 length); + function getMappingLength(address target, bytes32 mappingSlot) external view returns (uint256 length); /// Gets the elements at index idx of the mapping at the given slot, for a given address. The /// index must be less than the length of the mapping (i.e. the number of keys in the mapping). #[cheatcode(group = Evm, safety = Safe)] - function getMappingSlotAt(address target, bytes32 mappingSlot, uint256 idx) external returns (bytes32 value); + function getMappingSlotAt(address target, bytes32 mappingSlot, uint256 idx) external view returns (bytes32 value); /// Gets the map key and parent of a mapping at a given slot, for a given address. #[cheatcode(group = Evm, safety = Safe)] function getMappingKeyAndParentOf(address target, bytes32 elementSlot) external + view returns (bool found, bytes32 key, bytes32 parent); // -------- Block and Transaction Properties -------- @@ -575,7 +576,7 @@ interface Vm { /// Utility cheatcode to remove any EIP-2930 access list set by `accessList` cheatcode. #[cheatcode(group = Evm, safety = Unsafe)] - function noAccessList() external; + function noAccessList() external view; /// Utility cheatcode to mark specific storage slot as warm, simulating a prior read. #[cheatcode(group = Evm, safety = Unsafe)] @@ -699,7 +700,7 @@ interface Vm { /// Reads the current `msg.sender` and `tx.origin` from state and reports if there is any active caller modification. #[cheatcode(group = Evm, safety = Unsafe)] - function readCallers() external returns (CallerMode callerMode, address msgSender, address txOrigin); + function readCallers() external view returns (CallerMode callerMode, address msgSender, address txOrigin); // ----- Arbitrary Snapshots ----- @@ -871,6 +872,7 @@ interface Vm { #[cheatcode(group = Evm, safety = Safe)] function eth_getLogs(uint256 fromBlock, uint256 toBlock, address target, bytes32[] calldata topics) external + view returns (EthGetLogs[] memory logs); // --- Behavior --- @@ -912,7 +914,7 @@ interface Vm { /// Gets all the recorded logs. #[cheatcode(group = Evm, safety = Safe)] - function getRecordedLogs() external returns (Log[] memory logs); + function getRecordedLogs() external view returns (Log[] memory logs); // -------- Gas Metering -------- @@ -2247,7 +2249,7 @@ interface Vm { /// Returns addresses of available unlocked wallets in the script environment. #[cheatcode(group = Scripting)] - function getWallets() external returns (address[] memory wallets); + function getWallets() external view returns (address[] memory wallets); // ======== Utilities ======== @@ -2313,7 +2315,7 @@ interface Vm { function indexOf(string calldata input, string calldata key) external pure returns (uint256); /// Returns true if `search` is found in `subject`, false otherwise. #[cheatcode(group = String)] - function contains(string calldata subject, string calldata search) external returns (bool result); + function contains(string calldata subject, string calldata search) external pure returns (bool result); // ======== JSON Parsing and Manipulation ======== diff --git a/crates/forge/tests/cli/script.rs b/crates/forge/tests/cli/script.rs index 1b1180e793015..879dacc59eed5 100644 --- a/crates/forge/tests/cli/script.rs +++ b/crates/forge/tests/cli/script.rs @@ -2259,7 +2259,7 @@ forgetest_init!(can_get_script_wallets, |prj, cmd| { import "forge-std/Script.sol"; interface Vm { - function getWallets() external returns (address[] memory wallets); + function getWallets() external view returns (address[] memory wallets); } contract WalletScript is Script { @@ -2575,7 +2575,7 @@ Chain 31337 accessList [] chainId 31337 -gasLimit 228231 +gasLimit 228247 gasPrice input [..] maxFeePerBlobGas diff --git a/testdata/cheats/Vm.sol b/testdata/cheats/Vm.sol index c043d29489763..ad9a6da16079f 100644 --- a/testdata/cheats/Vm.sol +++ b/testdata/cheats/Vm.sol @@ -31,7 +31,7 @@ interface Vm { function _expectCheatcodeRevert(bytes4 revertData) external; function _expectCheatcodeRevert(bytes calldata revertData) external; function accessList(AccessListItem[] calldata access) external; - function accesses(address target) external returns (bytes32[] memory readSlots, bytes32[] memory writeSlots); + function accesses(address target) external view returns (bytes32[] memory readSlots, bytes32[] memory writeSlots); function activeFork() external view returns (uint256 forkId); function addr(uint256 privateKey) external pure returns (address keyAddr); function allowCheatcodes(address account) external; @@ -173,7 +173,7 @@ interface Vm { function computeCreate2Address(bytes32 salt, bytes32 initCodeHash, address deployer) external pure returns (address); function computeCreate2Address(bytes32 salt, bytes32 initCodeHash) external pure returns (address); function computeCreateAddress(address deployer, uint256 nonce) external pure returns (address); - function contains(string calldata subject, string calldata search) external returns (bool result); + function contains(string calldata subject, string calldata search) external pure returns (bool result); function cool(address target) external; function coolSlot(address target, bytes32 slot) external; function copyFile(string calldata from, string calldata to) external returns (uint64 copied); @@ -238,7 +238,7 @@ interface Vm { function envUint(string calldata name) external view returns (uint256 value); function envUint(string calldata name, string calldata delim) external view returns (uint256[] memory value); function etch(address target, bytes calldata newRuntimeBytecode) external; - function eth_getLogs(uint256 fromBlock, uint256 toBlock, address target, bytes32[] calldata topics) external returns (EthGetLogs[] memory logs); + function eth_getLogs(uint256 fromBlock, uint256 toBlock, address target, bytes32[] calldata topics) external view returns (EthGetLogs[] memory logs); function exists(string calldata path) external view returns (bool result); function expectCallMinGas(address callee, uint256 msgValue, uint64 minGas, bytes calldata data) external; function expectCallMinGas(address callee, uint256 msgValue, uint64 minGas, bytes calldata data, uint64 count) external; @@ -301,15 +301,15 @@ interface Vm { function getDeployments(string calldata contractName, uint64 chainId) external view returns (address[] memory deployedAddresses); function getFoundryVersion() external view returns (string memory version); function getLabel(address account) external view returns (string memory currentLabel); - function getMappingKeyAndParentOf(address target, bytes32 elementSlot) external returns (bool found, bytes32 key, bytes32 parent); - function getMappingLength(address target, bytes32 mappingSlot) external returns (uint256 length); - function getMappingSlotAt(address target, bytes32 mappingSlot, uint256 idx) external returns (bytes32 value); + function getMappingKeyAndParentOf(address target, bytes32 elementSlot) external view returns (bool found, bytes32 key, bytes32 parent); + function getMappingLength(address target, bytes32 mappingSlot) external view returns (uint256 length); + function getMappingSlotAt(address target, bytes32 mappingSlot, uint256 idx) external view returns (bytes32 value); function getNonce(address account) external view returns (uint64 nonce); - function getNonce(Wallet calldata wallet) external returns (uint64 nonce); - function getRecordedLogs() external returns (Log[] memory logs); + function getNonce(Wallet calldata wallet) external view returns (uint64 nonce); + function getRecordedLogs() external view returns (Log[] memory logs); function getStateDiff() external view returns (string memory diff); function getStateDiffJson() external view returns (string memory diff); - function getWallets() external returns (address[] memory wallets); + function getWallets() external view returns (address[] memory wallets); function indexOf(string calldata input, string calldata key) external pure returns (uint256); function interceptInitcode() external; function isContext(ForgeContext context) external view returns (bool result); @@ -338,7 +338,7 @@ interface Vm { function mockCalls(address callee, bytes calldata data, bytes[] calldata returnData) external; function mockCalls(address callee, uint256 msgValue, bytes calldata data, bytes[] calldata returnData) external; function mockFunction(address callee, address target, bytes calldata data) external; - function noAccessList() external; + function noAccessList() external view; function parseAddress(string calldata stringifiedValue) external pure returns (address parsedValue); function parseBool(string calldata stringifiedValue) external pure returns (bool parsedValue); function parseBytes(string calldata stringifiedValue) external pure returns (bytes memory parsedValue); @@ -410,7 +410,7 @@ interface Vm { function randomUint() external returns (uint256); function randomUint(uint256 min, uint256 max) external returns (uint256); function randomUint(uint256 bits) external view returns (uint256); - function readCallers() external returns (CallerMode callerMode, address msgSender, address txOrigin); + function readCallers() external view returns (CallerMode callerMode, address msgSender, address txOrigin); function readDir(string calldata path) external view returns (DirEntry[] memory entries); function readDir(string calldata path, uint64 maxDepth) external view returns (DirEntry[] memory entries); function readDir(string calldata path, uint64 maxDepth, bool followLinks) external view returns (DirEntry[] memory entries);