Skip to content

Commit

Permalink
cover the executable part
Browse files Browse the repository at this point in the history
  • Loading branch information
hedgar2017 committed Dec 17, 2024
1 parent e6ba663 commit b6f884e
Show file tree
Hide file tree
Showing 10 changed files with 242 additions and 24 deletions.
34 changes: 17 additions & 17 deletions Cargo.lock

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

35 changes: 35 additions & 0 deletions tests/cli/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,38 @@ fn default() -> anyhow::Result<()> {

Ok(())
}

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

let args = &[];

let result = common::execute_zkvyper(args)?;
result
.failure()
.stderr(predicate::str::contains("No input files provided."));

let vyper_result = common::execute_vyper(args)?;
vyper_result.code(2);

Ok(())
}

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

let args = &[
common::TEST_GREETER_CONTRACT_PATH,
"--llvm-ir",
"--eravm-assembly",
];

let result = common::execute_zkvyper(args)?;
result.failure().stderr(predicate::str::contains(
"Only one mode is allowed at the same time: format, LLVM IR, EraVM assembly, disassembler.",
));

Ok(())
}
60 changes: 60 additions & 0 deletions tests/cli/evm_version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
use predicates::prelude::*;

use crate::common;

#[test]
fn default() -> anyhow::Result<()> {
common::setup()?;

let evm_version = era_compiler_common::EVMVersion::Cancun.to_string();
let args = &[
"--evm-version",
evm_version.as_str(),
common::TEST_GREETER_CONTRACT_PATH,
];

let result = common::execute_zkvyper(args)?;
result.success().stdout(predicate::str::contains("0x"));

Ok(())
}

#[test]
fn llvm_ir_mode() -> anyhow::Result<()> {
common::setup()?;

let evm_version = era_compiler_common::EVMVersion::Cancun.to_string();
let args = &[
"--evm-version",
evm_version.as_str(),
"--llvm-ir",
common::TEST_GREETER_CONTRACT_PATH,
];

let result = common::execute_zkvyper(args)?;
result.failure().stderr(predicate::str::contains(
"EVM version is not used in LLVM IR and EraVM assembly modes.",
));

Ok(())
}

#[test]
fn eravm_assembly_mode() -> anyhow::Result<()> {
common::setup()?;

let evm_version = era_compiler_common::EVMVersion::Cancun.to_string();
let args = &[
"--evm-version",
evm_version.as_str(),
"--eravm-assembly",
common::TEST_GREETER_CONTRACT_PATH,
];

let result = common::execute_zkvyper(args)?;
result.failure().stderr(predicate::str::contains(
"EVM version is not used in LLVM IR and EraVM assembly modes.",
));

Ok(())
}
18 changes: 18 additions & 0 deletions tests/cli/fallback_oz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,21 @@ fn default() -> anyhow::Result<()> {

Ok(())
}

#[test]
fn eravm_assembly_mode() -> anyhow::Result<()> {
common::setup()?;

let args = &[
"--fallback-Oz",
"--eravm-assembly",
common::TEST_GREETER_CONTRACT_PATH,
];

let result = common::execute_zkvyper(args)?;
result.failure().stderr(predicate::str::contains(
"Falling back to -Oz is not supported in EraVM assembly mode.",
));

Ok(())
}
18 changes: 18 additions & 0 deletions tests/cli/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,21 @@ fn unsupported_selector() -> anyhow::Result<()> {

Ok(())
}

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

let args = &[
common::TEST_GREETER_CONTRACT_PATH,
"-f",
"combined_json,ast",
];

let result = common::execute_zkvyper(args)?;
result.failure().stderr(predicate::str::contains(
"`combined_json` cannot be requested together with other output",
));

Ok(())
}
9 changes: 2 additions & 7 deletions tests/cli/metadata_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,11 @@ use crate::common;
fn default(hash_type: HashType) -> anyhow::Result<()> {
let _ = common::setup();

let hash_type = match hash_type {
HashType::None => "none",
HashType::Keccak256 => "keccak256",
HashType::Ipfs => "ipfs",
};

let hash_type = hash_type.to_string();
let args = &[
common::TEST_GREETER_CONTRACT_PATH,
"--metadata-hash",
hash_type,
hash_type.as_str(),
];

let result = common::execute_zkvyper(args)?;
Expand Down
2 changes: 2 additions & 0 deletions tests/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod debug_output_dir;
mod disable_vyper_optimizer;
mod disassemble;
mod eravm_assembly;
mod evm_version;
mod fallback_oz;
mod format;
mod llvm_debug_logging;
Expand All @@ -17,6 +18,7 @@ mod metadata_hash;
mod optimization;
mod output_dir;
mod overwrite;
mod recursive_process;
mod search_paths;
mod suppress;
mod threads;
Expand Down
19 changes: 19 additions & 0 deletions tests/cli/optimization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,22 @@ fn default(level: char) -> anyhow::Result<()> {

Ok(())
}

#[test]
fn eravm_assembly_mode() -> anyhow::Result<()> {
common::setup()?;

let args = &[
"--optimization",
"3",
"--eravm-assembly",
common::TEST_GREETER_CONTRACT_PATH,
];

let result = common::execute_zkvyper(args)?;
result.failure().stderr(predicate::str::contains(
"LLVM optimizations are not supported in EraVM assembly mode.",
));

Ok(())
}
31 changes: 31 additions & 0 deletions tests/cli/recursive_process.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use predicates::prelude::*;

use crate::common;

#[test]
fn default() -> anyhow::Result<()> {
common::setup()?;

let args = &["--recursive-process"];

let result = common::execute_zkvyper(args)?;
result
.failure()
.stderr(predicate::str::contains("Stdin reading error"));

Ok(())
}

#[test]
fn excess_args() -> anyhow::Result<()> {
common::setup()?;

let args = &["--recursive-process", common::TEST_GREETER_CONTRACT_PATH];

let result = common::execute_zkvyper(args)?;
result.failure().stderr(predicate::str::contains(
"No other options are allowed in recursive mode.",
));

Ok(())
}
40 changes: 40 additions & 0 deletions tests/cli/vyper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,43 @@ fn invalid_path() -> anyhow::Result<()> {

Ok(())
}

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

let vyper = common::get_vyper_compiler(&semver::Version::new(0, 4, 0))?.executable;
let args = &[
"--vyper",
vyper.as_str(),
"--llvm-ir",
common::TEST_GREETER_CONTRACT_PATH,
];

let result = common::execute_zkvyper(args)?;
result.failure().stderr(predicate::str::contains(
"`vyper` is not used in LLVM IR and EraVM assembly modes.",
));

Ok(())
}

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

let vyper = common::get_vyper_compiler(&semver::Version::new(0, 4, 0))?.executable;
let args = &[
"--vyper",
vyper.as_str(),
"--eravm-assembly",
common::TEST_GREETER_CONTRACT_PATH,
];

let result = common::execute_zkvyper(args)?;
result.failure().stderr(predicate::str::contains(
"`vyper` is not used in LLVM IR and EraVM assembly modes.",
));

Ok(())
}

0 comments on commit b6f884e

Please sign in to comment.