From 7ef76bb470e878a0b9c818c7b7423cd32bb497ce Mon Sep 17 00:00:00 2001 From: Omar Abdulla Date: Thu, 24 Jul 2025 19:07:06 +0300 Subject: [PATCH] Use wrappers for libraries in metadata. --- crates/core/src/driver/mod.rs | 4 ++-- crates/format/src/metadata.rs | 26 +++++++++++++------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/crates/core/src/driver/mod.rs b/crates/core/src/driver/mod.rs index 5267c52..f8619c0 100644 --- a/crates/core/src/driver/mod.rs +++ b/crates/core/src/driver/mod.rs @@ -27,7 +27,7 @@ use revive_dt_compiler::{Compiler, SolidityCompiler}; use revive_dt_config::Arguments; use revive_dt_format::case::CaseIdx; use revive_dt_format::input::{Calldata, Expected, ExpectedOutput, Method}; -use revive_dt_format::metadata::{ContractInstance, ContractPathAndIdentifier}; +use revive_dt_format::metadata::{ContractInstance, ContractPathAndIdent}; use revive_dt_format::{input::Input, metadata::Metadata, mode::SolcMode}; use revive_dt_node::Node; use revive_dt_node_interaction::EthereumNode; @@ -197,7 +197,7 @@ where // What we have at this moment is just a contract instance which is kind of like a variable // name for an actual underlying contract. So, we need to resolve this instance to the info // of the contract that it belongs to. - let Some(ContractPathAndIdentifier { + let Some(ContractPathAndIdent { contract_source_path, contract_ident, }) = metadata.contract_sources()?.remove(&instance) diff --git a/crates/format/src/metadata.rs b/crates/format/src/metadata.rs index 9329002..47f938c 100644 --- a/crates/format/src/metadata.rs +++ b/crates/format/src/metadata.rs @@ -47,9 +47,9 @@ impl Deref for MetadataFile { pub struct Metadata { pub targets: Option>, pub cases: Vec, - pub contracts: Option>, + pub contracts: Option>, // TODO: Convert into wrapper types for clarity. - pub libraries: Option>>, + pub libraries: Option>>, pub ignore: Option, pub modes: Option>, pub file_path: Option, @@ -86,7 +86,7 @@ impl Metadata { /// Returns the contract sources with canonicalized paths for the files pub fn contract_sources( &self, - ) -> anyhow::Result> { + ) -> anyhow::Result> { let directory = self.directory()?; let mut sources = BTreeMap::new(); let Some(contracts) = &self.contracts else { @@ -95,7 +95,7 @@ impl Metadata { for ( alias, - ContractPathAndIdentifier { + ContractPathAndIdent { contract_source_path, contract_ident, }, @@ -107,7 +107,7 @@ impl Metadata { sources.insert( alias, - ContractPathAndIdentifier { + ContractPathAndIdent { contract_source_path: absolute_path, contract_ident, }, @@ -194,7 +194,7 @@ impl Metadata { metadata.contracts = Some( [( ContractInstance::new("test"), - ContractPathAndIdentifier { + ContractPathAndIdent { contract_source_path: path.to_path_buf(), contract_ident: ContractIdent::new("Test"), }, @@ -245,7 +245,7 @@ define_wrapper_type!( /// ``` #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] #[serde(try_from = "String", into = "String")] -pub struct ContractPathAndIdentifier { +pub struct ContractPathAndIdent { /// The path of the contract source code relative to the directory containing the metadata file. pub contract_source_path: PathBuf, @@ -253,7 +253,7 @@ pub struct ContractPathAndIdentifier { pub contract_ident: ContractIdent, } -impl Display for ContractPathAndIdentifier { +impl Display for ContractPathAndIdent { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!( f, @@ -264,7 +264,7 @@ impl Display for ContractPathAndIdentifier { } } -impl FromStr for ContractPathAndIdentifier { +impl FromStr for ContractPathAndIdent { type Err = anyhow::Error; fn from_str(s: &str) -> Result { @@ -300,7 +300,7 @@ impl FromStr for ContractPathAndIdentifier { } } -impl TryFrom for ContractPathAndIdentifier { +impl TryFrom for ContractPathAndIdent { type Error = anyhow::Error; fn try_from(value: String) -> Result { @@ -308,8 +308,8 @@ impl TryFrom for ContractPathAndIdentifier { } } -impl From for String { - fn from(value: ContractPathAndIdentifier) -> Self { +impl From for String { + fn from(value: ContractPathAndIdent) -> Self { value.to_string() } } @@ -324,7 +324,7 @@ mod test { let string = "ERC20/ERC20.sol:ERC20"; // Act - let identifier = ContractPathAndIdentifier::from_str(string); + let identifier = ContractPathAndIdent::from_str(string); // Assert let identifier = identifier.expect("Failed to parse");