Skip to content

Commit

Permalink
Address code review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
agostbiro committed Aug 1, 2024
1 parent 6cfbfc2 commit 8ade557
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
10 changes: 5 additions & 5 deletions crates/edr_napi/src/solidity_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ mod config;
mod runner;
mod test_results;

use std::{path::Path, sync::Arc};
use std::{collections::BTreeMap, path::Path, sync::Arc};

use artifact::Artifact;
use forge::TestFilter;
use foundry_common::ContractsByArtifact;
use foundry_common::{ContractData, ContractsByArtifact};
use napi::{
threadsafe_function::{
ErrorStrategy, ThreadSafeCallContext, ThreadsafeFunction, ThreadsafeFunctionCallMode,
Expand Down Expand Up @@ -44,11 +44,11 @@ pub fn run_solidity_tests(
|ctx: ThreadSafeCallContext<SuiteResult>| Ok(vec![ctx.value]),
)?;

let artifacts = artifacts
let known_contracts: ContractsByArtifact = artifacts
.into_iter()
.map(|item| Ok((item.id.try_into()?, item.contract.try_into()?)))
.collect::<Result<_, napi::Error>>()?;
let known_contracts = ContractsByArtifact::new(artifacts);
.collect::<Result<BTreeMap<foundry_common::ArtifactId, ContractData>, napi::Error>>()?
.into();

let test_suites = test_suites
.into_iter()
Expand Down
11 changes: 6 additions & 5 deletions crates/foundry/common/src/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ type ArtifactWithContractRef<'a> = (&'a ArtifactId, &'a ContractData);
pub struct ContractsByArtifact(BTreeMap<ArtifactId, ContractData>);

impl ContractsByArtifact {
/// Creates a new instance with the given map.
pub fn new(values: BTreeMap<ArtifactId, ContractData>) -> Self {
Self(values)
}

/// Creates a new instance by collecting all artifacts with present bytecode
/// from an iterator.
///
Expand Down Expand Up @@ -164,6 +159,12 @@ impl ContractsByArtifact {
}
}

impl From<BTreeMap<ArtifactId, ContractData>> for ContractsByArtifact {
fn from(value: BTreeMap<ArtifactId, ContractData>) -> Self {
Self(value)
}
}

/// Wrapper type that maps an address to a contract identifier and contract ABI.
pub type ContractsByAddress = BTreeMap<Address, (String, JsonAbi)>;

Expand Down
2 changes: 1 addition & 1 deletion crates/foundry/forge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl TestOptions {
})
}

/// Create a new test options configuration for Hardhat.
/// Creates a new test options configuration for Hardhat.
/// As opposed to Foundry, Hardhat doesn't support inline configuration.
pub fn new_hardhat(
base_fuzz: FuzzConfig,
Expand Down

0 comments on commit 8ade557

Please sign in to comment.