Skip to content
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: better artifacts management for getCode #7685

Merged
merged 4 commits into from
Apr 17, 2024
Merged

Conversation

klkvr
Copy link
Member

@klkvr klkvr commented Apr 16, 2024

Motivation

Follow-up to #7661 extending usage of ContractsByArtifact

Closes #4876

Solution

Rewrite getCode logic to directly use compilation artifacts instead of reading them from filesystem. This makes it possible to use getCode in tests which were compiled without writing artifacts (which is happening in coverage for example).

This also separates known_contracts per each test contract. This is needed because different test contracts might be linked with different libraries, thus having a single known_contracts object is incorrect and might result in invalid getCode output or identifiers failing to identify contracts. This introduces overhead of cloning compiler output for each running test which shouldn't affect performance much I believe.

Related to #1161 and foundry-rs/book#1361 but not resolves in full because getCode will now only work for linked contracts which only depend on subset of test contract libraries.

Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also separates known_contracts per each test contract. This is needed because different test contracts might be linked with different libraries, thus having a single known_contracts object is incorrect and might result in invalid getCode output or identifiers failing to identify contracts.

I see, this makes sense

This introduces overhead of cloning compiler output for each running test which shouldn't affect performance much I believe.

this should be ok.

removing the cheatsconfig also makes sense to me

reasonable, I think artifact mgmt is a lot better now,

pending @DaniPopes

Comment on lines -325 to -331
.with_cheats_config(CheatsConfig::new(
&config,
evm_opts.clone(),
Some(artifact_ids),
None,
None,
))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, this makes cheatsconfig redundant here

/// Additional cheatcode inspector related settings derived from the `Config`
pub cheats_config: Option<CheatsConfig>,
/// Project config.
pub config: Config,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this also be an Arc?

crates/common/src/contracts.rs Show resolved Hide resolved
@klkvr klkvr merged commit 19871fc into master Apr 17, 2024
19 checks passed
@klkvr klkvr deleted the klkvr/fix-artifacts branch April 17, 2024 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Coverage report inconsistent
3 participants