Skip to content

Commit

Permalink
fix(features): remove ethers-solc for foundry-compilers (#3)
Browse files Browse the repository at this point in the history
* fix(features): remove ethers-solc for foundry-compilers

* chore: imports
  • Loading branch information
Evalir authored Oct 18, 2023
1 parent e218510 commit c9c3470
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
13 changes: 8 additions & 5 deletions src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ use semver::Version;
use serde::{Deserialize, Serialize};
use std::{collections::HashMap, path::Path};

#[cfg(feature = "foundry-compilers")]
use foundry_compilers::{artifacts::Settings, EvmVersion, Project, ProjectBuilder, SolcConfig};

#[derive(Clone, Debug, Default, Serialize, Deserialize)]
pub enum SourceCodeLanguage {
#[default]
Expand Down Expand Up @@ -85,7 +88,7 @@ impl SourceCodeMetadata {
}
}

#[cfg(feature = "ethers-solc")]
#[cfg(feature = "foundry-compilers")]
pub fn settings(&self) -> Result<Option<Settings>> {
match self {
Self::Metadata { settings, .. } => match settings {
Expand All @@ -103,7 +106,7 @@ impl SourceCodeMetadata {
}
}

#[cfg(not(feature = "ethers-solc"))]
#[cfg(not(feature = "foundry-compilers"))]
pub fn settings(&self) -> Option<&serde_json::Value> {
match self {
Self::Metadata { settings, .. } => settings.as_ref(),
Expand Down Expand Up @@ -246,7 +249,7 @@ impl Metadata {
}

/// Returns the contract's compiler settings.
#[cfg(feature = "ethers-solc")]
#[cfg(feature = "foundry-compilers")]
pub fn settings(&self) -> Result<Settings> {
let mut settings = self.source_code.settings()?.unwrap_or_default();

Expand All @@ -261,15 +264,15 @@ impl Metadata {
}

/// Creates a Solc [ProjectBuilder] with this contract's settings.
#[cfg(feature = "ethers-solc")]
#[cfg(feature = "foundry-compilers")]
pub fn project_builder(&self) -> Result<ProjectBuilder> {
let solc_config = SolcConfig::builder().settings(self.settings()?).build();

Ok(Project::builder().solc_config(solc_config))
}

/// Parses the EVM version.
#[cfg(feature = "ethers-solc")]
#[cfg(feature = "foundry-compilers")]
pub fn evm_version(&self) -> Result<Option<EvmVersion>> {
match self.evm_version.as_str() {
"" | "Default" => {
Expand Down
4 changes: 2 additions & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ mod tests {
de.source_code.sources().get("Contract").unwrap().content,
src
);
#[cfg(feature = "ethers-solc")]
#[cfg(feature = "foundry-compilers")]
assert!(de.source_code.settings().unwrap().is_none());

// Stringified JSON
Expand All @@ -294,7 +294,7 @@ mod tests {
de.source_code.sources().get("Contract").unwrap().content,
src
);
#[cfg(feature = "ethers-solc")]
#[cfg(feature = "foundry-compilers")]
assert!(de.source_code.settings().unwrap().is_none());

let json = r#"{"source_code": "source code text"}"#;
Expand Down

0 comments on commit c9c3470

Please sign in to comment.