Skip to content

Commit 3a1e76b

Browse files
authored
fix(cli): handle id and named chain_id's correctly (#9480)
* fix(`cli`): handle id and named chain_id's correctly * test
1 parent 805d7ce commit 3a1e76b

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

crates/cast/tests/cli/main.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1955,3 +1955,22 @@ Transaction successfully executed.
19551955
19561956
"#]]);
19571957
});
1958+
1959+
// https://github.com/foundry-rs/foundry/issues/9476
1960+
forgetest_async!(cast_call_custom_chain_id, |_prj, cmd| {
1961+
let chain_id = 55555u64;
1962+
let (_api, handle) = anvil::spawn(NodeConfig::test().with_chain_id(Some(chain_id))).await;
1963+
1964+
let http_endpoint = handle.http_endpoint();
1965+
1966+
cmd.cast_fuse()
1967+
.args([
1968+
"call",
1969+
"5FbDB2315678afecb367f032d93F642f64180aa3",
1970+
"--rpc-url",
1971+
&http_endpoint,
1972+
"--chain",
1973+
&chain_id.to_string(),
1974+
])
1975+
.assert_success();
1976+
});

crates/cli/src/opts/ethereum.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::opts::ChainValueParser;
2+
use alloy_chains::ChainKind;
23
use clap::Parser;
34
use eyre::Result;
45
use foundry_config::{
@@ -154,7 +155,11 @@ impl EtherscanOpts {
154155
dict.insert("etherscan_api_key".into(), key.into());
155156
}
156157
if let Some(chain) = self.chain {
157-
dict.insert("chain_id".into(), chain.to_string().into());
158+
if let ChainKind::Id(id) = chain.kind() {
159+
dict.insert("chain_id".into(), (*id).into());
160+
} else {
161+
dict.insert("chain_id".into(), chain.to_string().into());
162+
}
158163
}
159164
dict
160165
}

0 commit comments

Comments
 (0)