Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more test in report/compiler.rs and Default trait for CompilerInput #19

Merged
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
39 changes: 39 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,40 @@ 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();
}
}
Loading