Skip to content

Commit 98a7ce2

Browse files
committed
test: cover invalid LLVM IR and EraVM assembly in CLI
1 parent e8a3ae7 commit 98a7ce2

File tree

6 files changed

+101
-40
lines changed

6 files changed

+101
-40
lines changed

era-compiler-solidity/src/solc/standard_json/input/settings/libraries/mod.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,6 @@ impl Libraries {
5959
pub fn as_inner(&self) -> &BTreeMap<String, BTreeMap<String, String>> {
6060
&self.inner
6161
}
62-
63-
///
64-
/// Extracts the inner value.
65-
///
66-
pub fn into_inner(self) -> BTreeMap<String, BTreeMap<String, String>> {
67-
self.inner
68-
}
6962
}
7063

7164
impl From<BTreeMap<String, BTreeMap<String, String>>> for Libraries {

era-compiler-solidity/src/solc/standard_json/input/settings/selection/file/mod.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ pub mod flag;
66

77
use std::collections::HashSet;
88

9-
use crate::solc::standard_json::input::settings::codegen::Codegen as SolcStandardJsonInputSettingsCodegen;
10-
119
use self::flag::Flag as SelectionFlag;
1210

1311
///
@@ -46,25 +44,6 @@ impl File {
4644
}
4745
}
4846

49-
///
50-
/// Creates the selection required by EraVM compilation process.
51-
///
52-
pub fn new_required(codegen: SolcStandardJsonInputSettingsCodegen) -> Self {
53-
Self::new(vec![
54-
SelectionFlag::AST,
55-
SelectionFlag::MethodIdentifiers,
56-
SelectionFlag::Metadata,
57-
codegen.into(),
58-
])
59-
}
60-
61-
///
62-
/// Creates the selection required by Yul validation process.
63-
///
64-
pub fn new_yul_validation() -> Self {
65-
Self::new(vec![SelectionFlag::EVM])
66-
}
67-
6847
///
6948
/// Extends the output selection with another one.
7049
///

era-compiler-solidity/src/solc/standard_json/input/settings/selection/mod.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,19 @@ impl Selection {
3333
/// Creates the selection required by EraVM compilation process.
3434
///
3535
pub fn new_required(codegen: SolcStandardJsonInputSettingsCodegen) -> Self {
36-
Self {
37-
all: FileSelection::new_required(codegen),
38-
}
36+
Self::new(vec![
37+
SelectionFlag::AST,
38+
SelectionFlag::MethodIdentifiers,
39+
SelectionFlag::Metadata,
40+
codegen.into(),
41+
])
3942
}
4043

4144
///
4245
/// Creates the selection required by Yul validation process.
4346
///
4447
pub fn new_yul_validation() -> Self {
45-
Self {
46-
all: FileSelection::new_yul_validation(),
47-
}
48+
Self::new(vec![SelectionFlag::EVM])
4849
}
4950

5051
///

era-compiler-solidity/tests/cli/eravm_assembly.rs

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn with_eravm_assembly() -> anyhow::Result<()> {
1919
}
2020

2121
#[test]
22-
fn with_double_eravm_options() -> anyhow::Result<()> {
22+
fn with_eravm_assembly_duplicate_flag() -> anyhow::Result<()> {
2323
common::setup()?;
2424
let args = &[
2525
"--eravm-assembly",
@@ -36,7 +36,24 @@ fn with_double_eravm_options() -> anyhow::Result<()> {
3636
}
3737

3838
#[test]
39-
fn with_incompatible_input_format() -> anyhow::Result<()> {
39+
fn with_eravm_assembly_invalid() -> anyhow::Result<()> {
40+
common::setup()?;
41+
42+
let args = &[
43+
"--eravm-assembly",
44+
cli::TEST_ERAVM_ASSEMBLY_CONTRACT_INVALID_PATH,
45+
];
46+
47+
let result = cli::execute_zksolc(args)?;
48+
result
49+
.failure()
50+
.stderr(predicate::str::contains("error: cannot parse operand"));
51+
52+
Ok(())
53+
}
54+
55+
#[test]
56+
fn with_wrong_input_format() -> anyhow::Result<()> {
4057
common::setup()?;
4158
let args = &[
4259
"--eravm-assembly",
@@ -66,6 +83,41 @@ fn with_incompatible_input_format_without_output() -> anyhow::Result<()> {
6683
Ok(())
6784
}
6885

86+
#[test]
87+
fn with_incompatible_json_modes_combined_json() -> anyhow::Result<()> {
88+
common::setup()?;
89+
let args = &[
90+
cli::TEST_ERAVM_ASSEMBLY_CONTRACT_PATH,
91+
"--eravm-assembly",
92+
"--combined-json",
93+
"anyarg",
94+
];
95+
96+
let result = cli::execute_zksolc(args)?;
97+
result.failure().stderr(predicate::str::contains(
98+
"Only one mode is allowed at the same time",
99+
));
100+
101+
Ok(())
102+
}
103+
104+
#[test]
105+
fn with_incompatible_json_modes_standard_json() -> anyhow::Result<()> {
106+
common::setup()?;
107+
let args = &[
108+
cli::TEST_ERAVM_ASSEMBLY_CONTRACT_PATH,
109+
"--eravm-assembly",
110+
"--standard-json",
111+
];
112+
113+
let result = cli::execute_zksolc(args)?;
114+
result.success().stdout(predicate::str::contains(
115+
"Only one mode is allowed at the same time",
116+
));
117+
118+
Ok(())
119+
}
120+
69121
#[test]
70122
fn with_incompatible_json_modes() -> anyhow::Result<()> {
71123
common::setup()?;

era-compiler-solidity/tests/cli/llvm_ir.rs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@ use predicates::prelude::*;
55
fn with_llvm_ir() -> anyhow::Result<()> {
66
common::setup()?;
77
let args = &[cli::TEST_LLVM_IR_CONTRACT_PATH, "--llvm-ir"];
8-
let invalid_args = &["--llvm-ir", "anyarg"];
98

109
let result = cli::execute_zksolc(args)?;
11-
let invalid_result = cli::execute_zksolc(invalid_args)?;
1210

1311
result.success().stderr(predicate::str::contains(
1412
"Compiler run successful. No output requested.",
1513
));
16-
invalid_result.failure();
1714

1815
Ok(())
1916
}
@@ -31,6 +28,20 @@ fn with_llvm_ir_duplicate_flag() -> anyhow::Result<()> {
3128
Ok(())
3229
}
3330

31+
#[test]
32+
fn with_llvm_ir_invalid() -> anyhow::Result<()> {
33+
common::setup()?;
34+
35+
let args = &["--llvm-ir", cli::TEST_LLVM_IR_CONTRACT_INVALID_PATH];
36+
37+
let result = cli::execute_zksolc(args)?;
38+
result.failure().stderr(predicate::str::contains(
39+
"error: use of undefined value \'%runtime\'",
40+
));
41+
42+
Ok(())
43+
}
44+
3445
#[test]
3546
fn with_wrong_input_format() -> anyhow::Result<()> {
3647
common::setup()?;
@@ -44,6 +55,20 @@ fn with_wrong_input_format() -> anyhow::Result<()> {
4455
Ok(())
4556
}
4657

58+
#[test]
59+
fn with_incompatible_input_format_without_output() -> anyhow::Result<()> {
60+
common::setup()?;
61+
62+
let args = &["--eravm-assembly", cli::TEST_BROKEN_INPUT_PATH];
63+
64+
let result = cli::execute_zksolc(args)?;
65+
result
66+
.failure()
67+
.stderr(predicate::str::contains("error: cannot parse operand"));
68+
69+
Ok(())
70+
}
71+
4772
#[test]
4873
fn with_incompatible_json_modes_combined_json() -> anyhow::Result<()> {
4974
common::setup()?;
@@ -65,7 +90,11 @@ fn with_incompatible_json_modes_combined_json() -> anyhow::Result<()> {
6590
#[test]
6691
fn with_incompatible_json_modes_standard_json() -> anyhow::Result<()> {
6792
common::setup()?;
68-
let args = &[cli::TEST_YUL_CONTRACT_PATH, "--llvm-ir", "--standard-json"];
93+
let args = &[
94+
cli::TEST_LLVM_IR_CONTRACT_PATH,
95+
"--llvm-ir",
96+
"--standard-json",
97+
];
6998

7099
let result = cli::execute_zksolc(args)?;
71100
result.success().stdout(predicate::str::contains(

era-compiler-solidity/tests/cli/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,16 @@ pub const TEST_YUL_CONTRACT_PATH: &str = "tests/data/contracts/yul/Default.yul";
7070
/// A test input file.
7171
pub const TEST_LLVM_IR_CONTRACT_PATH: &str = "tests/data/contracts/llvm_ir/Test.ll";
7272

73+
/// A test input file.
74+
pub const TEST_LLVM_IR_CONTRACT_INVALID_PATH: &str = "tests/data/contracts/llvm_ir/Invalid.ll";
75+
7376
/// A test input file.
7477
pub const TEST_ERAVM_ASSEMBLY_CONTRACT_PATH: &str = "tests/data/contracts/eravm_assembly/Test.zasm";
7578

79+
/// A test input file.
80+
pub const TEST_ERAVM_ASSEMBLY_CONTRACT_INVALID_PATH: &str =
81+
"tests/data/contracts/eravm_assembly/Invalid.zasm";
82+
7683
/// A test input file.
7784
pub const TEST_SOLIDITY_STANDARD_JSON_NON_EXISTENT_PATH: &str =
7885
"tests/data/standard_json_input/non_existent.json";

0 commit comments

Comments
 (0)