Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(vm): Test EVM emulator in multivm crate #3232

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ db-ssd/
backups/
artifacts/
artifacts-zk/
cache-evm/
cache-zk/
zksolc
verified_sources
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion contracts
Submodule contracts updated 149 files
28 changes: 19 additions & 9 deletions core/lib/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,26 @@ pub fn read_bytecode_from_path(
) -> Option<Vec<u8>> {
let artifact = read_file_to_json_value(&artifact_path)?;

let bytecode = if let Some(bytecode) = artifact["bytecode"].as_str() {
bytecode
.strip_prefix("0x")
.unwrap_or_else(|| panic!("Bytecode in {:?} is not hex", artifact_path))
} else {
artifact["bytecode"]["object"]
.as_str()
.unwrap_or_else(|| panic!("Bytecode not found in {:?}", artifact_path))
};
let bytecode = artifact["bytecode"]
.as_str()
.or_else(|| artifact["bytecode"]["object"].as_str())
.unwrap_or_else(|| panic!("Bytecode not found in {:?}", artifact_path));
// Strip an optional `0x` prefix.
let bytecode = bytecode.strip_prefix("0x").unwrap_or(bytecode);
Some(
hex::decode(bytecode)
.unwrap_or_else(|err| panic!("Can't decode bytecode in {:?}: {}", artifact_path, err)),
)
}

pub fn read_deployed_bytecode_from_path(artifact_path: &Path) -> Option<Vec<u8>> {
let artifact = read_file_to_json_value(artifact_path)?;
let bytecode = artifact["deployedBytecode"]
.as_str()
.or_else(|| artifact["deployedBytecode"]["object"].as_str())
.unwrap_or_else(|| panic!("Deployed bytecode not found in {:?}", artifact_path));
// Strip an optional `0x` prefix.
let bytecode = bytecode.strip_prefix("0x").unwrap_or(bytecode);
Some(
hex::decode(bytecode)
.unwrap_or_else(|err| panic!("Can't decode bytecode in {:?}: {}", artifact_path, err)),
Expand Down
1 change: 1 addition & 0 deletions core/lib/multivm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ ethabi.workspace = true
[dev-dependencies]
assert_matches.workspace = true
pretty_assertions.workspace = true
rand.workspace = true
test-casing.workspace = true
zksync_test_account.workspace = true
zksync_eth_signer.workspace = true
4 changes: 2 additions & 2 deletions core/lib/multivm/src/versions/shadow/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,10 @@ mod default_aa {
}
}

mod evm_emulator {
mod mock_evm {
use test_casing::{test_casing, Product};

use crate::versions::testonly::evm_emulator::*;
use crate::versions::testonly::mock_evm::*;

#[test]
fn tracing_evm_contract_deployment() {
Expand Down
2 changes: 0 additions & 2 deletions core/lib/multivm/src/versions/testonly/bootloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ pub(crate) fn test_dummy_bootloader<VM: TestedVm>() {
base_system_contracts.bootloader = get_bootloader("dummy");

let mut vm = VmTesterBuilder::new()
.with_empty_in_memory_storage()
.with_base_system_smart_contracts(base_system_contracts)
.with_execution_mode(TxExecutionMode::VerifyExecute)
.build::<VM>();
Expand All @@ -27,7 +26,6 @@ pub(crate) fn test_bootloader_out_of_gas<VM: TestedVm>() {
base_system_contracts.bootloader = get_bootloader("dummy");

let mut vm = VmTesterBuilder::new()
.with_empty_in_memory_storage()
.with_base_system_smart_contracts(base_system_contracts)
.with_bootloader_gas_limit(10)
.with_execution_mode(TxExecutionMode::VerifyExecute)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ pub(crate) fn test_bytecode_publishing<VM: TestedVm>() {
// In this test, we aim to ensure that the contents of the compressed bytecodes
// are included as part of the L2->L1 long messages
let mut vm = VmTesterBuilder::new()
.with_empty_in_memory_storage()
.with_execution_mode(TxExecutionMode::VerifyExecute)
.with_rich_accounts(1)
.build::<VM>();
Expand Down
1 change: 0 additions & 1 deletion core/lib/multivm/src/versions/testonly/circuits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use crate::{
/// from hardcoded expected value.
pub(crate) fn test_circuits<VM: TestedVm>() {
let mut vm = VmTesterBuilder::new()
.with_empty_in_memory_storage()
.with_rich_accounts(1)
.with_bootloader_gas_limit(BATCH_COMPUTATIONAL_GAS_LIMIT)
.with_execution_mode(TxExecutionMode::VerifyExecute)
Expand Down
2 changes: 0 additions & 2 deletions core/lib/multivm/src/versions/testonly/code_oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ pub(crate) fn test_code_oracle<VM: TestedVm>() {
// In this test, we aim to test whether a simple account interaction (without any fee logic)
// will work. The account will try to deploy a simple contract from integration tests.
let mut vm = VmTesterBuilder::new()
.with_empty_in_memory_storage()
.with_execution_mode(TxExecutionMode::VerifyExecute)
.with_rich_accounts(1)
.with_custom_contracts(vec![ContractToDeploy::new(
Expand Down Expand Up @@ -126,7 +125,6 @@ pub(crate) fn test_code_oracle_big_bytecode<VM: TestedVm>() {
// In this test, we aim to test whether a simple account interaction (without any fee logic)
// will work. The account will try to deploy a simple contract from integration tests.
let mut vm = VmTesterBuilder::new()
.with_empty_in_memory_storage()
.with_execution_mode(TxExecutionMode::VerifyExecute)
.with_rich_accounts(1)
.with_custom_contracts(vec![ContractToDeploy::new(
Expand Down
1 change: 0 additions & 1 deletion core/lib/multivm/src/versions/testonly/default_aa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ pub(crate) fn test_default_aa_interaction<VM: TestedVm>() {
// In this test, we aim to test whether a simple account interaction (without any fee logic)
// will work. The account will try to deploy a simple contract from integration tests.
let mut vm = VmTesterBuilder::new()
.with_empty_in_memory_storage()
.with_execution_mode(TxExecutionMode::VerifyExecute)
.with_rich_accounts(1)
.build::<VM>();
Expand Down
Loading
Loading