Skip to content

Commit 1da4d32

Browse files
redtramagrandizzy
andauthored
feat: add vm.getChain(chainAlias) (#10226)
* add Chain struct * generate interface * define getChain cheatcode * add getChain(alias) implementation * add GetChain test * run fmt * fix: add alloy_chain for check chain validity --------- Co-authored-by: grandizzy <38490174+grandizzy@users.noreply.github.com>
1 parent 09970aa commit 1da4d32

File tree

9 files changed

+706
-1
lines changed

9 files changed

+706
-1
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/cheatcodes/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ parking_lot.workspace = true
4040
alloy-consensus = { workspace = true, features = ["k256"] }
4141
alloy-network.workspace = true
4242
alloy-rlp.workspace = true
43+
alloy-chains.workspace = true
4344

4445
base64.workspace = true
4546
dialoguer = "0.11"

crates/cheatcodes/assets/cheatcodes.json

Lines changed: 66 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/cheatcodes/spec/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ impl Cheatcodes<'static> {
8383
Vm::Wallet::STRUCT.clone(),
8484
Vm::FfiResult::STRUCT.clone(),
8585
Vm::ChainInfo::STRUCT.clone(),
86+
Vm::Chain::STRUCT.clone(),
8687
Vm::AccountAccess::STRUCT.clone(),
8788
Vm::StorageAccess::STRUCT.clone(),
8889
Vm::Gas::STRUCT.clone(),

crates/cheatcodes/spec/src/vm.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,18 @@ interface Vm {
207207
uint256 chainId;
208208
}
209209

210+
/// Information about a blockchain.
211+
struct Chain {
212+
/// The chain name.
213+
string name;
214+
/// The chain's Chain ID.
215+
uint256 chainId;
216+
/// The chain's alias. (i.e. what gets specified in `foundry.toml`).
217+
string chainAlias;
218+
/// A default RPC endpoint for this chain.
219+
string rpcUrl;
220+
}
221+
210222
/// The storage accessed during an `AccountAccess`.
211223
struct StorageAccess {
212224
/// The account whose storage was accessed.
@@ -967,6 +979,14 @@ interface Vm {
967979
#[cheatcode(group = Testing, safety = Safe)]
968980
function rpcUrlStructs() external view returns (Rpc[] memory urls);
969981

982+
/// Returns a Chain struct for specific alias
983+
#[cheatcode(group = Testing, safety = Safe)]
984+
function getChain(string calldata chainAlias) external view returns (Chain memory chain);
985+
986+
/// Returns a Chain struct for specific chainId
987+
#[cheatcode(group = Testing, safety = Safe)]
988+
function getChain(uint256 chainId) external view returns (Chain memory chain);
989+
970990
/// Suspends execution of the main thread for `duration` milliseconds.
971991
#[cheatcode(group = Testing, safety = Safe)]
972992
function sleep(uint256 duration) external;

0 commit comments

Comments
 (0)