Skip to content

Commit 3f10e64

Browse files
committed
fix tests for internal function pointers
1 parent a94a22b commit 3f10e64

23 files changed

+317
-136
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@
2222
*.bak
2323

2424
# Test solc versions
25-
solc-bin/
25+
**/solc-bin/
26+
**/solc-bin-upstream/

era-compiler-solidity/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,7 @@ pub fn standard_json_eravm(
436436
let output_assembly = solc_input
437437
.settings
438438
.output_selection
439-
.as_ref()
440-
.map(|selection| selection.contains_eravm_assembly())
441-
.unwrap_or_default();
439+
.contains_eravm_assembly();
442440

443441
let (mut solc_output, solc_version, project) = match (language, solc_compiler) {
444442
(SolcStandardJsonInputLanguage::Solidity, solc_compiler) => {

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

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ pub struct Settings {
4040
#[serde(skip_serializing_if = "Option::is_none")]
4141
pub evm_version: Option<era_compiler_common::EVMVersion>,
4242
/// The output selection filters.
43-
#[serde(skip_serializing_if = "Option::is_none")]
44-
pub output_selection: Option<Selection>,
43+
#[serde(default)]
44+
pub output_selection: Selection,
4545
/// The metadata settings.
4646
#[serde(default)]
4747
pub metadata: Metadata,
@@ -114,7 +114,7 @@ impl Settings {
114114
force_evmla: codegen == Some(SolcCodegen::EVMLA),
115115
enable_eravm_extensions,
116116

117-
output_selection: Some(output_selection),
117+
output_selection,
118118
metadata,
119119
llvm_options,
120120
suppressed_errors,
@@ -129,18 +129,14 @@ impl Settings {
129129
/// Sets the necessary defaults for EraVM compilation.
130130
///
131131
pub fn normalize(&mut self, codegen: Option<SolcCodegen>) {
132-
self.output_selection
133-
.get_or_insert_with(Selection::default)
134-
.extend_with_required(codegen);
132+
self.output_selection.extend_with_required(codegen);
135133
}
136134

137135
///
138136
/// Sets the necessary defaults for Yul validation.
139137
///
140138
pub fn normalize_yul_validation(&mut self) {
141-
self.output_selection
142-
.get_or_insert_with(Selection::new_yul_validation)
143-
.extend_with_yul_validation();
139+
self.output_selection.extend_with_yul_validation();
144140
}
145141

146142
///
@@ -150,9 +146,6 @@ impl Settings {
150146
/// Afterwards, the flags are used to prune JSON output before returning it.
151147
///
152148
pub fn get_unset_required(&self) -> HashSet<SelectionFlag> {
153-
self.output_selection
154-
.as_ref()
155-
.map(|selection| selection.get_unset_required())
156-
.unwrap_or_else(|| Selection::default().get_unset_required())
149+
self.output_selection.get_unset_required()
157150
}
158151
}

era-compiler-solidity/src/solc/standard_json/output/contract/eravm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
///
66
/// The `solc --standard-json` output contract EraVM data.
77
///
8-
#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
8+
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
99
#[serde(rename_all = "camelCase")]
1010
pub struct EraVM {
1111
/// The contract bytecode.

era-compiler-solidity/src/solc/standard_json/output/contract/evm/extra_metadata/mod.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,21 @@ impl ExtraMetadata {
2828
for function in self.recursive_functions.iter() {
2929
match block_key.code_type {
3030
era_compiler_llvm_context::CodeType::Deploy => {
31-
if let Some(creation_tag) = function.creation_tag {
32-
if num::BigUint::from(creation_tag) == block_key.tag {
33-
return Some(function);
34-
}
31+
if function
32+
.creation_tag
33+
.map(|creation_tag| num::BigUint::from(creation_tag) == block_key.tag)
34+
.unwrap_or_default()
35+
{
36+
return Some(function);
3537
}
3638
}
3739
era_compiler_llvm_context::CodeType::Runtime => {
38-
if let Some(runtime_tag) = function.runtime_tag {
39-
if num::BigUint::from(runtime_tag) == block_key.tag {
40-
return Some(function);
41-
}
40+
if function
41+
.runtime_tag
42+
.map(|runtime_tag| num::BigUint::from(runtime_tag) == block_key.tag)
43+
.unwrap_or_default()
44+
{
45+
return Some(function);
4246
}
4347
}
4448
}

era-compiler-solidity/src/solc/standard_json/output/error/source_location.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,3 @@ impl SourceLocation {
6767
))
6868
}
6969
}
70-
71-
impl std::fmt::Display for SourceLocation {
72-
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
73-
write!(f, "{}", self.file)?;
74-
if self.start > 0 {
75-
write!(f, ":{}", self.start)?;
76-
if self.end > 0 {
77-
write!(f, ":{}", self.end)?;
78-
}
79-
}
80-
Ok(())
81-
}
82-
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ pub const TEST_SOLIDITY_STANDARD_JSON_SOLC_INVALID_PATH: &str =
101101
pub const TEST_SOLIDITY_STANDARD_JSON_ZKSOLC_RECURSION_PATH: &str =
102102
"tests/data/standard_json_input/solidity_zksolc_recursion.json";
103103

104+
/// A test input file.
105+
pub const TEST_SOLIDITY_STANDARD_JSON_ZKSOLC_INTERNAL_FUNCTION_POINTERS_PATH: &str =
106+
"tests/data/standard_json_input/solidity_zksolc_internal_function_pointers.json";
107+
104108
/// A test input file.
105109
pub const TEST_SOLIDITY_STANDARD_JSON_ZKSOLC_INVALID_PATH: &str =
106110
"tests/data/standard_json_input/solidity_zksolc_invalid.json";
@@ -247,6 +251,7 @@ pub fn execute_zksolc_with_target(
247251
pub fn execute_solc(args: &[&str]) -> anyhow::Result<assert_cmd::assert::Assert> {
248252
let solc_compiler = crate::common::get_solc_compiler(
249253
&era_compiler_solidity::SolcCompiler::LAST_SUPPORTED_VERSION,
254+
false,
250255
)?
251256
.executable;
252257
let mut cmd = Command::new(solc_compiler);

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

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ fn with_solc() -> anyhow::Result<()> {
88
common::setup()?;
99

1010
let mut zksolc = Command::cargo_bin(era_compiler_solidity::DEFAULT_EXECUTABLE_NAME)?;
11-
let solc_compiler =
12-
common::get_solc_compiler(&era_compiler_solidity::SolcCompiler::LAST_SUPPORTED_VERSION)?
13-
.executable;
11+
let solc_compiler = common::get_solc_compiler(
12+
&era_compiler_solidity::SolcCompiler::LAST_SUPPORTED_VERSION,
13+
false,
14+
)?
15+
.executable;
1416

1517
let assert = zksolc
1618
.arg(cli::TEST_SOLIDITY_CONTRACT_PATH)
@@ -48,9 +50,11 @@ fn with_solc_standard_json_mode() -> anyhow::Result<()> {
4850
common::setup()?;
4951

5052
let mut zksolc = Command::cargo_bin(era_compiler_solidity::DEFAULT_EXECUTABLE_NAME)?;
51-
let solc_compiler =
52-
common::get_solc_compiler(&era_compiler_solidity::SolcCompiler::LAST_SUPPORTED_VERSION)?
53-
.executable;
53+
let solc_compiler = common::get_solc_compiler(
54+
&era_compiler_solidity::SolcCompiler::LAST_SUPPORTED_VERSION,
55+
false,
56+
)?
57+
.executable;
5458

5559
let assert = zksolc
5660
.arg("--solc")
@@ -88,9 +92,11 @@ fn without_solc_standard_json_mode() -> anyhow::Result<()> {
8892
fn with_solc_llvm_ir_mode() -> anyhow::Result<()> {
8993
common::setup()?;
9094

91-
let solc_compiler =
92-
common::get_solc_compiler(&era_compiler_solidity::SolcCompiler::LAST_SUPPORTED_VERSION)?
93-
.executable;
95+
let solc_compiler = common::get_solc_compiler(
96+
&era_compiler_solidity::SolcCompiler::LAST_SUPPORTED_VERSION,
97+
false,
98+
)?
99+
.executable;
94100

95101
let args = &[
96102
"--solc",
@@ -112,9 +118,11 @@ fn with_solc_llvm_ir_mode() -> anyhow::Result<()> {
112118
fn with_solc_eravm_assembly_mode() -> anyhow::Result<()> {
113119
common::setup()?;
114120

115-
let solc_compiler =
116-
common::get_solc_compiler(&era_compiler_solidity::SolcCompiler::LAST_SUPPORTED_VERSION)?
117-
.executable;
121+
let solc_compiler = common::get_solc_compiler(
122+
&era_compiler_solidity::SolcCompiler::LAST_SUPPORTED_VERSION,
123+
false,
124+
)?
125+
.executable;
118126

119127
let args = &[
120128
"--solc",

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

Lines changed: 52 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ use predicates::prelude::*;
55
fn with_standard_json() -> anyhow::Result<()> {
66
common::setup()?;
77

8-
let solc_compiler =
9-
common::get_solc_compiler(&era_compiler_solidity::SolcCompiler::LAST_SUPPORTED_VERSION)?
10-
.executable;
8+
let solc_compiler = common::get_solc_compiler(
9+
&era_compiler_solidity::SolcCompiler::LAST_SUPPORTED_VERSION,
10+
false,
11+
)?
12+
.executable;
1113

1214
let args = &[
1315
"--solc",
@@ -60,9 +62,11 @@ fn with_standard_json_incompatible_input() -> anyhow::Result<()> {
6062
fn with_standard_json_invalid_by_solc() -> anyhow::Result<()> {
6163
common::setup()?;
6264

63-
let solc_compiler =
64-
common::get_solc_compiler(&era_compiler_solidity::SolcCompiler::LAST_SUPPORTED_VERSION)?
65-
.executable;
65+
let solc_compiler = common::get_solc_compiler(
66+
&era_compiler_solidity::SolcCompiler::LAST_SUPPORTED_VERSION,
67+
false,
68+
)?
69+
.executable;
6670

6771
let args = &[
6872
"--solc",
@@ -96,9 +100,11 @@ fn with_standard_json_invalid_by_solc() -> anyhow::Result<()> {
96100
fn with_standard_json_invalid_by_zksolc() -> anyhow::Result<()> {
97101
common::setup()?;
98102

99-
let solc_compiler =
100-
common::get_solc_compiler(&era_compiler_solidity::SolcCompiler::LAST_SUPPORTED_VERSION)?
101-
.executable;
103+
let solc_compiler = common::get_solc_compiler(
104+
&era_compiler_solidity::SolcCompiler::LAST_SUPPORTED_VERSION,
105+
false,
106+
)?
107+
.executable;
102108

103109
let args = &[
104110
"--solc",
@@ -126,9 +132,11 @@ fn with_standard_json_invalid_by_zksolc() -> anyhow::Result<()> {
126132
fn with_standard_json_with_suppressed_messages() -> anyhow::Result<()> {
127133
common::setup()?;
128134

129-
let solc_compiler =
130-
common::get_solc_compiler(&era_compiler_solidity::SolcCompiler::LAST_SUPPORTED_VERSION)?
131-
.executable;
135+
let solc_compiler = common::get_solc_compiler(
136+
&era_compiler_solidity::SolcCompiler::LAST_SUPPORTED_VERSION,
137+
false,
138+
)?
139+
.executable;
132140

133141
let args = &[
134142
"--solc",
@@ -173,6 +181,23 @@ fn with_standard_json_recursion() -> anyhow::Result<()> {
173181
Ok(())
174182
}
175183

184+
#[test]
185+
fn with_standard_json_internal_function_pointers() -> anyhow::Result<()> {
186+
common::setup()?;
187+
188+
let args = &[
189+
"--standard-json",
190+
cli::TEST_SOLIDITY_STANDARD_JSON_ZKSOLC_INTERNAL_FUNCTION_POINTERS_PATH,
191+
];
192+
193+
let result = cli::execute_zksolc(args)?;
194+
result
195+
.success()
196+
.stdout(predicate::str::contains("bytecode"));
197+
198+
Ok(())
199+
}
200+
176201
#[test]
177202
fn with_standard_json_non_existent() -> anyhow::Result<()> {
178203
common::setup()?;
@@ -398,9 +423,11 @@ fn with_standard_json_neither_urls_nor_content() -> anyhow::Result<()> {
398423
fn with_standard_json_yul_with_solc() -> anyhow::Result<()> {
399424
common::setup()?;
400425

401-
let solc_compiler =
402-
common::get_solc_compiler(&era_compiler_solidity::SolcCompiler::LAST_SUPPORTED_VERSION)?
403-
.executable;
426+
let solc_compiler = common::get_solc_compiler(
427+
&era_compiler_solidity::SolcCompiler::LAST_SUPPORTED_VERSION,
428+
false,
429+
)?
430+
.executable;
404431

405432
let args = &[
406433
"--solc",
@@ -443,9 +470,11 @@ fn with_standard_json_llvm_ir() -> anyhow::Result<()> {
443470
fn with_standard_json_llvm_ir_with_solc() -> anyhow::Result<()> {
444471
common::setup()?;
445472

446-
let solc_compiler =
447-
common::get_solc_compiler(&era_compiler_solidity::SolcCompiler::LAST_SUPPORTED_VERSION)?
448-
.executable;
473+
let solc_compiler = common::get_solc_compiler(
474+
&era_compiler_solidity::SolcCompiler::LAST_SUPPORTED_VERSION,
475+
false,
476+
)?
477+
.executable;
449478

450479
let args = &[
451480
"--standard-json",
@@ -483,9 +512,11 @@ fn with_standard_json_eravm_assembly() -> anyhow::Result<()> {
483512
fn with_standard_json_eravm_assembly_with_solc() -> anyhow::Result<()> {
484513
common::setup()?;
485514

486-
let solc_compiler =
487-
common::get_solc_compiler(&era_compiler_solidity::SolcCompiler::LAST_SUPPORTED_VERSION)?
488-
.executable;
515+
let solc_compiler = common::get_solc_compiler(
516+
&era_compiler_solidity::SolcCompiler::LAST_SUPPORTED_VERSION,
517+
false,
518+
)?
519+
.executable;
489520

490521
let args = &[
491522
"--standard-json",

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,11 @@ fn with_suppressed_errors_invalid() -> anyhow::Result<()> {
6464
fn with_suppressed_warnings_invalid_standard_json() -> anyhow::Result<()> {
6565
common::setup()?;
6666

67-
let solc_compiler =
68-
common::get_solc_compiler(&era_compiler_solidity::SolcCompiler::LAST_SUPPORTED_VERSION)?
69-
.executable;
67+
let solc_compiler = common::get_solc_compiler(
68+
&era_compiler_solidity::SolcCompiler::LAST_SUPPORTED_VERSION,
69+
false,
70+
)?
71+
.executable;
7072

7173
let args = &[
7274
"--solc",
@@ -87,9 +89,11 @@ fn with_suppressed_warnings_invalid_standard_json() -> anyhow::Result<()> {
8789
fn with_suppressed_errors_invalid_standard_json() -> anyhow::Result<()> {
8890
common::setup()?;
8991

90-
let solc_compiler =
91-
common::get_solc_compiler(&era_compiler_solidity::SolcCompiler::LAST_SUPPORTED_VERSION)?
92-
.executable;
92+
let solc_compiler = common::get_solc_compiler(
93+
&era_compiler_solidity::SolcCompiler::LAST_SUPPORTED_VERSION,
94+
false,
95+
)?
96+
.executable;
9397

9498
let args = &[
9599
"--solc",

0 commit comments

Comments
 (0)