diff --git a/testdata/cheats/Vm.sol b/testdata/cheats/Vm.sol index 2efb15366..6ce385a91 100644 --- a/testdata/cheats/Vm.sol +++ b/testdata/cheats/Vm.sol @@ -6,20 +6,130 @@ pragma solidity >=0.6.2 <0.9.0; pragma experimental ABIEncoderV2; interface Vm { - enum CallerMode { None, Broadcast, RecurrentBroadcast, Prank, RecurrentPrank } - enum AccountAccessKind { Call, DelegateCall, CallCode, StaticCall, Create, SelfDestruct, Resume, Balance, Extcodesize, Extcodehash, Extcodecopy } - enum ForgeContext { TestGroup, Test, Coverage, Snapshot, ScriptGroup, ScriptDryRun, ScriptBroadcast, ScriptResume, Unknown } - struct Log { bytes32[] topics; bytes data; address emitter; } - struct Rpc { string key; string url; } - struct EthGetLogs { address emitter; bytes32[] topics; bytes data; bytes32 blockHash; uint64 blockNumber; bytes32 transactionHash; uint64 transactionIndex; uint256 logIndex; bool removed; } - struct DirEntry { string errorMessage; string path; uint64 depth; bool isDir; bool isSymlink; } - struct FsMetadata { bool isDir; bool isSymlink; uint256 length; bool readOnly; uint256 modified; uint256 accessed; uint256 created; } - struct Wallet { address addr; uint256 publicKeyX; uint256 publicKeyY; uint256 privateKey; } - struct FfiResult { int32 exitCode; bytes stdout; bytes stderr; } - struct ChainInfo { uint256 forkId; uint256 chainId; } - struct AccountAccess { ChainInfo chainInfo; AccountAccessKind kind; address account; address accessor; bool initialized; uint256 oldBalance; uint256 newBalance; bytes deployedCode; uint256 value; bytes data; bool reverted; StorageAccess[] storageAccesses; uint64 depth; } - struct StorageAccess { address account; bytes32 slot; bool isWrite; bytes32 previousValue; bytes32 newValue; bool reverted; } - struct Gas { uint64 gasLimit; uint64 gasTotalUsed; uint64 gasMemoryUsed; int64 gasRefunded; uint64 gasRemaining; } + enum CallerMode { + None, + Broadcast, + RecurrentBroadcast, + Prank, + RecurrentPrank + } + enum AccountAccessKind { + Call, + DelegateCall, + CallCode, + StaticCall, + Create, + SelfDestruct, + Resume, + Balance, + Extcodesize, + Extcodehash, + Extcodecopy + } + enum ForgeContext { + TestGroup, + Test, + Coverage, + Snapshot, + ScriptGroup, + ScriptDryRun, + ScriptBroadcast, + ScriptResume, + Unknown + } + + struct Log { + bytes32[] topics; + bytes data; + address emitter; + } + + struct Rpc { + string key; + string url; + } + + struct EthGetLogs { + address emitter; + bytes32[] topics; + bytes data; + bytes32 blockHash; + uint64 blockNumber; + bytes32 transactionHash; + uint64 transactionIndex; + uint256 logIndex; + bool removed; + } + + struct DirEntry { + string errorMessage; + string path; + uint64 depth; + bool isDir; + bool isSymlink; + } + + struct FsMetadata { + bool isDir; + bool isSymlink; + uint256 length; + bool readOnly; + uint256 modified; + uint256 accessed; + uint256 created; + } + + struct Wallet { + address addr; + uint256 publicKeyX; + uint256 publicKeyY; + uint256 privateKey; + } + + struct FfiResult { + int32 exitCode; + bytes stdout; + bytes stderr; + } + + struct ChainInfo { + uint256 forkId; + uint256 chainId; + } + + struct AccountAccess { + ChainInfo chainInfo; + AccountAccessKind kind; + address account; + address accessor; + bool initialized; + uint256 oldBalance; + uint256 newBalance; + bytes deployedCode; + uint256 value; + bytes data; + bool reverted; + StorageAccess[] storageAccesses; + uint64 depth; + } + + struct StorageAccess { + address account; + bytes32 slot; + bool isWrite; + bytes32 previousValue; + bytes32 newValue; + bool reverted; + } + + struct Gas { + uint64 gasLimit; + uint64 gasTotalUsed; + uint64 gasMemoryUsed; + int64 gasRefunded; + uint64 gasRemaining; + } + function _expectCheatcodeRevert() external; function _expectCheatcodeRevert(bytes4 revertData) external; function _expectCheatcodeRevert(bytes calldata revertData) external; @@ -28,21 +138,53 @@ interface Vm { function addr(uint256 privateKey) external pure returns (address keyAddr); function allowCheatcodes(address account) external; function assertApproxEqAbsDecimal(uint256 left, uint256 right, uint256 maxDelta, uint256 decimals) external pure; - function assertApproxEqAbsDecimal(uint256 left, uint256 right, uint256 maxDelta, uint256 decimals, string calldata error) external pure; + function assertApproxEqAbsDecimal( + uint256 left, + uint256 right, + uint256 maxDelta, + uint256 decimals, + string calldata error + ) external pure; function assertApproxEqAbsDecimal(int256 left, int256 right, uint256 maxDelta, uint256 decimals) external pure; - function assertApproxEqAbsDecimal(int256 left, int256 right, uint256 maxDelta, uint256 decimals, string calldata error) external pure; + function assertApproxEqAbsDecimal( + int256 left, + int256 right, + uint256 maxDelta, + uint256 decimals, + string calldata error + ) external pure; function assertApproxEqAbs(uint256 left, uint256 right, uint256 maxDelta) external pure; function assertApproxEqAbs(uint256 left, uint256 right, uint256 maxDelta, string calldata error) external pure; function assertApproxEqAbs(int256 left, int256 right, uint256 maxDelta) external pure; function assertApproxEqAbs(int256 left, int256 right, uint256 maxDelta, string calldata error) external pure; - function assertApproxEqRelDecimal(uint256 left, uint256 right, uint256 maxPercentDelta, uint256 decimals) external pure; - function assertApproxEqRelDecimal(uint256 left, uint256 right, uint256 maxPercentDelta, uint256 decimals, string calldata error) external pure; - function assertApproxEqRelDecimal(int256 left, int256 right, uint256 maxPercentDelta, uint256 decimals) external pure; - function assertApproxEqRelDecimal(int256 left, int256 right, uint256 maxPercentDelta, uint256 decimals, string calldata error) external pure; + function assertApproxEqRelDecimal(uint256 left, uint256 right, uint256 maxPercentDelta, uint256 decimals) + external + pure; + function assertApproxEqRelDecimal( + uint256 left, + uint256 right, + uint256 maxPercentDelta, + uint256 decimals, + string calldata error + ) external pure; + function assertApproxEqRelDecimal(int256 left, int256 right, uint256 maxPercentDelta, uint256 decimals) + external + pure; + function assertApproxEqRelDecimal( + int256 left, + int256 right, + uint256 maxPercentDelta, + uint256 decimals, + string calldata error + ) external pure; function assertApproxEqRel(uint256 left, uint256 right, uint256 maxPercentDelta) external pure; - function assertApproxEqRel(uint256 left, uint256 right, uint256 maxPercentDelta, string calldata error) external pure; + function assertApproxEqRel(uint256 left, uint256 right, uint256 maxPercentDelta, string calldata error) + external + pure; function assertApproxEqRel(int256 left, int256 right, uint256 maxPercentDelta) external pure; - function assertApproxEqRel(int256 left, int256 right, uint256 maxPercentDelta, string calldata error) external pure; + function assertApproxEqRel(int256 left, int256 right, uint256 maxPercentDelta, string calldata error) + external + pure; function assertEqDecimal(uint256 left, uint256 right, uint256 decimals) external pure; function assertEqDecimal(uint256 left, uint256 right, uint256 decimals, string calldata error) external pure; function assertEqDecimal(int256 left, int256 right, uint256 decimals) external pure; @@ -155,7 +297,10 @@ interface Vm { function clearMockedCalls() external; function closeFile(string calldata path) external; function coinbase(address newCoinbase) external; - function computeCreate2Address(bytes32 salt, bytes32 initCodeHash, address deployer) external pure returns (address); + 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 cool(address target) external; @@ -174,11 +319,22 @@ interface Vm { function deleteSnapshot(uint256 snapshotId) external returns (bool success); function deleteSnapshots() external; function deployCode(string calldata artifactPath) external returns (address deployedAddress); - function deployCode(string calldata artifactPath, bytes calldata constructorArgs) external returns (address deployedAddress); + function deployCode(string calldata artifactPath, bytes calldata constructorArgs) + external + returns (address deployedAddress); function deriveKey(string calldata mnemonic, uint32 index) external pure returns (uint256 privateKey); - function deriveKey(string calldata mnemonic, string calldata derivationPath, uint32 index) external pure returns (uint256 privateKey); - function deriveKey(string calldata mnemonic, uint32 index, string calldata language) external pure returns (uint256 privateKey); - function deriveKey(string calldata mnemonic, string calldata derivationPath, uint32 index, string calldata language) external pure returns (uint256 privateKey); + function deriveKey(string calldata mnemonic, string calldata derivationPath, uint32 index) + external + pure + returns (uint256 privateKey); + function deriveKey(string calldata mnemonic, uint32 index, string calldata language) + external + pure + returns (uint256 privateKey); + function deriveKey(string calldata mnemonic, string calldata derivationPath, uint32 index, string calldata language) + external + pure + returns (uint256 privateKey); function difficulty(uint256 newDifficulty) external; function dumpState(string calldata pathToStateJson) external; function ensNamehash(string calldata name) external pure returns (bytes32); @@ -195,39 +351,72 @@ interface Vm { function envInt(string calldata name, string calldata delim) external view returns (int256[] memory value); function envOr(string calldata name, bool defaultValue) external view returns (bool value); function envOr(string calldata name, uint256 defaultValue) external view returns (uint256 value); - function envOr(string calldata name, string calldata delim, address[] calldata defaultValue) external view returns (address[] memory value); - function envOr(string calldata name, string calldata delim, bytes32[] calldata defaultValue) external view returns (bytes32[] memory value); - function envOr(string calldata name, string calldata delim, string[] calldata defaultValue) external view returns (string[] memory value); - function envOr(string calldata name, string calldata delim, bytes[] calldata defaultValue) external view returns (bytes[] memory value); + function envOr(string calldata name, string calldata delim, address[] calldata defaultValue) + external + view + returns (address[] memory value); + function envOr(string calldata name, string calldata delim, bytes32[] calldata defaultValue) + external + view + returns (bytes32[] memory value); + function envOr(string calldata name, string calldata delim, string[] calldata defaultValue) + external + view + returns (string[] memory value); + function envOr(string calldata name, string calldata delim, bytes[] calldata defaultValue) + external + view + returns (bytes[] memory value); function envOr(string calldata name, int256 defaultValue) external view returns (int256 value); function envOr(string calldata name, address defaultValue) external view returns (address value); function envOr(string calldata name, bytes32 defaultValue) external view returns (bytes32 value); function envOr(string calldata name, string calldata defaultValue) external view returns (string memory value); function envOr(string calldata name, bytes calldata defaultValue) external view returns (bytes memory value); - function envOr(string calldata name, string calldata delim, bool[] calldata defaultValue) external view returns (bool[] memory value); - function envOr(string calldata name, string calldata delim, uint256[] calldata defaultValue) external view returns (uint256[] memory value); - function envOr(string calldata name, string calldata delim, int256[] calldata defaultValue) external view returns (int256[] memory value); + function envOr(string calldata name, string calldata delim, bool[] calldata defaultValue) + external + view + returns (bool[] memory value); + function envOr(string calldata name, string calldata delim, uint256[] calldata defaultValue) + external + view + returns (uint256[] memory value); + function envOr(string calldata name, string calldata delim, int256[] calldata defaultValue) + external + view + returns (int256[] memory value); function envString(string calldata name) external view returns (string memory value); function envString(string calldata name, string calldata delim) external view returns (string[] memory value); 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[] memory topics) external returns (EthGetLogs[] memory logs); + function eth_getLogs(uint256 fromBlock, uint256 toBlock, address target, bytes32[] memory topics) + external + returns (EthGetLogs[] memory logs); function exists(string calldata path) external 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; + function expectCallMinGas(address callee, uint256 msgValue, uint64 minGas, bytes calldata data, uint64 count) + external; function expectCall(address callee, bytes calldata data) external; function expectCall(address callee, bytes calldata data, uint64 count) external; function expectCall(address callee, uint256 msgValue, bytes calldata data) external; function expectCall(address callee, uint256 msgValue, bytes calldata data, uint64 count) external; function expectCall(address callee, uint256 msgValue, uint64 gas, bytes calldata data) external; function expectCall(address callee, uint256 msgValue, uint64 gas, bytes calldata data, uint64 count) external; - function expectEmitAnonymous(bool checkTopic0, bool checkTopic1, bool checkTopic2, bool checkTopic3, bool checkData) external; - function expectEmitAnonymous(bool checkTopic0, bool checkTopic1, bool checkTopic2, bool checkTopic3, bool checkData, address emitter) external; + function expectEmitAnonymous(bool checkTopic0, bool checkTopic1, bool checkTopic2, bool checkTopic3, bool checkData) + external; + function expectEmitAnonymous( + bool checkTopic0, + bool checkTopic1, + bool checkTopic2, + bool checkTopic3, + bool checkData, + address emitter + ) external; function expectEmitAnonymous() external; function expectEmitAnonymous(address emitter) external; function expectEmit(bool checkTopic1, bool checkTopic2, bool checkTopic3, bool checkData) external; - function expectEmit(bool checkTopic1, bool checkTopic2, bool checkTopic3, bool checkData, address emitter) external; + function expectEmit(bool checkTopic1, bool checkTopic2, bool checkTopic3, bool checkData, address emitter) + external; function expectEmit() external; function expectEmit(address emitter) external; function expectRevert() external; @@ -245,7 +434,9 @@ interface Vm { function getCode(string calldata artifactPath) external view returns (bytes memory creationBytecode); function getDeployedCode(string calldata artifactPath) external view returns (bytes memory runtimeBytecode); 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 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 getNonce(address account) external view returns (uint64 nonce); @@ -268,7 +459,8 @@ interface Vm { function makePersistent(address account0, address account1, address account2) external; function makePersistent(address[] calldata accounts) external; function mockCallRevert(address callee, bytes calldata data, bytes calldata revertData) external; - function mockCallRevert(address callee, uint256 msgValue, bytes calldata data, bytes calldata revertData) external; + function mockCallRevert(address callee, uint256 msgValue, bytes calldata data, bytes calldata revertData) + external; function mockCall(address callee, bytes calldata data, bytes calldata returnData) external; function mockCall(address callee, uint256 msgValue, bytes calldata data, bytes calldata returnData) external; function parseAddress(string calldata stringifiedValue) external pure returns (address parsedValue); @@ -277,32 +469,53 @@ interface Vm { function parseBytes32(string calldata stringifiedValue) external pure returns (bytes32 parsedValue); function parseInt(string calldata stringifiedValue) external pure returns (int256 parsedValue); function parseJsonAddress(string calldata json, string calldata key) external pure returns (address); - function parseJsonAddressArray(string calldata json, string calldata key) external pure returns (address[] memory); + function parseJsonAddressArray(string calldata json, string calldata key) + external + pure + returns (address[] memory); function parseJsonBool(string calldata json, string calldata key) external pure returns (bool); function parseJsonBoolArray(string calldata json, string calldata key) external pure returns (bool[] memory); function parseJsonBytes(string calldata json, string calldata key) external pure returns (bytes memory); function parseJsonBytes32(string calldata json, string calldata key) external pure returns (bytes32); - function parseJsonBytes32Array(string calldata json, string calldata key) external pure returns (bytes32[] memory); + function parseJsonBytes32Array(string calldata json, string calldata key) + external + pure + returns (bytes32[] memory); function parseJsonBytesArray(string calldata json, string calldata key) external pure returns (bytes[] memory); function parseJsonInt(string calldata json, string calldata key) external pure returns (int256); function parseJsonIntArray(string calldata json, string calldata key) external pure returns (int256[] memory); function parseJsonKeys(string calldata json, string calldata key) external pure returns (string[] memory keys); function parseJsonString(string calldata json, string calldata key) external pure returns (string memory); function parseJsonStringArray(string calldata json, string calldata key) external pure returns (string[] memory); - function parseJsonTypeArray(string calldata json, string calldata key, string calldata typeDescription) external pure returns (bytes memory); - function parseJsonType(string calldata json, string calldata typeDescription) external pure returns (bytes memory); - function parseJsonType(string calldata json, string calldata key, string calldata typeDescription) external pure returns (bytes memory); + function parseJsonTypeArray(string calldata json, string calldata key, string calldata typeDescription) + external + pure + returns (bytes memory); + function parseJsonType(string calldata json, string calldata typeDescription) + external + pure + returns (bytes memory); + function parseJsonType(string calldata json, string calldata key, string calldata typeDescription) + external + pure + returns (bytes memory); function parseJsonUint(string calldata json, string calldata key) external pure returns (uint256); function parseJsonUintArray(string calldata json, string calldata key) external pure returns (uint256[] memory); function parseJson(string calldata json) external pure returns (bytes memory abiEncodedData); function parseJson(string calldata json, string calldata key) external pure returns (bytes memory abiEncodedData); function parseTomlAddress(string calldata toml, string calldata key) external pure returns (address); - function parseTomlAddressArray(string calldata toml, string calldata key) external pure returns (address[] memory); + function parseTomlAddressArray(string calldata toml, string calldata key) + external + pure + returns (address[] memory); function parseTomlBool(string calldata toml, string calldata key) external pure returns (bool); function parseTomlBoolArray(string calldata toml, string calldata key) external pure returns (bool[] memory); function parseTomlBytes(string calldata toml, string calldata key) external pure returns (bytes memory); function parseTomlBytes32(string calldata toml, string calldata key) external pure returns (bytes32); - function parseTomlBytes32Array(string calldata toml, string calldata key) external pure returns (bytes32[] memory); + function parseTomlBytes32Array(string calldata toml, string calldata key) + external + pure + returns (bytes32[] memory); function parseTomlBytesArray(string calldata toml, string calldata key) external pure returns (bytes[] memory); function parseTomlInt(string calldata toml, string calldata key) external pure returns (int256); function parseTomlIntArray(string calldata toml, string calldata key) external pure returns (int256[] memory); @@ -331,7 +544,10 @@ interface Vm { function readCallers() external 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); + function readDir(string calldata path, uint64 maxDepth, bool followLinks) + external + view + returns (DirEntry[] memory entries); function readFile(string calldata path) external view returns (string memory data); function readFileBinary(string calldata path) external view returns (bytes memory data); function readLine(string calldata path) external view returns (string memory line); @@ -341,7 +557,10 @@ interface Vm { function rememberKey(uint256 privateKey) external returns (address keyAddr); function removeDir(string calldata path, bool recursive) external; function removeFile(string calldata path) external; - function replace(string calldata input, string calldata from, string calldata to) external pure returns (string memory output); + function replace(string calldata input, string calldata from, string calldata to) + external + pure + returns (string memory output); function resetNonce(address account) external; function resumeGasMetering() external; function revertTo(uint256 snapshotId) external returns (bool success); @@ -357,26 +576,66 @@ interface Vm { function rpcUrlStructs() external view returns (Rpc[] memory urls); function rpcUrls() external view returns (string[2][] memory urls); function rpc(string calldata method, string calldata params) external returns (bytes memory data); - function rpc(string calldata urlOrAlias, string calldata method, string calldata params) external returns (bytes memory data); + function rpc(string calldata urlOrAlias, string calldata method, string calldata params) + external + returns (bytes memory data); function selectFork(uint256 forkId) external; - function serializeAddress(string calldata objectKey, string calldata valueKey, address value) external returns (string memory json); - function serializeAddress(string calldata objectKey, string calldata valueKey, address[] calldata values) external returns (string memory json); - function serializeBool(string calldata objectKey, string calldata valueKey, bool value) external returns (string memory json); - function serializeBool(string calldata objectKey, string calldata valueKey, bool[] calldata values) external returns (string memory json); - function serializeBytes32(string calldata objectKey, string calldata valueKey, bytes32 value) external returns (string memory json); - function serializeBytes32(string calldata objectKey, string calldata valueKey, bytes32[] calldata values) external returns (string memory json); - function serializeBytes(string calldata objectKey, string calldata valueKey, bytes calldata value) external returns (string memory json); - function serializeBytes(string calldata objectKey, string calldata valueKey, bytes[] calldata values) external returns (string memory json); - function serializeInt(string calldata objectKey, string calldata valueKey, int256 value) external returns (string memory json); - function serializeInt(string calldata objectKey, string calldata valueKey, int256[] calldata values) external returns (string memory json); + function serializeAddress(string calldata objectKey, string calldata valueKey, address value) + external + returns (string memory json); + function serializeAddress(string calldata objectKey, string calldata valueKey, address[] calldata values) + external + returns (string memory json); + function serializeBool(string calldata objectKey, string calldata valueKey, bool value) + external + returns (string memory json); + function serializeBool(string calldata objectKey, string calldata valueKey, bool[] calldata values) + external + returns (string memory json); + function serializeBytes32(string calldata objectKey, string calldata valueKey, bytes32 value) + external + returns (string memory json); + function serializeBytes32(string calldata objectKey, string calldata valueKey, bytes32[] calldata values) + external + returns (string memory json); + function serializeBytes(string calldata objectKey, string calldata valueKey, bytes calldata value) + external + returns (string memory json); + function serializeBytes(string calldata objectKey, string calldata valueKey, bytes[] calldata values) + external + returns (string memory json); + function serializeInt(string calldata objectKey, string calldata valueKey, int256 value) + external + returns (string memory json); + function serializeInt(string calldata objectKey, string calldata valueKey, int256[] calldata values) + external + returns (string memory json); function serializeJson(string calldata objectKey, string calldata value) external returns (string memory json); - function serializeJsonType(string calldata typeDescription, bytes memory value) external pure returns (string memory json); - function serializeJsonType(string calldata objectKey, string calldata valueKey, string calldata typeDescription, bytes memory value) external returns (string memory json); - function serializeString(string calldata objectKey, string calldata valueKey, string calldata value) external returns (string memory json); - function serializeString(string calldata objectKey, string calldata valueKey, string[] calldata values) external returns (string memory json); - function serializeUintToHex(string calldata objectKey, string calldata valueKey, uint256 value) external returns (string memory json); - function serializeUint(string calldata objectKey, string calldata valueKey, uint256 value) external returns (string memory json); - function serializeUint(string calldata objectKey, string calldata valueKey, uint256[] calldata values) external returns (string memory json); + function serializeJsonType(string calldata typeDescription, bytes memory value) + external + pure + returns (string memory json); + function serializeJsonType( + string calldata objectKey, + string calldata valueKey, + string calldata typeDescription, + bytes memory value + ) external returns (string memory json); + function serializeString(string calldata objectKey, string calldata valueKey, string calldata value) + external + returns (string memory json); + function serializeString(string calldata objectKey, string calldata valueKey, string[] calldata values) + external + returns (string memory json); + function serializeUintToHex(string calldata objectKey, string calldata valueKey, uint256 value) + external + returns (string memory json); + function serializeUint(string calldata objectKey, string calldata valueKey, uint256 value) + external + returns (string memory json); + function serializeUint(string calldata objectKey, string calldata valueKey, uint256[] calldata values) + external + returns (string memory json); function setBlockhash(uint256 blockNumber, bytes32 blockHash) external; function setEnv(string calldata name, string calldata value) external; function setNonce(address account, uint64 newNonce) external; @@ -429,7 +688,14 @@ interface Vm { function writeLine(string calldata path, string calldata data) external; function writeToml(string calldata json, string calldata path) external; function writeToml(string calldata json, string calldata path, string calldata valueKey) external; - function zkRegisterContract(string calldata name, bytes32 evmBytecodeHash, bytes calldata evmDeployedBytecode, bytes calldata evmBytecode, bytes32 zkBytecodeHash, bytes calldata zkDeployedBytecode) external pure; + function zkRegisterContract( + string calldata name, + bytes32 evmBytecodeHash, + bytes calldata evmDeployedBytecode, + bytes calldata evmBytecode, + bytes32 zkBytecodeHash, + bytes calldata zkDeployedBytecode + ) external pure; function zkVm(bool enable) external pure; function zkVmSkip() external pure; } diff --git a/testdata/zk/Cheatcodes.t.sol b/testdata/zk/Cheatcodes.t.sol index 84fcdd955..332a829ed 100644 --- a/testdata/zk/Cheatcodes.t.sol +++ b/testdata/zk/Cheatcodes.t.sol @@ -97,24 +97,15 @@ contract ZkCheatcodesTest is DSTest { require(block.number == ERA_FORK_BLOCK, "era block number mismatch"); vm.roll(ERA_FORK_BLOCK + 1); - require( - block.number == ERA_FORK_BLOCK + 1, - "era block number mismatch" - ); + require(block.number == ERA_FORK_BLOCK + 1, "era block number mismatch"); } function testZkCheatcodesWarp() public { vm.selectFork(forkEra); - require( - block.timestamp == ERA_FORK_BLOCK_TS, - "era block timestamp mismatch" - ); + require(block.timestamp == ERA_FORK_BLOCK_TS, "era block timestamp mismatch"); vm.warp(ERA_FORK_BLOCK_TS + 1); - require( - block.timestamp == ERA_FORK_BLOCK_TS + 1, - "era block timestamp mismatch" - ); + require(block.timestamp == ERA_FORK_BLOCK_TS + 1, "era block timestamp mismatch"); } function testZkCheatcodesDeal() public { @@ -139,18 +130,11 @@ contract ZkCheatcodesTest is DSTest { function testZkCheatcodesEtch() public { vm.selectFork(forkEra); - string memory artifact = vm.readFile( - "./zk/zkout/ConstantNumber.sol/ConstantNumber.json" - ); - bytes memory constantNumberCode = vm.parseJsonBytes( - artifact, - ".bytecode.object" - ); + string memory artifact = vm.readFile("./zk/zkout/ConstantNumber.sol/ConstantNumber.json"); + bytes memory constantNumberCode = vm.parseJsonBytes(artifact, ".bytecode.object"); vm.etch(TEST_ADDRESS, constantNumberCode); - (bool success, bytes memory output) = TEST_ADDRESS.call( - abi.encodeWithSignature("ten()") - ); + (bool success, bytes memory output) = TEST_ADDRESS.call(abi.encodeWithSignature("ten()")); require(success, "ten() call failed"); uint8 number = abi.decode(output, (uint8)); @@ -161,9 +145,7 @@ contract ZkCheatcodesTest is DSTest { FixedSlot fs = new FixedSlot(); vm.record(); fs.setSlot0(10); - (bytes32[] memory reads, bytes32[] memory writes) = vm.accesses( - address(fs) - ); + (bytes32[] memory reads, bytes32[] memory writes) = vm.accesses(address(fs)); bytes32 keySlot0 = bytes32(uint256(0)); assertEq(reads[0], keySlot0); assertEq(writes[0], keySlot0); @@ -198,11 +180,7 @@ contract ZkCheatcodesTest is DSTest { bytes memory dataBefore = target.getBytes(); assertEq(dataBefore, bytes(hex"abcd")); - vm.mockCall( - address(inner), - abi.encodeWithSelector(inner.getBytes.selector), - abi.encode(bytes(hex"a1b1")) - ); + vm.mockCall(address(inner), abi.encodeWithSelector(inner.getBytes.selector), abi.encode(bytes(hex"a1b1"))); bytes memory dataAfter = target.getBytes(); assertEq(dataAfter, bytes(hex"a1b1")); @@ -212,11 +190,7 @@ contract ZkCheatcodesTest is DSTest { address thisAddress = address(this); MyProxyCaller transactor = new MyProxyCaller(thisAddress); - vm.mockCall( - thisAddress, - abi.encodeWithSelector(IMyProxyCaller.transact.selector), - abi.encode() - ); + vm.mockCall(thisAddress, abi.encodeWithSelector(IMyProxyCaller.transact.selector), abi.encode()); transactor.transact(); } @@ -229,32 +203,19 @@ contract ZkCheatcodesTest is DSTest { MyProxyCaller transactor = new MyProxyCaller(mockMe); - vm.mockCall( - mockMe, - abi.encodeWithSelector(IMyProxyCaller.transact.selector), - abi.encode() - ); + vm.mockCall(mockMe, abi.encodeWithSelector(IMyProxyCaller.transact.selector), abi.encode()); transactor.transact(); } function testZkCheatcodesCanBeUsedAfterFork() public { - assertEq( - 0, - address(0x4e59b44847b379578588920cA78FbF26c0B4956C).balance - ); + assertEq(0, address(0x4e59b44847b379578588920cA78FbF26c0B4956C).balance); vm.createSelectFork(Globals.ETHEREUM_MAINNET_URL, ETH_FORK_BLOCK); - assertEq( - 0, - address(0x4e59b44847b379578588920cA78FbF26c0B4956C).balance - ); + assertEq(0, address(0x4e59b44847b379578588920cA78FbF26c0B4956C).balance); vm.deal(0x4e59b44847b379578588920cA78FbF26c0B4956C, 1 ether); - assertEq( - 1 ether, - address(0x4e59b44847b379578588920cA78FbF26c0B4956C).balance - ); + assertEq(1 ether, address(0x4e59b44847b379578588920cA78FbF26c0B4956C).balance); } function testRecordLogsInZkVm() public { @@ -284,18 +245,14 @@ contract ZkCheatcodesTest is DSTest { vm.makePersistent(address(emitter)); // ensure we are in zkvm - (bool _success, bytes memory _ret) = address(vm).call( - abi.encodeWithSignature("zkVm(bool)", true) - ); + (bool _success, bytes memory _ret) = address(vm).call(abi.encodeWithSignature("zkVm(bool)", true)); vm.recordLogs(); emitter.emitConsole("zkvm"); Vm.Log[] memory zkvmEntries = vm.getRecordedLogs(); // ensure we are NOT in zkvm - (_success, _ret) = address(vm).call( - abi.encodeWithSignature("zkVm(bool)", false) - ); + (_success, _ret) = address(vm).call(abi.encodeWithSignature("zkVm(bool)", false)); vm.recordLogs(); emitter.emitConsole("evm"); @@ -370,6 +327,7 @@ contract Calculator { contract EvmTargetContract is DSTest { Vm constant vm = Vm(HEVM_ADDRESS); + event Added(uint8 indexed sum); function exec() public {