Skip to content

Commit

Permalink
more test in report/compiler.rs and Default trait for CompilerInput (#19
Browse files Browse the repository at this point in the history
)

* Update mod.rs

* Update compiler.rs

* Update compiler.rs

* Update mod.rs

* Update compiler.rs

* chore: clippy/fmt

---------

Co-authored-by: Enrique Ortiz <[email protected]>
  • Loading branch information
DoTheBestToGetTheBest and Evalir authored Nov 10, 2023
1 parent b7573c6 commit 0fc9af7
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/artifacts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ pub(crate) type VersionedFilteredSources = BTreeMap<Solc, (Version, FilteredSour
const SOLIDITY: &str = "Solidity";
const YUL: &str = "Yul";

///
/// Default `language` field is set to `"SOLIDITY"`.
/// This indicates the language used for the compiler input is Solidity.
impl Default for CompilerInput {
fn default() -> Self {
CompilerInput {
language: "SOLIDITY".to_string(),
sources: Sources::default(),
settings: Settings::default(),
}
}
}
/// Input type `solc` expects
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct CompilerInput {
Expand Down
37 changes: 37 additions & 0 deletions src/report/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ fn get_file_name(path: impl Into<PathBuf>, v: &Version) -> PathBuf {
#[cfg(test)]
mod tests {
use super::*;
use semver::Version;
use std::fs;
use tempfile::tempdir;

#[test]
fn can_set_file_name() {
Expand Down Expand Up @@ -208,4 +211,38 @@ mod tests {
);
std::env::remove_var("foundry_compilers_LOG");
}

#[test]
fn check_no_write_when_no_target() {
let reporter = SolcCompilerIoReporter::default();
let version = Version::parse("0.8.10").unwrap();
let input = CompilerInput::default();
let output = CompilerOutput::default();

reporter.log_compiler_input(&input, &version);
reporter.log_compiler_output(&output, &version);
}

#[test]
fn serialize_and_write_to_file() {
let dir = tempdir().unwrap();
let input_path = dir.path().join("input.json");
let output_path = dir.path().join("output.json");
let version = Version::parse("0.8.10").unwrap();
let target = Target { dest_input: input_path.clone(), dest_output: output_path.clone() };

let input = CompilerInput::default();
let output = CompilerOutput::default();

target.write_input(&input, &version);
target.write_output(&output, &version);

let input_content = fs::read_to_string(get_file_name(&input_path, &version)).unwrap();
let output_content = fs::read_to_string(get_file_name(&output_path, &version)).unwrap();

assert!(!input_content.is_empty());
assert!(!output_content.is_empty());

dir.close().unwrap();
}
}

0 comments on commit 0fc9af7

Please sign in to comment.