-
Notifications
You must be signed in to change notification settings - Fork 2k
fix: better artifacts management for getCode
#7685
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
Merged
Merged
Changes from all commits
Commits
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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
---|---|---|
|
@@ -7,7 +7,6 @@ use forge::{ | |
analysis::SourceAnalyzer, anchors::find_anchors, BytecodeReporter, ContractId, | ||
CoverageReport, CoverageReporter, DebugReporter, LcovReporter, SummaryReporter, | ||
}, | ||
inspectors::CheatsConfig, | ||
opts::EvmOpts, | ||
result::SuiteResult, | ||
revm::primitives::SpecId, | ||
|
@@ -28,7 +27,11 @@ use foundry_compilers::{ | |
use foundry_config::{Config, SolcReq}; | ||
use rustc_hash::FxHashMap; | ||
use semver::Version; | ||
use std::{collections::HashMap, path::PathBuf, sync::mpsc::channel}; | ||
use std::{ | ||
collections::HashMap, | ||
path::PathBuf, | ||
sync::{mpsc::channel, Arc}, | ||
}; | ||
use yansi::Paint; | ||
|
||
/// A map, keyed by contract ID, to a tuple of the deployment source map and the runtime source map. | ||
|
@@ -101,7 +104,7 @@ impl CoverageArgs { | |
let report = self.prepare(&config, output.clone())?; | ||
|
||
p_println!(!self.opts.silent => "Running tests..."); | ||
self.collect(project, output, report, config, evm_opts).await | ||
self.collect(project, output, report, Arc::new(config), evm_opts).await | ||
} | ||
|
||
/// Builds the project. | ||
|
@@ -308,61 +311,53 @@ impl CoverageArgs { | |
project: Project, | ||
output: ProjectCompileOutput, | ||
mut report: CoverageReport, | ||
config: Config, | ||
config: Arc<Config>, | ||
evm_opts: EvmOpts, | ||
) -> Result<()> { | ||
let root = project.paths.root; | ||
|
||
let artifact_ids = output.artifact_ids().map(|(id, _)| id).collect(); | ||
|
||
// Build the contract runner | ||
let env = evm_opts.evm_env().await?; | ||
let mut runner = MultiContractRunnerBuilder::default() | ||
let mut runner = MultiContractRunnerBuilder::new(config.clone()) | ||
.initial_balance(evm_opts.initial_balance) | ||
.evm_spec(config.evm_spec_id()) | ||
.sender(evm_opts.sender) | ||
.with_fork(evm_opts.get_fork(&config, env.clone())) | ||
.with_cheats_config(CheatsConfig::new( | ||
&config, | ||
evm_opts.clone(), | ||
Some(artifact_ids), | ||
None, | ||
None, | ||
)) | ||
Comment on lines
-325
to
-331
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. I see, this makes cheatsconfig redundant here |
||
.with_test_options(TestOptions { | ||
fuzz: config.fuzz, | ||
fuzz: config.fuzz.clone(), | ||
invariant: config.invariant, | ||
..Default::default() | ||
}) | ||
.set_coverage(true) | ||
.build(&root, output, env, evm_opts)?; | ||
|
||
// Run tests | ||
let known_contracts = runner.known_contracts.clone(); | ||
let filter = self.filter; | ||
let (tx, rx) = channel::<(String, SuiteResult)>(); | ||
let handle = tokio::task::spawn_blocking(move || runner.test(&filter, tx)); | ||
|
||
// Add hit data to the coverage report | ||
let data = rx | ||
.into_iter() | ||
.flat_map(|(_, suite)| suite.test_results.into_values()) | ||
.filter_map(|mut result| result.coverage.take()) | ||
.flat_map(|hit_maps| { | ||
hit_maps.0.into_values().filter_map(|map| { | ||
let data = rx.into_iter().flat_map(|(_, suite)| { | ||
let mut hits = Vec::new(); | ||
for (_, mut result) in suite.test_results { | ||
let Some(hit_maps) = result.coverage.take() else { continue }; | ||
|
||
for map in hit_maps.0.into_values() { | ||
if let Some((id, _)) = | ||
known_contracts.find_by_deployed_code(map.bytecode.as_ref()) | ||
suite.known_contracts.find_by_deployed_code(map.bytecode.as_ref()) | ||
{ | ||
Some((id, map, true)) | ||
hits.push((id.clone(), map, true)); | ||
} else if let Some((id, _)) = | ||
known_contracts.find_by_creation_code(map.bytecode.as_ref()) | ||
suite.known_contracts.find_by_creation_code(map.bytecode.as_ref()) | ||
{ | ||
Some((id, map, false)) | ||
} else { | ||
None | ||
hits.push((id.clone(), map, false)); | ||
} | ||
}) | ||
}); | ||
} | ||
} | ||
|
||
hits | ||
}); | ||
|
||
for (artifact_id, hits, is_deployed_code) in data { | ||
// TODO: Note down failing tests | ||
if let Some(source_id) = report.get_source_id( | ||
|
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.
Uh oh!
There was an error while loading. Please reload this page.