@@ -739,12 +739,12 @@ impl Config {
739
739
/// # }
740
740
/// ```
741
741
pub fn get_rpc_url ( & self ) -> Option < Result < Cow < str > , UnresolvedEnvVarError > > {
742
- let eth_rpc_url = self . eth_rpc_url . as_ref ( ) . or ( self . etherscan_api_key . as_ref ( ) ) ?;
742
+ let maybe_alias = self . eth_rpc_url . as_ref ( ) . or ( self . etherscan_api_key . as_ref ( ) ) ?;
743
743
let mut endpoints = self . rpc_endpoints . clone ( ) . resolved ( ) ;
744
- if let Some ( alias) = endpoints. remove ( eth_rpc_url ) {
744
+ if let Some ( alias) = endpoints. remove ( maybe_alias ) {
745
745
Some ( alias. map ( Cow :: Owned ) )
746
746
} else {
747
- Some ( Ok ( Cow :: Borrowed ( eth_rpc_url. as_str ( ) ) ) )
747
+ Some ( Ok ( Cow :: Borrowed ( self . eth_rpc_url . as_deref ( ) ? ) ) )
748
748
}
749
749
}
750
750
@@ -818,7 +818,9 @@ impl Config {
818
818
// we treat the `etherscan_api_key` as actual API key
819
819
// if no chain provided, we assume mainnet
820
820
let chain = self . chain_id . unwrap_or_else ( || Mainnet . into ( ) ) ;
821
- ResolvedEtherscanConfig :: create ( maybe_alias, chain) . map ( Ok )
821
+
822
+ let api_key = self . etherscan_api_key . as_ref ( ) ?;
823
+ ResolvedEtherscanConfig :: create ( api_key, chain) . map ( Ok )
822
824
}
823
825
824
826
/// Same as [`Self::get_etherscan_config()`] but optionally updates the config with the given
@@ -2859,6 +2861,26 @@ mod tests {
2859
2861
} )
2860
2862
}
2861
2863
2864
+ #[ test]
2865
+ fn test_resolve_rpc_url_if_etherscan_set ( ) {
2866
+ figment:: Jail :: expect_with ( |jail| {
2867
+ jail. create_file (
2868
+ "foundry.toml" ,
2869
+ r#"
2870
+ [profile.default]
2871
+ etherscan_api_key = "dummy"
2872
+ [rpc_endpoints]
2873
+ optimism = "https://example.com/"
2874
+ "# ,
2875
+ ) ?;
2876
+
2877
+ let config = Config :: load ( ) ;
2878
+ assert_eq ! ( "http://localhost:8545" , config. get_rpc_url_or_localhost_http( ) . unwrap( ) ) ;
2879
+
2880
+ Ok ( ( ) )
2881
+ } )
2882
+ }
2883
+
2862
2884
#[ test]
2863
2885
fn test_resolve_rpc_url_alias ( ) {
2864
2886
figment:: Jail :: expect_with ( |jail| {
0 commit comments