From f5acb1738fcc2fbc61967cfa9f2ae3f80d385d9a Mon Sep 17 00:00:00 2001 From: Yash Atreya <44857776+yash-atreya@users.noreply.github.com> Date: Wed, 4 Dec 2024 12:23:41 +0530 Subject: [PATCH 1/3] fix(`cli`): handle id and named chain_id's correctly --- crates/cli/src/opts/ethereum.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/cli/src/opts/ethereum.rs b/crates/cli/src/opts/ethereum.rs index 4b15b8551940..8d2601be1638 100644 --- a/crates/cli/src/opts/ethereum.rs +++ b/crates/cli/src/opts/ethereum.rs @@ -1,4 +1,5 @@ use crate::opts::ChainValueParser; +use alloy_chains::ChainKind; use clap::Parser; use eyre::Result; use foundry_config::{ @@ -154,7 +155,11 @@ impl EtherscanOpts { dict.insert("etherscan_api_key".into(), key.into()); } if let Some(chain) = self.chain { - dict.insert("chain_id".into(), chain.to_string().into()); + if let ChainKind::Id(id) = chain.kind() { + dict.insert("chain_id".into(), (*id).into()); + } else { + dict.insert("chain_id".into(), chain.to_string().into()); + } } dict } From c28ed8fabd431ef5a9a1c0c6e5f6aa75837bf686 Mon Sep 17 00:00:00 2001 From: Yash Atreya <44857776+yash-atreya@users.noreply.github.com> Date: Wed, 4 Dec 2024 12:52:12 +0530 Subject: [PATCH 2/3] test --- crates/cast/tests/cli/main.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/crates/cast/tests/cli/main.rs b/crates/cast/tests/cli/main.rs index cd833f7c3ed9..cc65aa6a36ab 100644 --- a/crates/cast/tests/cli/main.rs +++ b/crates/cast/tests/cli/main.rs @@ -1955,3 +1955,22 @@ Transaction successfully executed. "#]]); }); + +// https://github.com/foundry-rs/foundry/issues/9476 +forgetest_async!(cast_call_custom_chain_id, |_prj, cmd| { + let chain_id = 5555u64; + let (_api, handle) = anvil::spawn(NodeConfig::test().with_chain_id(Some(chain_id))).await; + + let http_endpoint = handle.http_endpoint(); + + cmd.cast_fuse() + .args([ + "call", + "5FbDB2315678afecb367f032d93F642f64180aa3", + "--rpc-url", + &http_endpoint, + "--chain", + &chain_id.to_string(), + ]) + .assert_success(); +}); From 72740539f3fe1ecd3975aa971e17b1cbe89f945b Mon Sep 17 00:00:00 2001 From: Yash Atreya <44857776+yash-atreya@users.noreply.github.com> Date: Wed, 4 Dec 2024 12:53:52 +0530 Subject: [PATCH 3/3] nit --- crates/cast/tests/cli/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/cast/tests/cli/main.rs b/crates/cast/tests/cli/main.rs index cc65aa6a36ab..fe9309877b6a 100644 --- a/crates/cast/tests/cli/main.rs +++ b/crates/cast/tests/cli/main.rs @@ -1958,7 +1958,7 @@ Transaction successfully executed. // https://github.com/foundry-rs/foundry/issues/9476 forgetest_async!(cast_call_custom_chain_id, |_prj, cmd| { - let chain_id = 5555u64; + let chain_id = 55555u64; let (_api, handle) = anvil::spawn(NodeConfig::test().with_chain_id(Some(chain_id))).await; let http_endpoint = handle.http_endpoint();