Skip to content

fix: better artifacts management for getCode#7685

Merged
klkvr merged 4 commits into
masterfrom
klkvr/fix-artifacts
Apr 17, 2024
Merged

fix: better artifacts management for getCode#7685
klkvr merged 4 commits into
masterfrom
klkvr/fix-artifacts

Conversation

@klkvr

@klkvr klkvr commented Apr 16, 2024

Copy link
Copy Markdown
Member

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.

@mattsse mattsse left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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

Comment thread crates/forge/src/multi_runner.rs Outdated
/// Additional cheatcode inspector related settings derived from the `Config`
pub cheats_config: Option<CheatsConfig>,
/// Project config.
pub config: Config,

Copy link
Copy Markdown
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?

Comment thread crates/common/src/contracts.rs
klkvr and others added 2 commits April 17, 2024 18:10
Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com>
@klkvr klkvr merged commit 19871fc into master Apr 17, 2024
@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