Utils
Internal helper methods used by Upgrades and Defender libraries.
State Variables
CHEATCODE_ADDRESS
address constant CHEATCODE_ADDRESS = 0x7109709ECfa91a80626fF3989D68f67F5b1DD12D;
Functions
getFullyQualifiedName
Gets the fully qualified name of a contract.
function getFullyQualifiedName(string memory contractName, string memory outDir)
internal
view
returns (string memory);
Parameters
Name | Type | Description |
---|---|---|
contractName | string | Contract name in the format "MyContract.sol" or "MyContract.sol:MyContract" or artifact path relative to the project root directory |
outDir | string | Foundry output directory to search in if contractName is not an artifact path |
Returns
Name | Type | Description |
---|---|---|
<none> | string | Fully qualified name of the contract, e.g. "src/MyContract.sol:MyContract" |
getContractInfo
Gets information about a contract from its Foundry artifact.
function getContractInfo(string memory contractName, string memory outDir)
internal
view
returns (ContractInfo memory);
Parameters
Name | Type | Description |
---|---|---|
contractName | string | Contract name in the format "MyContract.sol" or "MyContract.sol:MyContract" or artifact path relative to the project root directory |
outDir | string | Foundry output directory to search in if contractName is not an artifact path |
Returns
Name | Type | Description |
---|---|---|
<none> | ContractInfo | ContractInfo struct containing information about the contract |
getBuildInfoFile
Gets the path to the build-info file that contains the given bytecode.
function getBuildInfoFile(string memory sourceCodeHash, string memory contractName, string memory outDir)
internal
returns (string memory);
Parameters
Name | Type | Description |
---|---|---|
sourceCodeHash | string | keccak256 hash of the source code from metadata |
contractName | string | Contract name to display in error message if build-info file is not found |
outDir | string | Foundry output directory that contains a build-info directory |
Returns
Name | Type | Description |
---|---|---|
<none> | string | The path to the build-info file that contains the given bytecode |
getOutDir
Gets the output directory from the FOUNDRY_OUT environment variable, or defaults to "out" if not set.
function getOutDir() internal view returns (string memory);
_toFileName
function _toFileName(string memory name) private pure returns (string memory);
_toShortName
function _toShortName(string memory name) private pure returns (string memory);
toBashCommand
Converts an array of inputs to a bash command.
function toBashCommand(string[] memory inputs, string memory bashPath) internal pure returns (string[] memory);
Parameters
Name | Type | Description |
---|---|---|
inputs | string[] | Inputs for a command, e.g. ["grep", "-rl", "0x1234", "out/build-info"] |
bashPath | string | Path to the bash executable or just "bash" if it is in the PATH |
Returns
Name | Type | Description |
---|---|---|
<none> | string[] | A bash command that runs the given inputs, e.g. ["bash", "-c", "grep -rl 0x1234 out/build-info"] |
runAsBashCommand
Runs an arbitrary command using bash.
function runAsBashCommand(string[] memory inputs) internal returns (Vm.FfiResult memory);
Parameters
Name | Type | Description |
---|---|---|
inputs | string[] | Inputs for a command, e.g. ["grep", "-rl", "0x1234", "out/build-info"] |
Returns
Name | Type | Description |
---|---|---|
<none> | Vm.FfiResult | The result of the corresponding bash command as a Vm.FfiResult struct |