From 941ec2ee5cec60aca9c1efd84d0eb2ad4531cefb Mon Sep 17 00:00:00 2001 From: DoTheBestToGetTheBest <146037313+DoTheBestToGetTheBest@users.noreply.github.com> Date: Tue, 7 Nov 2023 14:05:29 -0800 Subject: [PATCH 1/6] Update mod.rs --- src/artifacts/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/artifacts/mod.rs b/src/artifacts/mod.rs index 53bc4504..b6848d96 100644 --- a/src/artifacts/mod.rs +++ b/src/artifacts/mod.rs @@ -54,7 +54,7 @@ const SOLIDITY: &str = "Solidity"; const YUL: &str = "Yul"; /// Input type `solc` expects -#[derive(Clone, Debug, Serialize, Deserialize)] +#[derive(Clone, Debug, Serialize, Deserialize, Default)] pub struct CompilerInput { pub language: String, pub sources: Sources, From e8152fc76d2e175a692c06b6642d340f4ee28fa5 Mon Sep 17 00:00:00 2001 From: DoTheBestToGetTheBest <146037313+DoTheBestToGetTheBest@users.noreply.github.com> Date: Tue, 7 Nov 2023 14:06:08 -0800 Subject: [PATCH 2/6] Update compiler.rs --- src/report/compiler.rs | 50 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/report/compiler.rs b/src/report/compiler.rs index 4b2f9c60..136c4a44 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,51 @@ mod tests { ); std::env::remove_var("foundry_compilers_LOG"); } + + #[test] + fn fails_on_invalid_format() { + let result: Result = "invalid_format".parse(); + assert!(result.is_err()); + } + #[test] + fn fails_on_bad_name() { + let result: Result = "bad=in.json".parse(); + assert!(result.is_err()); + if let Err(e) = result { + assert_eq!(e.to_string(), "bad"); + } + } + #[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(); + } } From c9017eec89c066958175601f59d1de6917fc3c3f Mon Sep 17 00:00:00 2001 From: DoTheBestToGetTheBest <146037313+DoTheBestToGetTheBest@users.noreply.github.com> Date: Fri, 10 Nov 2023 05:50:30 -0800 Subject: [PATCH 3/6] Update compiler.rs --- src/report/compiler.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/report/compiler.rs b/src/report/compiler.rs index 136c4a44..4f69131d 100644 --- a/src/report/compiler.rs +++ b/src/report/compiler.rs @@ -217,14 +217,16 @@ mod tests { let result: Result = "invalid_format".parse(); assert!(result.is_err()); } + #[test] fn fails_on_bad_name() { let result: Result = "bad=in.json".parse(); assert!(result.is_err()); if let Err(e) = result { - assert_eq!(e.to_string(), "bad"); + assert_eq!(e.to_string(), "bad=in.json"); } } + #[test] fn check_no_write_when_no_target() { let reporter = SolcCompilerIoReporter::default(); From 1a4759abad331821a91d4cb02b2a06c0b09dcabf Mon Sep 17 00:00:00 2001 From: DoTheBestToGetTheBest <146037313+DoTheBestToGetTheBest@users.noreply.github.com> Date: Fri, 10 Nov 2023 06:27:38 -0800 Subject: [PATCH 4/6] Update mod.rs --- src/artifacts/mod.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/artifacts/mod.rs b/src/artifacts/mod.rs index b6848d96..0755acce 100644 --- a/src/artifacts/mod.rs +++ b/src/artifacts/mod.rs @@ -53,8 +53,20 @@ 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, Default)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct CompilerInput { pub language: String, pub sources: Sources, From af117dc5a48aeba839a9f5379159da89288d96b4 Mon Sep 17 00:00:00 2001 From: DoTheBestToGetTheBest <146037313+DoTheBestToGetTheBest@users.noreply.github.com> Date: Fri, 10 Nov 2023 07:45:56 -0800 Subject: [PATCH 5/6] Update compiler.rs --- src/report/compiler.rs | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/src/report/compiler.rs b/src/report/compiler.rs index 4f69131d..2a15e9db 100644 --- a/src/report/compiler.rs +++ b/src/report/compiler.rs @@ -212,20 +212,7 @@ mod tests { std::env::remove_var("foundry_compilers_LOG"); } - #[test] - fn fails_on_invalid_format() { - let result: Result = "invalid_format".parse(); - assert!(result.is_err()); - } - - #[test] - fn fails_on_bad_name() { - let result: Result = "bad=in.json".parse(); - assert!(result.is_err()); - if let Err(e) = result { - assert_eq!(e.to_string(), "bad=in.json"); - } - } + #[test] fn check_no_write_when_no_target() { From 60ec90d3d6153d50bc9948e9e3ca974ce0d7411c Mon Sep 17 00:00:00 2001 From: Enrique Ortiz Date: Fri, 10 Nov 2023 12:05:20 -0400 Subject: [PATCH 6/6] chore: clippy/fmt --- src/report/compiler.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/report/compiler.rs b/src/report/compiler.rs index 2a15e9db..7169f30f 100644 --- a/src/report/compiler.rs +++ b/src/report/compiler.rs @@ -212,8 +212,6 @@ mod tests { std::env::remove_var("foundry_compilers_LOG"); } - - #[test] fn check_no_write_when_no_target() { let reporter = SolcCompilerIoReporter::default();