Skip to content

Commit

Permalink
Run basic EVM tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hedgar2017 committed Apr 9, 2024
1 parent 1907b07 commit 763bdd6
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl Case {
continue;
}

if name != "BenchmarkCaller"
if name != "Benchmark"
&& name.split('_').next().unwrap_or_default()
!= self.name.split('_').next().unwrap_or_default()
{
Expand Down
18 changes: 9 additions & 9 deletions compiler_tester/src/directories/matter_labs/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,23 +210,23 @@ impl MatterLabsTest {
}

///
/// Adds the BenchmarkCaller contract as a proxy for the EVM interpreter.
/// Adds the Benchmark contract as a proxy for the EVM interpreter.
///
fn push_benchmark_caller(
&self,
sources: &mut Vec<(String, String)>,
contracts: &mut BTreeMap<String, String>,
) -> anyhow::Result<()> {
let benchmark_caller_string = std::fs::read_to_string(PathBuf::from(
"tests/solidity/complex/interpreter/BenchmarkCaller.sol",
"tests/solidity/complex/interpreter/Benchmark.sol",
))?;
sources.push((
"tests/solidity/complex/interpreter/BenchmarkCaller.sol".to_owned(),
"tests/solidity/complex/interpreter/Benchmark.sol".to_owned(),
benchmark_caller_string,
)); // TODO
contracts.insert(
"BenchmarkCaller".to_owned(),
"tests/solidity/complex/interpreter/BenchmarkCaller.sol:BenchmarkCaller".to_owned(),
"Benchmark".to_owned(),
"tests/solidity/complex/interpreter/Benchmark.sol:Benchmark".to_owned(),
);
Ok(())
}
Expand Down Expand Up @@ -333,7 +333,7 @@ impl MatterLabsTest {
caller: default_caller_address(),
method: "benchmark".to_owned(),
calldata: MatterLabsCaseInputCalldata::List(vec![
"BenchmarkCaller.address".to_owned(),
"Benchmark.address".to_owned(),
format!("{template}.address"),
]),
value: None,
Expand All @@ -348,7 +348,7 @@ impl MatterLabsTest {
caller: default_caller_address(),
method: "benchmark".to_owned(),
calldata: MatterLabsCaseInputCalldata::List(vec![
"BenchmarkCaller.address".to_owned(),
"Benchmark.address".to_owned(),
format!("{full}.address"),
]),
value: None,
Expand All @@ -363,7 +363,7 @@ impl MatterLabsTest {
caller: default_caller_address(),
method: "benchmark".to_owned(),
calldata: MatterLabsCaseInputCalldata::List(vec![
"BenchmarkCaller.address".to_owned(),
"Benchmark.address".to_owned(),
format!("{template}.address"),
]),
value: None,
Expand All @@ -378,7 +378,7 @@ impl MatterLabsTest {
caller: default_caller_address(),
method: "benchmark".to_owned(),
calldata: MatterLabsCaseInputCalldata::List(vec![
"BenchmarkCaller.address".to_owned(),
"Benchmark.address".to_owned(),
format!("{full}.address"),
]),
value: None,
Expand Down
9 changes: 7 additions & 2 deletions compiler_tester/src/test/case/input/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,16 +197,21 @@ impl Runtime {
let benchmark_caller_address =
web3::types::Address::from_str(EraVM::DEFAULT_BENCHMARK_CALLER_ADDRESS)
.expect("Always valid");
let evm_proxy_address =
web3::types::Address::from_low_u64_be(0x10000);

let mut calldata =
Vec::with_capacity(era_compiler_common::BYTE_LENGTH_FIELD + self.calldata.inner.len());
Vec::with_capacity(era_compiler_common::BYTE_LENGTH_X32 + (era_compiler_common::BYTE_LENGTH_FIELD * 2) + self.calldata.inner.len());
calldata.extend(crate::utils::selector("benchmark(address,address)"));
calldata.extend([0u8; era_compiler_common::BYTE_LENGTH_FIELD - BYTE_LENGTH_ETH_ADDRESS]);
calldata.extend(benchmark_caller_address.as_bytes());
calldata.extend([0u8; era_compiler_common::BYTE_LENGTH_FIELD - BYTE_LENGTH_ETH_ADDRESS]);
calldata.extend(self.address.as_bytes());
calldata.extend(self.calldata.inner);

let mut result = match vm.execute::<M>(
name.clone(),
benchmark_caller_address,
evm_proxy_address,
self.caller,
self.value,
calldata.clone(),
Expand Down
19 changes: 15 additions & 4 deletions compiler_tester/src/vm/eravm/system_contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ impl SystemContracts {
const PATH_EVM_GAS_MANAGER: &'static str =
"era-contracts/system-contracts/contracts/EvmGasManager.sol:EvmGasManager";

/// The EVM proxy temporary system contract implementation path.
const PATH_EVM_PROXY: &'static str =
"tests/solidity/complex/interpreter/Proxy.sol:Proxy";

///
/// Loads or builds the system contracts.
///
Expand Down Expand Up @@ -234,6 +238,10 @@ impl SystemContracts {
web3::types::Address::from_low_u64_be(0x8012),
Self::PATH_EVM_GAS_MANAGER,
),
(
web3::types::Address::from_low_u64_be(0x10000),
Self::PATH_EVM_PROXY,
),
];

let mut yul_file_paths = Vec::with_capacity(yul_system_contracts.len() + 1);
Expand All @@ -252,12 +260,15 @@ impl SystemContracts {
let file_path = path.split(':').next().expect("Always valid");
solidity_file_paths.push(file_path.to_owned());
}
for path in glob::glob("era-contracts/system-contracts/**/*.sol")?.filter_map(Result::ok) {
let path = path.to_string_lossy().to_string();
if !solidity_file_paths.contains(&path) {
solidity_file_paths.push(path);
for pattern in ["era-contracts/system-contracts/**/*.sol", "tests/solidity/complex/interpreter/*.sol"] {
for path in glob::glob(pattern)?.filter_map(Result::ok) {
let path = path.to_string_lossy().to_string();
if !solidity_file_paths.contains(&path) {
solidity_file_paths.push(path);
}
}
}

let solidity_optimizer_settings =
era_compiler_llvm_context::OptimizerSettings::evm_interpreter();
let solidity_mode = SolidityMode::new(
Expand Down
Binary file modified system-contracts-stable-build
Binary file not shown.

0 comments on commit 763bdd6

Please sign in to comment.