diff --git a/crates/compiler/src/lib.rs b/crates/compiler/src/lib.rs index c3a6fb8..5b6d247 100644 --- a/crates/compiler/src/lib.rs +++ b/crates/compiler/src/lib.rs @@ -65,6 +65,7 @@ pub struct CompilerInput { pub base_path: Option, pub sources: HashMap, pub libraries: HashMap>, + pub revert_string_handling: Option, } /// The generic compilation output configuration. @@ -101,6 +102,7 @@ where base_path: Default::default(), sources: Default::default(), libraries: Default::default(), + revert_string_handling: Default::default(), }, additional_options: T::Options::default(), } @@ -152,6 +154,14 @@ where self } + pub fn with_revert_string_handling( + mut self, + revert_string_handling: impl Into>, + ) -> Self { + self.input.revert_string_handling = revert_string_handling.into(); + self + } + pub fn with_additional_options(mut self, options: impl Into) -> Self { self.additional_options = options.into(); self @@ -170,3 +180,15 @@ where self.input.clone() } } + +/// Defines how the compiler should handle revert strings. +#[derive( + Clone, Debug, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Serialize, Deserialize, +)] +pub enum RevertString { + #[default] + Default, + Debug, + Strip, + VerboseDebug, +} diff --git a/crates/compiler/src/revive_resolc.rs b/crates/compiler/src/revive_resolc.rs index bdb88af..e9e2bf3 100644 --- a/crates/compiler/src/revive_resolc.rs +++ b/crates/compiler/src/revive_resolc.rs @@ -47,6 +47,9 @@ impl SolidityCompiler for Resolc { base_path, sources, libraries, + // TODO: this is currently not being handled since there is no way to pass it into + // resolc. So, we need to go back to this later once it's supported. + revert_string_handling: _, }: CompilerInput, additional_options: Self::Options, ) -> anyhow::Result { diff --git a/crates/compiler/src/solc.rs b/crates/compiler/src/solc.rs index eafcb33..993bf0d 100644 --- a/crates/compiler/src/solc.rs +++ b/crates/compiler/src/solc.rs @@ -45,6 +45,7 @@ impl SolidityCompiler for Solc { base_path, sources, libraries, + revert_string_handling, }: CompilerInput, _: Self::Options, ) -> anyhow::Result { @@ -101,6 +102,15 @@ impl SolidityCompiler for Solc { }) .collect(), }, + debug: revert_string_handling.map(|revert_string_handling| DebuggingSettings { + revert_strings: match revert_string_handling { + crate::RevertString::Default => Some(RevertStrings::Default), + crate::RevertString::Debug => Some(RevertStrings::Debug), + crate::RevertString::Strip => Some(RevertStrings::Strip), + crate::RevertString::VerboseDebug => Some(RevertStrings::VerboseDebug), + }, + debug_info: Default::default(), + }), ..Default::default() }, }; diff --git a/crates/format/src/metadata.rs b/crates/format/src/metadata.rs index e327ab7..7089bb7 100644 --- a/crates/format/src/metadata.rs +++ b/crates/format/src/metadata.rs @@ -75,6 +75,12 @@ pub struct Metadata { /// be run of the evm version of the nodes match the evm version specified here. #[serde(skip_serializing_if = "Option::is_none")] pub required_evm_version: Option, + + /// A set of compilation directives that will be passed to the compiler whenever the contracts for + /// the test are being compiled. Note that this differs from the [`Mode`]s in that a [`Mode`] is + /// just a filter for when a test can run whereas this is an instruction to the compiler. + #[serde(skip_serializing_if = "Option::is_none")] + pub compiler_directives: Option, } impl Metadata { @@ -481,6 +487,31 @@ impl From for String { } } +/// A set of compilation directives that will be passed to the compiler whenever the contracts for +/// the test are being compiled. Note that this differs from the [`Mode`]s in that a [`Mode`] is +/// just a filter for when a test can run whereas this is an instruction to the compiler. +/// Defines how the compiler should handle revert strings. +#[derive( + Clone, Debug, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Serialize, Deserialize, +)] +pub struct CompilationDirectives { + /// Defines how the revert strings should be handled. + pub revert_string_handling: Option, +} + +/// Defines how the compiler should handle revert strings. +#[derive( + Clone, Debug, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Serialize, Deserialize, +)] +#[serde(rename_all = "camelCase")] +pub enum RevertString { + #[default] + Default, + Debug, + Strip, + VerboseDebug, +} + #[cfg(test)] mod test { use super::*;