Skip to content
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
400 changes: 400 additions & 0 deletions crates/cheatcodes/assets/cheatcodes.json

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions crates/cheatcodes/assets/cheatcodes.schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions crates/cheatcodes/spec/src/cheatcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ pub enum Group {
///
/// Safety: safe.
Scripting,
/// Cheatcodes that interact with the program's forking configuration.
///
/// Examples: `forkChains`, `forkChainRpcUrl`, `forkUint`.
///
/// Safety: safe.
Forking,
/// Cheatcodes that interact with the OS or filesystem.
///
/// Examples: `ffi`, `projectRoot`, `writeFile`.
Expand Down Expand Up @@ -140,6 +146,7 @@ impl Group {
match self {
Self::Evm | Self::Testing => None,
Self::Scripting
| Self::Forking
| Self::Filesystem
| Self::Environment
| Self::String
Expand All @@ -157,6 +164,7 @@ impl Group {
Self::Evm => "evm",
Self::Testing => "testing",
Self::Scripting => "scripting",
Self::Forking => "forking",
Self::Filesystem => "filesystem",
Self::Environment => "environment",
Self::String => "string",
Expand Down
107 changes: 106 additions & 1 deletion crates/cheatcodes/spec/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2179,8 +2179,113 @@ interface Vm {
#[cheatcode(group = Environment)]
function isContext(ForgeContext context) external view returns (bool result);

// ======== Scripts ========
// ======== Forks ========

/// Returns an array with the name of all the configured fork chains.
///
/// Note that the configured fork chains are subsections of the `[fork]` section of 'foundry.toml'.
#[cheatcode(group = Forking)]
function forkChains() external view returns (string[] memory);

/// Returns an array with the ids of all the configured fork chains.
///
/// Note that the configured fork chains are subsections of the `[fork]` section of 'foundry.toml'.
#[cheatcode(group = Forking)]
function forkChainIds() external view returns (uint256[] memory);

/// Returns the chain name of the currently selected fork.
#[cheatcode(group = Forking)]
function forkChain() external view returns (string memory);

/// Returns the chain id of the currently selected fork.
#[cheatcode(group = Forking)]
function forkChainId() external view returns (uint256);

/// Returns the rpc url of the currently selected fork.
///
/// By default, the rpc url of each fork is derived from the `[rpc_endpoints]`, unless
/// the rpc config is specifically informed in the fork config for that specific chain.
#[cheatcode(group = Forking)]
function forkRpcUrl() external view returns (string memory);

/// Returns the rpc url of the corresponding chain id.
///
/// By default, the rpc url of each fork is derived from the `[rpc_endpoints]`, unless
/// the rpc config is specifically informed in the fork config for that specific chain.
#[cheatcode(group = Forking)]
function forkChainRpcUrl(uint256 id) external view returns (string memory);

/// Gets the value for the key `key` from the currently active fork and parses it as `bool`.
/// Reverts if the key was not found or the value could not be parsed.
#[cheatcode(group = Forking)]
function forkBool(string memory key) external view returns (bool);

/// Gets the value for the key `key` from the fork config for chain `chain` and parses it as `bool`.
/// Reverts if the key was not found or the value could not be parsed.
#[cheatcode(group = Forking)]
function forkChainBool(uint256 chain, string memory key) external view returns (bool);

/// Gets the value for the key `key` from the currently active fork and parses it as `int256`.
/// Reverts if the key was not found or the value could not be parsed.
#[cheatcode(group = Forking)]
function forkInt(string memory key) external view returns (int256);

/// Gets the value for the key `key` from the fork config for chain `chain` and parses it as `int256`.
/// Reverts if the key was not found or the value could not be parsed.
#[cheatcode(group = Forking)]
function forkChainInt(uint256 chain, string memory key) external view returns (int256);

/// Gets the value for the key `key` from the currently active fork and parses it as `uint256`.
/// Reverts if the key was not found or the value could not be parsed.
#[cheatcode(group = Forking)]
function forkUint(string memory key) external view returns (uint256);

/// Gets the value for the key `key` from the fork config for chain `chain` and parses it as `uint256`.
/// Reverts if the key was not found or the value could not be parsed.
#[cheatcode(group = Forking)]
function forkChainUint(uint256 chain, string memory key) external view returns (uint256);

/// Gets the value for the key `key` from the currently active fork and parses it as `address`.
/// Reverts if the key was not found or the value could not be parsed.
#[cheatcode(group = Forking)]
function forkAddress(string memory key) external view returns (address);

/// Gets the value for the key `key` from the fork config for chain `chain` and parses it as `address`.
/// Reverts if the key was not found or the value could not be parsed.
#[cheatcode(group = Forking)]
function forkChainAddress(uint256 chain, string memory key) external view returns (address);

/// Gets the value for the key `key` from the currently active fork and parses it as `bytes32`.
/// Reverts if the key was not found or the value could not be parsed.
#[cheatcode(group = Forking)]
function forkBytes32(string memory key) external view returns (bytes32);

/// Gets the value for the key `key` from the fork config for chain `chain` and parses it as `bytes32`.
/// Reverts if the key was not found or the value could not be parsed.
#[cheatcode(group = Forking)]
function forkChainBytes32(uint256 chain, string memory key) external view returns (bytes32);

/// Gets the value for the key `key` from the currently active fork and parses it as `string`.
/// Reverts if the key was not found or the value could not be parsed.
#[cheatcode(group = Forking)]
function forkString(string memory key) external view returns (string memory);

/// Gets the value for the key `key` from the fork config for chain `chain` and parses it as `string`.
/// Reverts if the key was not found or the value could not be parsed.
#[cheatcode(group = Forking)]
function forkChainString(uint256 chain, string memory key) external view returns (string memory);

/// Gets the value for the key `key` from the currently active fork and parses it as `bytes`.
/// Reverts if the key was not found or the value could not be parsed.
#[cheatcode(group = Forking)]
function forkBytes(string memory key) external view returns (bytes memory);

/// Gets the value for the key `key` from the fork config for chain `chain` and parses it as `bytes`.
/// Reverts if the key was not found or the value could not be parsed.
#[cheatcode(group = Forking)]
function forkChainBytes(uint256 chain, string memory key) external view returns (bytes memory);

// ======== Scripts ========
// -------- Broadcasting Transactions --------

/// Has the next call (at this call depth only) create transactions that can later be signed and sent onchain.
Expand Down
8 changes: 6 additions & 2 deletions crates/cheatcodes/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use alloy_primitives::{U256, map::AddressHashMap};
use foundry_common::{ContractsByArtifact, fs::normalize_path};
use foundry_compilers::{ArtifactId, ProjectPathsConfig, utils::canonicalize};
use foundry_config::{
Config, FsPermissions, ResolvedRpcEndpoint, ResolvedRpcEndpoints, RpcEndpoint, RpcEndpointUrl,
cache::StorageCachingConfig, fs_permissions::FsAccessKind,
Config, ForkConfig, FsPermissions, ResolvedRpcEndpoint, ResolvedRpcEndpoints, RpcEndpoint,
RpcEndpointUrl, cache::StorageCachingConfig, fs_permissions::FsAccessKind,
};
use foundry_evm_core::opts::EvmOpts;
use std::{
Expand Down Expand Up @@ -63,6 +63,8 @@ pub struct CheatsConfig {
pub chains: HashMap<String, ChainData>,
/// Mapping of chain IDs to their aliases
pub chain_id_to_alias: HashMap<u64, String>,
/// Fork configuration
pub forks: HashMap<String, ForkConfig>,
}

/// Chain data for getChain cheatcodes
Expand Down Expand Up @@ -114,6 +116,7 @@ impl CheatsConfig {
internal_expect_revert: config.allow_internal_expect_revert,
chains: HashMap::new(),
chain_id_to_alias: HashMap::new(),
forks: config.forks.clone(),
}
}

Expand Down Expand Up @@ -318,6 +321,7 @@ impl Default for CheatsConfig {
internal_expect_revert: false,
chains: HashMap::new(),
chain_id_to_alias: HashMap::new(),
forks: Default::default(),
}
}
}
Expand Down
Loading
Loading