From 0fc9af798b0eb92290796ec078b6e29f1e1fb844 Mon Sep 17 00:00:00 2001 From: DoTheBestToGetTheBest <146037313+DoTheBestToGetTheBest@users.noreply.github.com> Date: Fri, 10 Nov 2023 08:33:41 -0800 Subject: [PATCH] more test in report/compiler.rs and Default trait for CompilerInput (#19) * Update mod.rs * Update compiler.rs * Update compiler.rs * Update mod.rs * Update compiler.rs * chore: clippy/fmt --------- Co-authored-by: Enrique Ortiz --- src/artifacts/mod.rs | 12 ++++++++++++ src/report/compiler.rs | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/src/artifacts/mod.rs b/src/artifacts/mod.rs index 53bc4504..0755acce 100644 --- a/src/artifacts/mod.rs +++ b/src/artifacts/mod.rs @@ -53,6 +53,18 @@ pub(crate) type VersionedFilteredSources = BTreeMap Self { + CompilerInput { + language: "SOLIDITY".to_string(), + sources: Sources::default(), + settings: Settings::default(), + } + } +} /// Input type `solc` expects #[derive(Clone, Debug, Serialize, Deserialize)] pub struct CompilerInput { diff --git a/src/report/compiler.rs b/src/report/compiler.rs index 4b2f9c60..7169f30f 100644 --- a/src/report/compiler.rs +++ b/src/report/compiler.rs @@ -171,6 +171,9 @@ fn get_file_name(path: impl Into, v: &Version) -> PathBuf { #[cfg(test)] mod tests { use super::*; + use semver::Version; + use std::fs; + use tempfile::tempdir; #[test] fn can_set_file_name() { @@ -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(); + } }