Skip to content

Commit

Permalink
fix(cli): handle id and named chain_id's correctly (#9480)
Browse files Browse the repository at this point in the history
* fix(`cli`): handle id and named chain_id's correctly

* test
  • Loading branch information
yash-atreya authored Dec 4, 2024
1 parent 805d7ce commit 3a1e76b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
19 changes: 19 additions & 0 deletions crates/cast/tests/cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = 55555u64;
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();
});
7 changes: 6 additions & 1 deletion crates/cli/src/opts/ethereum.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::opts::ChainValueParser;
use alloy_chains::ChainKind;
use clap::Parser;
use eyre::Result;
use foundry_config::{
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 3a1e76b

Please sign in to comment.