Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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

NameTypeDescription
contractNamestringContract name in the format "MyContract.sol" or "MyContract.sol:MyContract" or artifact path relative to the project root directory
outDirstringFoundry output directory to search in if contractName is not an artifact path

Returns

NameTypeDescription
<none>stringFully 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

NameTypeDescription
contractNamestringContract name in the format "MyContract.sol" or "MyContract.sol:MyContract" or artifact path relative to the project root directory
outDirstringFoundry output directory to search in if contractName is not an artifact path

Returns

NameTypeDescription
<none>ContractInfoContractInfo 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

NameTypeDescription
sourceCodeHashstringkeccak256 hash of the source code from metadata
contractNamestringContract name to display in error message if build-info file is not found
outDirstringFoundry output directory that contains a build-info directory

Returns

NameTypeDescription
<none>stringThe 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

NameTypeDescription
inputsstring[]Inputs for a command, e.g. ["grep", "-rl", "0x1234", "out/build-info"]
bashPathstringPath to the bash executable or just "bash" if it is in the PATH

Returns

NameTypeDescription
<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

NameTypeDescription
inputsstring[]Inputs for a command, e.g. ["grep", "-rl", "0x1234", "out/build-info"]

Returns

NameTypeDescription
<none>Vm.FfiResultThe result of the corresponding bash command as a Vm.FfiResult struct