-
Notifications
You must be signed in to change notification settings - Fork 795
Ignore SPDX and contract size for tests #775
Changes from 4 commits
0870288
650dbe0
74e4d5a
371afb9
b8c06db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -537,12 +537,17 @@ impl CompilerOutput { | |||
} | ||||
|
||||
/// Whether the output contains a compiler warning | ||||
pub fn has_warning(&self) -> bool { | ||||
self.errors.iter().any(|err| err.severity.is_warning()) | ||||
pub fn has_warning(&self, ignored_error_codes: &[u64]) -> bool { | ||||
self.errors.iter().any(|err| { | ||||
let is_ignored = | ||||
err.error_code.as_ref().map_or(false, |code| !ignored_error_codes.contains(code)); | ||||
|
||||
err.severity.is_warning() && !is_ignored | ||||
}) | ||||
} | ||||
|
||||
pub fn diagnostics<'a>(&'a self, ignored_error_codes: &'a [u64]) -> OutputDiagnostics { | ||||
OutputDiagnostics { errors: &self.errors, ignored_error_codes } | ||||
OutputDiagnostics { compiler_output: self, ignored_error_codes } | ||||
} | ||||
|
||||
/// Finds the _first_ contract with the given name | ||||
|
@@ -683,19 +688,29 @@ impl OutputContracts { | |||
/// Helper type to implement display for solc errors | ||||
#[derive(Clone, Debug)] | ||||
pub struct OutputDiagnostics<'a> { | ||||
errors: &'a [Error], | ||||
compiler_output: &'a CompilerOutput, | ||||
ignored_error_codes: &'a [u64], | ||||
} | ||||
|
||||
impl<'a> OutputDiagnostics<'a> { | ||||
/// Returns true if there is at least one error of high severity | ||||
pub fn has_error(&self) -> bool { | ||||
self.errors.iter().any(|err| err.severity.is_error()) | ||||
self.compiler_output.has_error() | ||||
} | ||||
|
||||
/// Returns true if there is at least one warning | ||||
pub fn has_warning(&self) -> bool { | ||||
self.errors.iter().any(|err| err.severity.is_warning()) | ||||
self.compiler_output.has_warning(self.ignored_error_codes) | ||||
} | ||||
|
||||
fn is_test<T: AsRef<str>>(&self, contract_path: T) -> bool { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure how robust this is and I couldn't really figure out a good way to do it for deps, should the test be "if it sits in node_modules or lib then it is a dependency"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm, one idea I have is to leave this completely up to the user, rn we're using it like this: ethers-rs/ethers-solc/src/lib.rs Line 864 in 371afb9
perhaps we can add something like filter: dyn ContractFilter
trait ContractFilter {
fn matches(&self, contract: &Contract) -> bool;
}
impl ContractFilter for () {
fn matches(&self) -> boo {true}
} then implement this for so we can add a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we could also do that for filtering of warnings in general, so instead of a contract filter etc. we just give the user
unless there is a specific reason we have this in ethers-solc as opposed to foundry? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sg, so we should map each error to its contract and ignore an error if:
|
||||
if contract_path.as_ref().ends_with(".t.sol") { | ||||
return true | ||||
} | ||||
|
||||
self.compiler_output.find(&contract_path).map_or(false, |contract| { | ||||
contract.abi.map_or(false, |abi| abi.functions.contains_key("IS_TEST")) | ||||
}) | ||||
} | ||||
} | ||||
|
||||
|
@@ -708,13 +723,21 @@ impl<'a> fmt::Display for OutputDiagnostics<'a> { | |||
} else { | ||||
f.write_str("Compiler run successful")?; | ||||
} | ||||
for err in self.errors { | ||||
// Do not log any ignored error codes | ||||
if let Some(error_code) = err.error_code { | ||||
if !self.ignored_error_codes.contains(&error_code) { | ||||
writeln!(f, "\n{}", err)?; | ||||
for err in &self.compiler_output.errors { | ||||
let is_ignored = err.error_code.as_ref().map_or(false, |code| { | ||||
if let Some(source_location) = &err.source_location { | ||||
// we ignore spdx and contract size warnings in test | ||||
// files. if we are looking at one of these warnings | ||||
// from a test file we skip | ||||
if self.is_test(&source_location.file) && (*code == 1878 || *code == 5574) { | ||||
return true | ||||
} | ||||
} | ||||
} else { | ||||
|
||||
self.ignored_error_codes.contains(code) | ||||
}); | ||||
|
||||
if !is_ignored { | ||||
writeln!(f, "\n{}", err)?; | ||||
} | ||||
} | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be more efficient to compute this only if
err.severity.is_warning() == true