Skip to content

Commit

Permalink
improve test directory path handling
Browse files Browse the repository at this point in the history
  • Loading branch information
hedgar2017 committed Jan 20, 2025
1 parent 7cb7080 commit 67b795b
Showing 3 changed files with 53 additions and 55 deletions.
19 changes: 6 additions & 13 deletions compiler_tester/src/directories/matter_labs/mod.rs
Original file line number Diff line number Diff line change
@@ -36,36 +36,29 @@ impl Collection for MatterLabsDirectory {
let entry = entry?;
let path = entry.path();
let entry_type = entry.file_type().map_err(|error| {
anyhow::anyhow!(
"Failed to get the type of file `{}`: {}",
path.to_string_lossy(),
error
)
anyhow::anyhow!("Failed to get the type of file {path:?}: {error}")
})?;

if entry_type.is_dir() {
tests.extend(Self::read_all(
_target,
&path,
path.as_path(),
extension,
summary.clone(),
filters,
)?);
continue;
} else if !entry_type.is_file() {
anyhow::bail!("Invalid type of file `{}`", path.to_string_lossy());
anyhow::bail!("Invalid type of file {path:?}");
}

if entry.file_name().to_string_lossy().starts_with('.') {
continue;
}

let file_extension = path.extension().ok_or_else(|| {
anyhow::anyhow!(
"Failed to get the extension of file `{}`",
path.to_string_lossy()
)
})?;
let file_extension = path
.extension()
.ok_or_else(|| anyhow::anyhow!("Failed to get the extension of file {path:?}"))?;
if file_extension != extension {
continue;
}
53 changes: 29 additions & 24 deletions compiler_tester/src/lib.rs
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ pub(crate) mod utils;
pub(crate) mod vm;
pub(crate) mod workflow;

use std::path::Path;
use std::path::PathBuf;
use std::sync::Arc;
use std::sync::Mutex;

@@ -281,7 +281,7 @@ impl CompilerTester {

tests.extend(self.directory::<MatterLabsDirectory>(
target,
Self::SOLIDITY_SIMPLE,
PathBuf::from(Self::SOLIDITY_SIMPLE.replace("/", std::path::MAIN_SEPARATOR_STR)),
era_compiler_common::EXTENSION_SOLIDITY,
match toolchain {
Toolchain::IrLLVM => solidity_compiler.clone(),
@@ -291,14 +291,14 @@ impl CompilerTester {
if let era_compiler_common::Target::EraVM = target {
tests.extend(self.directory::<MatterLabsDirectory>(
target,
Self::VYPER_SIMPLE,
PathBuf::from(Self::VYPER_SIMPLE.replace("/", std::path::MAIN_SEPARATOR_STR)),
era_compiler_common::EXTENSION_VYPER,
vyper_compiler.clone(),
)?);
}
tests.extend(self.directory::<MatterLabsDirectory>(
target,
Self::YUL_SIMPLE,
PathBuf::from(Self::YUL_SIMPLE.replace("/", std::path::MAIN_SEPARATOR_STR)),
era_compiler_common::EXTENSION_YUL,
match toolchain {
Toolchain::IrLLVM => yul_compiler.clone(),
@@ -307,20 +307,20 @@ impl CompilerTester {
)?);
tests.extend(self.directory::<MatterLabsDirectory>(
target,
Self::LLVM_SIMPLE,
PathBuf::from(Self::LLVM_SIMPLE.replace("/", std::path::MAIN_SEPARATOR_STR)),
era_compiler_common::EXTENSION_LLVM_SOURCE,
llvm_compiler,
)?);
tests.extend(self.directory::<MatterLabsDirectory>(
target,
Self::ERAVM_SIMPLE,
PathBuf::from(Self::ERAVM_SIMPLE.replace("/", std::path::MAIN_SEPARATOR_STR)),
era_compiler_common::EXTENSION_ERAVM_ASSEMBLY,
eravm_compiler,
)?);

tests.extend(self.directory::<MatterLabsDirectory>(
target,
Self::SOLIDITY_COMPLEX,
PathBuf::from(Self::SOLIDITY_COMPLEX.replace("/", std::path::MAIN_SEPARATOR_STR)),
era_compiler_common::EXTENSION_JSON,
match toolchain {
Toolchain::IrLLVM => solidity_compiler.clone(),
@@ -330,28 +330,33 @@ impl CompilerTester {
if let era_compiler_common::Target::EraVM = target {
tests.extend(self.directory::<MatterLabsDirectory>(
target,
Self::VYPER_COMPLEX,
PathBuf::from(Self::VYPER_COMPLEX.replace("/", std::path::MAIN_SEPARATOR_STR)),
era_compiler_common::EXTENSION_JSON,
vyper_compiler.clone(),
)?);
}

tests.extend(self.directory::<EthereumDirectory>(
target,
match target {
era_compiler_common::Target::EraVM => Self::SOLIDITY_ETHEREUM,
era_compiler_common::Target::EVM => Self::SOLIDITY_ETHEREUM_UPSTREAM,
},
era_compiler_common::EXTENSION_SOLIDITY,
match toolchain {
Toolchain::IrLLVM => solidity_compiler.clone(),
Toolchain::Solc | Toolchain::SolcLLVM => solidity_upstream_compiler.clone(),
},
)?);
tests.extend(
self.directory::<EthereumDirectory>(
target,
PathBuf::from(
match target {
era_compiler_common::Target::EraVM => Self::SOLIDITY_ETHEREUM,
era_compiler_common::Target::EVM => Self::SOLIDITY_ETHEREUM_UPSTREAM,
}
.replace("/", std::path::MAIN_SEPARATOR_STR),
),
era_compiler_common::EXTENSION_SOLIDITY,
match toolchain {
Toolchain::IrLLVM => solidity_compiler.clone(),
Toolchain::Solc | Toolchain::SolcLLVM => solidity_upstream_compiler.clone(),
},
)?,
);
if let era_compiler_common::Target::EraVM = target {
tests.extend(self.directory::<EthereumDirectory>(
target,
Self::VYPER_ETHEREUM,
PathBuf::from(Self::VYPER_ETHEREUM.replace("/", std::path::MAIN_SEPARATOR_STR)),
era_compiler_common::EXTENSION_VYPER,
vyper_compiler,
)?);
@@ -366,7 +371,7 @@ impl CompilerTester {
fn directory<T>(
&self,
target: era_compiler_common::Target,
path: &str,
path: PathBuf,
extension: &'static str,
compiler: Arc<dyn Compiler>,
) -> anyhow::Result<Vec<Test>>
@@ -375,12 +380,12 @@ impl CompilerTester {
{
Ok(T::read_all(
target,
Path::new(path),
path.as_path(),
extension,
self.summary.clone(),
&self.filters,
)
.map_err(|error| anyhow::anyhow!("Failed to read the tests directory `{path}`: {error}"))?
.map_err(|error| anyhow::anyhow!("Failed to read the tests directory {path:?}: {error}"))?
.into_iter()
.map(|test| Arc::new(test) as Arc<dyn Buildable>)
.cartesian_product(compiler.all_modes())
36 changes: 18 additions & 18 deletions compiler_tester/src/vm/eravm/system_contracts.rs
Original file line number Diff line number Diff line change
@@ -220,20 +220,20 @@ impl SystemContracts {
let solidity_system_contracts = vec![
(
web3::types::Address::zero(),
Self::normalize_path_fs(
Self::normalize_name_fs(
Self::PATH_EMPTY_CONTRACT.0,
Some(Self::PATH_EMPTY_CONTRACT.1),
),
),
(
web3::types::Address::from_low_u64_be(zkevm_opcode_defs::ADDRESS_IDENTITY.into()),
Self::normalize_path_fs(Self::PATH_IDENTITY.0, Some(Self::PATH_IDENTITY.1)),
Self::normalize_name_fs(Self::PATH_IDENTITY.0, Some(Self::PATH_IDENTITY.1)),
),
(
web3::types::Address::from_low_u64_be(
zkevm_opcode_defs::ADDRESS_ACCOUNT_CODE_STORAGE.into(),
),
Self::normalize_path_fs(
Self::normalize_name_fs(
Self::PATH_ACCOUNT_CODE_STORAGE.0,
Some(Self::PATH_ACCOUNT_CODE_STORAGE.1),
),
@@ -242,13 +242,13 @@ impl SystemContracts {
web3::types::Address::from_low_u64_be(
zkevm_opcode_defs::ADDRESS_NONCE_HOLDER.into(),
),
Self::normalize_path_fs(Self::PATH_NONCE_HOLDER.0, Some(Self::PATH_NONCE_HOLDER.1)),
Self::normalize_name_fs(Self::PATH_NONCE_HOLDER.0, Some(Self::PATH_NONCE_HOLDER.1)),
),
(
web3::types::Address::from_low_u64_be(
zkevm_opcode_defs::ADDRESS_KNOWN_CODES_STORAGE.into(),
),
Self::normalize_path_fs(
Self::normalize_name_fs(
Self::PATH_KNOWN_CODES_STORAGE.0,
Some(Self::PATH_KNOWN_CODES_STORAGE.1),
),
@@ -257,7 +257,7 @@ impl SystemContracts {
web3::types::Address::from_low_u64_be(
zkevm_opcode_defs::ADDRESS_IMMUTABLE_SIMULATOR.into(),
),
Self::normalize_path_fs(
Self::normalize_name_fs(
Self::PATH_IMMUTABLE_SIMULATOR.0,
Some(Self::PATH_IMMUTABLE_SIMULATOR.1),
),
@@ -266,7 +266,7 @@ impl SystemContracts {
web3::types::Address::from_low_u64_be(
zkevm_opcode_defs::ADDRESS_CONTRACT_DEPLOYER.into(),
),
Self::normalize_path_fs(
Self::normalize_name_fs(
Self::PATH_CONTRACT_DEPLOYER.0,
Some(Self::PATH_CONTRACT_DEPLOYER.1),
),
@@ -275,11 +275,11 @@ impl SystemContracts {
web3::types::Address::from_low_u64_be(
zkevm_opcode_defs::ADDRESS_L1_MESSENGER.into(),
),
Self::normalize_path_fs(Self::PATH_L1_MESSENGER.0, Some(Self::PATH_L1_MESSENGER.1)),
Self::normalize_name_fs(Self::PATH_L1_MESSENGER.0, Some(Self::PATH_L1_MESSENGER.1)),
),
(
web3::types::Address::from_low_u64_be(zkevm_opcode_defs::ADDRESS_MSG_VALUE.into()),
Self::normalize_path_fs(
Self::normalize_name_fs(
Self::PATH_MSG_VALUE_SIMULATOR.0,
Some(Self::PATH_MSG_VALUE_SIMULATOR.1),
),
@@ -288,14 +288,14 @@ impl SystemContracts {
web3::types::Address::from_low_u64_be(
zkevm_opcode_defs::ADDRESS_SYSTEM_CONTEXT.into(),
),
Self::normalize_path_fs(
Self::normalize_name_fs(
Self::PATH_SYSTEM_CONTEXT.0,
Some(Self::PATH_SYSTEM_CONTEXT.1),
),
),
(
web3::types::Address::from_low_u64_be(zkevm_opcode_defs::ADDRESS_ETH_TOKEN.into()),
Self::normalize_path_fs(Self::PATH_BASE_TOKEN.0, Some(Self::PATH_BASE_TOKEN.1)),
Self::normalize_name_fs(Self::PATH_BASE_TOKEN.0, Some(Self::PATH_BASE_TOKEN.1)),
),
];

@@ -368,14 +368,14 @@ impl SystemContracts {

let default_aa = builds
.remove(
Self::normalize_path_solc(Self::PATH_DEFAULT_AA.0, Some(Self::PATH_DEFAULT_AA.1))
Self::normalize_name_solc(Self::PATH_DEFAULT_AA.0, Some(Self::PATH_DEFAULT_AA.1))
.as_str(),
)
.ok_or_else(|| {
anyhow::anyhow!("The default AA code not found in the compiler build artifacts")
})?;
let evm_emulator = builds
.remove(Self::normalize_path_solc(Self::PATH_EVM_EMULATOR, None).as_str())
.remove(Self::normalize_name_solc(Self::PATH_EVM_EMULATOR, None).as_str())
.ok_or_else(|| {
anyhow::anyhow!("The EVM emulator code not found in the compiler build artifacts")
})?;
@@ -388,7 +388,7 @@ impl SystemContracts {
let mut deployed_contracts = Vec::with_capacity(system_contracts.len());
for (address, path) in system_contracts.into_iter() {
let build = builds
.remove(Self::normalize_path_solc(path.as_str(), None).as_str())
.remove(Self::normalize_name_solc(path.as_str(), None).as_str())
.unwrap_or_else(|| panic!("System contract `{path}` not found in the builds"));
deployed_contracts.push((address, build));
}
@@ -444,9 +444,9 @@ impl SystemContracts {
}

///
/// Normalizes paths with respect to the file system.
/// Normalizes contract names with respect to the file system.
///
fn normalize_path_fs(path: &str, name: Option<&str>) -> String {
fn normalize_name_fs(path: &str, name: Option<&str>) -> String {
let contract_name = era_compiler_common::ContractName::new(
path.replace("/", std::path::MAIN_SEPARATOR_STR),
name.map(|name| name.to_string()),
@@ -455,9 +455,9 @@ impl SystemContracts {
}

///
/// Normalizes paths with respect to `solc`.
/// Normalizes contract names with respect to `solc`.
///
fn normalize_path_solc(path: &str, name: Option<&str>) -> String {
fn normalize_name_solc(path: &str, name: Option<&str>) -> String {
let contract_name = era_compiler_common::ContractName::new(
path.replace(std::path::MAIN_SEPARATOR_STR, "/"),
name.map(|name| name.to_string()),

0 comments on commit 67b795b

Please sign in to comment.