-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(forge
): fix cache search for verification
#7053
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
use super::{provider::VerificationProvider, VerifyArgs, VerifyCheckArgs}; | ||
use crate::cmd::retry::RETRY_CHECK_ON_VERIFY; | ||
use alloy_json_abi::Function; | ||
use eyre::{eyre, Context, Result}; | ||
use eyre::{eyre, Context, OptionExt, Result}; | ||
use forge::hashbrown::HashSet; | ||
use foundry_block_explorers::{ | ||
errors::EtherscanError, | ||
|
@@ -11,7 +11,9 @@ use foundry_block_explorers::{ | |
}; | ||
use foundry_cli::utils::{get_cached_entry_by_name, read_constructor_args_file, LoadConfig}; | ||
use foundry_common::{abi::encode_function_args, retry::Retry}; | ||
use foundry_compilers::{artifacts::CompactContract, cache::CacheEntry, Project, Solc}; | ||
use foundry_compilers::{ | ||
artifacts::CompactContract, cache::CacheEntry, info::ContractInfo, Project, Solc, | ||
}; | ||
use foundry_config::{Chain, Config, SolcReq}; | ||
use futures::FutureExt; | ||
use once_cell::sync::Lazy; | ||
|
@@ -212,15 +214,27 @@ impl EtherscanVerificationProvider { | |
fn cache_entry( | ||
&mut self, | ||
project: &Project, | ||
contract_name: &str, | ||
contract: &ContractInfo, | ||
) -> Result<&(PathBuf, CacheEntry, CompactContract)> { | ||
if let Some(ref entry) = self.cached_entry { | ||
return Ok(entry) | ||
} | ||
|
||
let cache = project.read_cache_file()?; | ||
let (path, entry) = get_cached_entry_by_name(&cache, contract_name)?; | ||
let contract: CompactContract = cache.read_artifact(path.clone(), contract_name)?; | ||
let (path, entry) = match contract.path.as_ref() { | ||
Some(path) => { | ||
let path = project.root().join(path); | ||
( | ||
path.clone(), | ||
cache | ||
.entry(&path) | ||
.ok_or_eyre(format!("Cache entry not found for {}", path.display()))? | ||
.to_owned(), | ||
) | ||
} | ||
None => get_cached_entry_by_name(&cache, &contract.name)?, | ||
}; | ||
mattsse marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let contract: CompactContract = cache.read_artifact(path.clone(), &contract.name)?; | ||
Ok(self.cached_entry.insert((path, entry, contract))) | ||
} | ||
|
||
|
@@ -350,7 +364,7 @@ impl EtherscanVerificationProvider { | |
let path = match args.contract.path.as_ref() { | ||
Some(path) => project.root().join(path), | ||
None => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. while we're at it, let's also do if let some else for this |
||
let (path, _, _) = self.cache_entry(project, &args.contract.name).wrap_err( | ||
let (path, _, _) = self.cache_entry(project, &args.contract).wrap_err( | ||
"If cache is disabled, contract info must be provided in the format <path>:<name>", | ||
)?; | ||
path.to_owned() | ||
|
@@ -391,7 +405,7 @@ impl EtherscanVerificationProvider { | |
} | ||
} | ||
|
||
let (_, entry, _) = self.cache_entry(project, &args.contract.name).wrap_err( | ||
let (_, entry, _) = self.cache_entry(project, &args.contract).wrap_err( | ||
"If cache is disabled, compiler version must be either provided with `--compiler-version` option or set in foundry.toml" | ||
)?; | ||
let artifacts = entry.artifacts_versions().collect::<Vec<_>>(); | ||
|
@@ -423,7 +437,7 @@ impl EtherscanVerificationProvider { | |
/// return whatever was set in the [VerifyArgs] args. | ||
fn constructor_args(&mut self, args: &VerifyArgs, project: &Project) -> Result<Option<String>> { | ||
if let Some(ref constructor_args_path) = args.constructor_args_path { | ||
let (_, _, contract) = self.cache_entry(project, &args.contract.name).wrap_err( | ||
let (_, _, contract) = self.cache_entry(project, &args.contract).wrap_err( | ||
"Cache must be enabled in order to use the `--constructor-args-path` option", | ||
)?; | ||
let abi = | ||
|
@@ -474,6 +488,7 @@ mod tests { | |
use clap::Parser; | ||
use foundry_cli::utils::LoadConfig; | ||
use foundry_common::fs; | ||
use foundry_test_utils::forgetest_async; | ||
use tempfile::tempdir; | ||
|
||
#[test] | ||
|
@@ -613,4 +628,22 @@ mod tests { | |
"Cache must be enabled in order to use the `--constructor-args-path` option", | ||
); | ||
} | ||
|
||
forgetest_async!(respects_path_for_duplicate, |prj, cmd| { | ||
prj.add_source("Counter1", "contract Counter {}").unwrap(); | ||
prj.add_source("Counter2", "contract Counter {}").unwrap(); | ||
|
||
cmd.args(["build", "--force"]).ensure_execute_success().unwrap(); | ||
|
||
let args = VerifyArgs::parse_from([ | ||
"foundry-cli", | ||
"0x0000000000000000000000000000000000000000", | ||
"src/Counter1.sol:Counter", | ||
"--root", | ||
&prj.root().to_string_lossy(), | ||
]); | ||
|
||
let mut etherscan = EtherscanVerificationProvider::default(); | ||
etherscan.preflight_check(args).await.unwrap(); | ||
}); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL ok_or_eyre