Skip to content

Commit

Permalink
Recover tests for vm virtual blocks
Browse files Browse the repository at this point in the history
Signed-off-by: Danil <[email protected]>
  • Loading branch information
Deniallugo committed Oct 26, 2023
1 parent 245af44 commit b5c2340
Show file tree
Hide file tree
Showing 21 changed files with 69 additions and 73 deletions.
6 changes: 3 additions & 3 deletions core/lib/multivm/src/versions/vm_virtual_blocks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub use old_vm::{

pub use tracers::{
dispatcher::TracerDispatcher,
traits::{ExecutionEndTracer, ExecutionProcessing, ToTracerPointer, TracerPointer, VmTracer},
traits::{ExecutionEndTracer, ExecutionProcessing, TracerPointer, VmTracer},
utils::VmExecutionStopReason,
};

Expand All @@ -27,5 +27,5 @@ mod vm;
pub mod constants;
pub mod utils;

// #[cfg(test)]
// mod tests;
#[cfg(test)]
mod tests;
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use zksync_types::U256;

use crate::interface::{ExecutionResult, Halt, TxExecutionMode, VmExecutionMode};
use crate::interface::{ExecutionResult, Halt, TxExecutionMode, VmExecutionMode, VmInterface};
use crate::vm_virtual_blocks::constants::BOOTLOADER_HEAP_PAGE;
use crate::vm_virtual_blocks::tests::tester::VmTesterBuilder;
use crate::vm_virtual_blocks::tests::utils::{
get_bootloader, verify_required_memory, BASE_SYSTEM_CONTRACTS,
};

use crate::vm_virtual_blocks::HistoryEnabled;
use crate::vm_latest::HistoryEnabled;

#[test]
fn test_dummy_bootloader() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use zksync_types::event::extract_long_l2_to_l1_messages;
use zksync_utils::bytecode::compress_bytecode;

use crate::interface::{TxExecutionMode, VmExecutionMode};
use crate::interface::{TxExecutionMode, VmExecutionMode, VmInterface};
use crate::vm_latest::HistoryEnabled;
use crate::vm_virtual_blocks::tests::tester::{DeployContractsTx, TxType, VmTesterBuilder};
use crate::vm_virtual_blocks::tests::utils::read_test_contract;
use crate::vm_virtual_blocks::HistoryEnabled;

#[test]
fn test_bytecode_publishing() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use crate::interface::{TxExecutionMode, VmExecutionMode};
use crate::interface::{TxExecutionMode, VmExecutionMode, VmInterface};
use crate::tracers::CallTracer;
use crate::vm_latest::HistoryEnabled;
use crate::vm_virtual_blocks::constants::BLOCK_GAS_LIMIT;
use crate::vm_virtual_blocks::tests::tester::VmTesterBuilder;
use crate::vm_virtual_blocks::tests::utils::{read_max_depth_contract, read_test_contract};
use crate::vm_virtual_blocks::{CallTracer, HistoryEnabled};
use crate::vm_virtual_blocks::VmTracer;
use once_cell::sync::OnceCell;
use std::sync::Arc;
use zksync_types::{Address, Execute};
Expand Down Expand Up @@ -34,11 +36,9 @@ fn test_max_depth() {
);

let result = Arc::new(OnceCell::new());
let call_tracer = CallTracer::new(result.clone(), HistoryEnabled);
let call_tracer = CallTracer::new(result.clone()).to_rc_ptr();
vm.vm.push_transaction(tx);
let res = vm
.vm
.inspect(vec![Box::new(call_tracer)], VmExecutionMode::OneTx);
let res = vm.vm.inspect(call_tracer.into(), VmExecutionMode::OneTx);
assert!(result.get().is_some());
assert!(res.result.is_failed());
}
Expand Down Expand Up @@ -71,11 +71,11 @@ fn test_basic_behavior() {
);

let result = Arc::new(OnceCell::new());
let call_tracer = CallTracer::new(result.clone(), HistoryEnabled);
let call_tracer = CallTracer::new(result.clone());
vm.vm.push_transaction(tx);
let res = vm
.vm
.inspect(vec![Box::new(call_tracer)], VmExecutionMode::OneTx);
.inspect(call_tracer.to_rc_ptr().into(), VmExecutionMode::OneTx);

let call_tracer_result = result.get().unwrap();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ use zksync_types::system_contracts::{DEPLOYMENT_NONCE_INCREMENT, TX_NONCE_INCREM
use zksync_types::{get_code_key, get_known_code_key, get_nonce_key, AccountTreeId, U256};
use zksync_utils::u256_to_h256;

use crate::interface::{TxExecutionMode, VmExecutionMode};
use crate::interface::{TxExecutionMode, VmExecutionMode, VmInterface};
use crate::vm_latest::HistoryEnabled;
use crate::vm_virtual_blocks::tests::tester::{DeployContractsTx, TxType, VmTesterBuilder};
use crate::vm_virtual_blocks::tests::utils::{
get_balance, read_test_contract, verify_required_storage,
};
use crate::vm_virtual_blocks::HistoryEnabled;

#[test]
fn test_default_aa_interaction() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use crate::vm_virtual_blocks::constants::{
};
use crate::vm_virtual_blocks::tests::tester::VmTesterBuilder;

use crate::interface::TxExecutionMode;
use crate::vm_virtual_blocks::HistoryDisabled;
use crate::interface::{TxExecutionMode, VmInterface};
use crate::vm_latest::HistoryDisabled;

/// Checks that `TX_GAS_LIMIT_OFFSET` constant is correct.
#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ use std::collections::{HashMap, HashSet};

use itertools::Itertools;

use crate::HistoryMode;
use zksync_state::WriteStorage;
use zksync_system_constants::CONTRACT_DEPLOYER_ADDRESS;
use zksync_test_account::Account;
use zksync_types::{Execute, U256};
use zksync_utils::bytecode::hash_bytecode;
use zksync_utils::h256_to_u256;

use crate::interface::{TxExecutionMode, VmExecutionMode};
use crate::interface::{TxExecutionMode, VmExecutionMode, VmInterface};
use crate::vm_latest::HistoryDisabled;
use crate::vm_virtual_blocks::tests::tester::{TxType, VmTesterBuilder};
use crate::vm_virtual_blocks::tests::utils::{read_test_contract, BASE_SYSTEM_CONTRACTS};
use crate::vm_virtual_blocks::{HistoryDisabled, HistoryMode, Vm};
use crate::vm_virtual_blocks::Vm;

#[test]
fn test_get_used_contracts() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use zksync_state::ReadStorage;
use zksync_types::get_nonce_key;

use crate::interface::{TxExecutionMode, VmExecutionMode};
use crate::interface::{TxExecutionMode, VmExecutionMode, VmInterface};
use crate::vm_latest::HistoryDisabled;
use crate::vm_virtual_blocks::tests::tester::{Account, TxType, VmTesterBuilder};
use crate::vm_virtual_blocks::tests::utils::read_test_contract;
use crate::vm_virtual_blocks::HistoryDisabled;

#[test]
fn test_is_write_initial_behaviour() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use zksync_types::storage_writes_deduplicator::StorageWritesDeduplicator;
use zksync_types::{get_code_key, get_known_code_key, U256};
use zksync_utils::u256_to_h256;

use crate::interface::{TxExecutionMode, VmExecutionMode};
use crate::interface::{TxExecutionMode, VmExecutionMode, VmInterface};
use crate::vm_latest::HistoryEnabled;
use crate::vm_virtual_blocks::tests::tester::{TxType, VmTesterBuilder};
use crate::vm_virtual_blocks::tests::utils::{
read_test_contract, verify_required_storage, BASE_SYSTEM_CONTRACTS,
};
use crate::vm_virtual_blocks::types::internals::TransactionData;
use crate::vm_virtual_blocks::HistoryEnabled;

#[test]
fn test_l1_tx_execution() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
//! The description for each of the tests can be found in the corresponding `.yul` file.
//!

use crate::interface::{ExecutionResult, Halt, L2BlockEnv, TxExecutionMode, VmExecutionMode};
use crate::interface::{
ExecutionResult, Halt, L2BlockEnv, TxExecutionMode, VmExecutionMode, VmInterface,
};
use crate::vm_latest::HistoryEnabled;
use crate::vm_virtual_blocks::constants::{
BOOTLOADER_HEAP_PAGE, TX_OPERATOR_L2_BLOCK_INFO_OFFSET, TX_OPERATOR_SLOTS_PER_L2_BLOCK_INFO,
};
use crate::vm_virtual_blocks::tests::tester::default_l1_batch;
use crate::vm_virtual_blocks::tests::tester::VmTesterBuilder;
use crate::vm_virtual_blocks::utils::l2_blocks::get_l2_block_hash_key;
use crate::vm_virtual_blocks::{HistoryEnabled, HistoryMode, Vm};
use crate::vm_virtual_blocks::Vm;
use crate::HistoryMode;
use zk_evm_1_3_3::aux_structures::Timestamp;
use zksync_state::{ReadStorage, WriteStorage};
use zksync_system_constants::{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use zksync_types::{Execute, Nonce};

use crate::interface::{
ExecutionResult, Halt, TxExecutionMode, TxRevertReason, VmExecutionMode, VmRevertReason,
ExecutionResult, Halt, TxExecutionMode, TxRevertReason, VmExecutionMode, VmInterface,
VmRevertReason,
};
use crate::vm_latest::HistoryEnabled;
use crate::vm_virtual_blocks::tests::tester::{Account, VmTesterBuilder};
use crate::vm_virtual_blocks::tests::utils::read_nonce_holder_tester;
use crate::vm_virtual_blocks::types::internals::TransactionData;
use crate::vm_virtual_blocks::HistoryEnabled;

pub enum NonceHolderTestMode {
SetValueUnderNonce,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::interface::{TxExecutionMode, VmExecutionMode};
use crate::interface::{TxExecutionMode, VmExecutionMode, VmInterface};
use crate::vm_virtual_blocks::tests::tester::{DeployContractsTx, TxType, VmTesterBuilder};
use crate::vm_virtual_blocks::tests::utils::read_test_contract;

use crate::vm_latest::HistoryEnabled;
use crate::vm_virtual_blocks::types::internals::TransactionData;
use crate::vm_virtual_blocks::HistoryEnabled;

#[test]
fn test_predetermined_refunded_gas() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ use zksync_types::transaction_request::TransactionRequest;
use zksync_types::utils::storage_key_for_standard_token_balance;
use zksync_types::{AccountTreeId, Address, Eip712Domain, Execute, Nonce, Transaction, U256};

use crate::interface::{TxExecutionMode, VmExecutionMode};
use crate::interface::{TxExecutionMode, VmExecutionMode, VmInterface};
use crate::vm_latest::HistoryDisabled;
use crate::vm_virtual_blocks::tests::tester::{Account, VmTester, VmTesterBuilder};
use crate::vm_virtual_blocks::tests::utils::read_many_owners_custom_account_contract;
use crate::vm_virtual_blocks::HistoryDisabled;

impl VmTester<HistoryDisabled> {
pub(crate) fn get_eth_balance(&mut self, address: Address) -> U256 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use zksync_contracts::test_contracts::LoadnextContractExecutionParams;
use zksync_types::{Execute, U256};

use crate::interface::TxExecutionMode;
use crate::vm_latest::HistoryEnabled;
use crate::vm_virtual_blocks::tests::tester::{
DeployContractsTx, TransactionTestInfo, TxModifier, TxType, VmTesterBuilder,
};
use crate::vm_virtual_blocks::tests::utils::read_test_contract;
use crate::vm_virtual_blocks::HistoryEnabled;

#[test]
fn test_vm_rollbacks() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::interface::{ExecutionResult, VmExecutionMode};
use crate::interface::{ExecutionResult, VmExecutionMode, VmInterface};
use crate::vm_latest::HistoryDisabled;
use crate::vm_virtual_blocks::tests::tester::{TxType, VmTesterBuilder};
use crate::vm_virtual_blocks::HistoryDisabled;

#[test]
fn estimate_fee() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::vm_virtual_blocks::old_vm::history_recorder::{
AppDataFrameManagerWithHistory, HistoryRecorder,
};
use crate::vm_virtual_blocks::{HistoryEnabled, HistoryMode, SimpleMemory, Vm};
use crate::HistoryMode as CommonHistoryMode;

#[derive(Clone, Debug)]
pub(crate) struct ModifiedKeysMap(HashMap<StorageKey, StorageValue>);
Expand Down Expand Up @@ -68,9 +69,9 @@ pub(crate) struct VmInstanceInnerState<H: HistoryMode> {
local_state: VmLocalState,
}

impl<S: WriteStorage, H: HistoryMode> Vm<S, H> {
impl<S: WriteStorage, H: CommonHistoryMode> Vm<S, H> {
// Dump inner state of the VM.
pub(crate) fn dump_inner_state(&self) -> VmInstanceInnerState<H> {
pub(crate) fn dump_inner_state(&self) -> VmInstanceInnerState<H::VmVirtualBlocksMode> {
let event_sink = self.state.event_sink.clone();
let precompile_processor_state = PrecompileProcessorTestInnerState {
timestamp_history: self.state.precompiles_processor.timestamp_history.clone(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use zksync_types::{ExecuteTransactionCommon, Transaction};

use crate::interface::{
CurrentExecutionState, ExecutionResult, Halt, TxRevertReason, VmExecutionMode,
VmExecutionResultAndLogs, VmRevertReason,
VmExecutionResultAndLogs, VmInterface, VmInterfaceHistoryEnabled, VmRevertReason,
};
use crate::vm_latest::HistoryEnabled;
use crate::vm_virtual_blocks::tests::tester::vm_tester::VmTester;
use crate::vm_virtual_blocks::HistoryEnabled;

#[derive(Debug, Clone)]
pub(crate) enum TxModifier {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::marker::PhantomData;
use zksync_contracts::BaseSystemContracts;
use zksync_state::{InMemoryStorage, StoragePtr, StorageView, WriteStorage};

use crate::HistoryMode;
use zksync_types::block::legacy_miniblock_hash;
use zksync_types::helpers::unix_timestamp_ms;
use zksync_types::utils::{deployed_address_create, storage_key_for_eth_balance};
Expand All @@ -13,13 +15,13 @@ use zksync_utils::u256_to_h256;

use crate::vm_virtual_blocks::constants::BLOCK_GAS_LIMIT;

use crate::interface::TxExecutionMode;
use crate::interface::{L1BatchEnv, L2Block, L2BlockEnv, SystemEnv, VmExecutionMode};
use crate::interface::{TxExecutionMode, VmInterface};
use crate::vm_virtual_blocks::tests::tester::Account;
use crate::vm_virtual_blocks::tests::tester::TxType;
use crate::vm_virtual_blocks::tests::utils::read_test_contract;
use crate::vm_virtual_blocks::utils::l2_blocks::load_last_l2_block;
use crate::vm_virtual_blocks::{HistoryMode, Vm};
use crate::vm_virtual_blocks::Vm;

pub(crate) type InMemoryStorageView = StorageView<InMemoryStorage>;

Expand All @@ -31,7 +33,7 @@ pub(crate) struct VmTester<H: HistoryMode> {
pub(crate) test_contract: Option<Address>,
pub(crate) rich_accounts: Vec<Account>,
pub(crate) custom_contracts: Vec<ContractsToDeploy>,
history_mode: H,
_phantom: PhantomData<H>,
}

impl<H: HistoryMode> VmTester<H> {
Expand Down Expand Up @@ -88,12 +90,7 @@ impl<H: HistoryMode> VmTester<H> {
};
}

let vm = Vm::new(
l1_batch,
self.vm.system_env.clone(),
self.storage.clone(),
self.history_mode.clone(),
);
let vm = Vm::new(l1_batch, self.vm.system_env.clone(), self.storage.clone());

if self.test_contract.is_some() {
self.deploy_test_contract();
Expand All @@ -106,7 +103,7 @@ impl<H: HistoryMode> VmTester<H> {
pub(crate) type ContractsToDeploy = (Vec<u8>, Address, bool);

pub(crate) struct VmTesterBuilder<H: HistoryMode> {
history_mode: H,
_phantom: PhantomData<H>,
storage: Option<InMemoryStorage>,
l1_batch_env: Option<L1BatchEnv>,
system_env: SystemEnv,
Expand All @@ -118,7 +115,7 @@ pub(crate) struct VmTesterBuilder<H: HistoryMode> {
impl<H: HistoryMode> Clone for VmTesterBuilder<H> {
fn clone(&self) -> Self {
Self {
history_mode: Default::default(),
_phantom: Default::default(),
storage: None,
l1_batch_env: self.l1_batch_env.clone(),
system_env: self.system_env.clone(),
Expand All @@ -131,9 +128,9 @@ impl<H: HistoryMode> Clone for VmTesterBuilder<H> {

#[allow(dead_code)]
impl<H: HistoryMode> VmTesterBuilder<H> {
pub(crate) fn new(history_mode: H) -> Self {
pub(crate) fn new(_: H) -> Self {
Self {
history_mode,
_phantom: Default::default(),
storage: None,
l1_batch_env: None,
system_env: SystemEnv {
Expand Down Expand Up @@ -229,12 +226,7 @@ impl<H: HistoryMode> VmTesterBuilder<H> {
}
let fee_account = l1_batch_env.fee_account;

let vm = Vm::new(
l1_batch_env,
self.system_env,
storage_ptr.clone(),
self.history_mode.clone(),
);
let vm = Vm::new(l1_batch_env, self.system_env, storage_ptr.clone());

VmTester {
vm,
Expand All @@ -244,7 +236,7 @@ impl<H: HistoryMode> VmTesterBuilder<H> {
test_contract: None,
rich_accounts: self.rich_accounts.clone(),
custom_contracts: self.custom_contracts.clone(),
history_mode: self.history_mode,
_phantom: Default::default(),
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use crate::interface::{TxExecutionMode, TxRevertReason, VmRevertReason};
use zksync_types::{Execute, H160};

use crate::vm_latest::HistoryEnabled;
use crate::vm_virtual_blocks::tests::tester::{
ExpectedError, TransactionTestInfo, VmTesterBuilder,
};
use crate::vm_virtual_blocks::tests::utils::{
get_execute_error_calldata, read_error_contract, BASE_SYSTEM_CONTRACTS,
};
use crate::vm_virtual_blocks::HistoryEnabled;

#[test]
fn test_tracing_of_execution_errors() {
Expand Down
Loading

0 comments on commit b5c2340

Please sign in to comment.