Skip to content

Commit

Permalink
add a unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
hedgar2017 committed Sep 6, 2024
1 parent 9b02780 commit eabea49
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 10 deletions.
18 changes: 9 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion era-compiler-solidity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ num = "0.4"
sha3 = "0.10"

era-compiler-common = { git = "https://github.com/matter-labs/era-compiler-common", branch = "main" }
era-compiler-llvm-context = { git = "https://github.com/matter-labs/era-compiler-llvm-context", branch = "az-cpr-1727-implement-the-ipfs-hash-algorithm" }
era-compiler-llvm-context = { git = "https://github.com/matter-labs/era-compiler-llvm-context", branch = "main" }
era-yul = { path = "../era-yul" }

[dev-dependencies]
Expand Down
54 changes: 54 additions & 0 deletions era-compiler-solidity/tests/cli/output_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,60 @@ fn run_zksolc_with_output_dir_by_default() -> anyhow::Result<()> {
Ok(())
}

#[test]
fn run_zksolc_with_output_dir_with_asm_and_metadata() -> anyhow::Result<()> {
let _ = common::setup();
let tmp_dir_zksolc = TempDir::with_prefix("zksolc_output")?;
let tmp_dir_solc = TempDir::with_prefix("solc_output")?;

let mut asm_path = tmp_dir_zksolc.path().to_path_buf();
asm_path.push("contract.sol");
asm_path.push("C.zasm");
let mut metadata_path = tmp_dir_zksolc.path().to_path_buf();
metadata_path.push("contract.sol");
metadata_path.push("C_meta.json");

let zksolc_args = &[
cli::TEST_SOLIDITY_CONTRACT_PATH,
"--bin",
"--asm",
"--metadata",
"--output-dir",
tmp_dir_zksolc.path().to_str().unwrap(),
];
let solc_args = &[
cli::TEST_SOLIDITY_CONTRACT_PATH,
"--bin",
"--asm",
"--metadata",
"--output-dir",
tmp_dir_solc.path().to_str().unwrap(),
];

// Execute zksolc command
let result = cli::execute_zksolc(zksolc_args)?;
let zksolc_status = result
.success()
.stderr(predicate::str::contains("Compiler run successful"))
.get_output()
.status
.code()
.expect("No exit code.");

// Ensure the directory is created
assert!(tmp_dir_zksolc.path().exists());

// Ensure the assembly and metadata file exist
assert!(asm_path.exists());
assert!(metadata_path.exists());

// Compare with solc
let solc_result = cli::execute_solc(solc_args)?;
solc_result.code(zksolc_status);

Ok(())
}

#[test]
fn run_zksolc_with_output_dir_invalid_arg_no_path() -> anyhow::Result<()> {
let _ = common::setup();
Expand Down

0 comments on commit eabea49

Please sign in to comment.