Skip to content

Commit

Permalink
re-enable tests
Browse files Browse the repository at this point in the history
  • Loading branch information
juan518munoz committed Aug 15, 2024
1 parent 7066bdc commit 7667e7a
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 47 deletions.
2 changes: 1 addition & 1 deletion core/lib/multivm/src/versions/era_vm/tests/bootloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn test_dummy_bootloader() {
let correct_first_cell = U256::from_str_radix("123123123", 16).unwrap();

verify_required_memory(
&vm.vm.inner.state,
&vm.vm.inner.execution,
vec![(correct_first_cell, vm2::FIRST_HEAP, 0)],
);
}
Expand Down
3 changes: 2 additions & 1 deletion core/lib/multivm/src/versions/era_vm/tests/code_oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ fn refunds_in_code_oracle() {
let is_fresh = vm
.vm
.inner
.contract_storage
.state
.contracts_storage
.borrow_mut()
.decommit(h256_to_u256(normal_zkevm_bytecode_hash))
.unwrap()
Expand Down
26 changes: 13 additions & 13 deletions core/lib/multivm/src/versions/era_vm/tests/default_aa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,28 @@ use crate::{
fn test_default_aa_interaction() {
// 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()
let mut vm_tester = VmTesterBuilder::new()
.with_empty_in_memory_storage()
.with_execution_mode(TxExecutionMode::VerifyExecute)
.with_random_rich_accounts(1)
.build();

let counter = read_test_contract();
let account = &mut vm.rich_accounts[0];
let account = &mut vm_tester.rich_accounts[0];
let DeployContractsTx {
tx,
bytecode_hash,
address,
} = account.get_deploy_tx(&counter, None, TxType::L2);
let maximal_fee = tx.gas_limit() * get_batch_base_fee(&vm.vm.batch_env);
let maximal_fee = tx.gas_limit() * get_batch_base_fee(&vm_tester.vm.batch_env);

vm.vm.push_transaction(tx);
let result = vm.vm.execute(VmExecutionMode::OneTx);
vm_tester.vm.push_transaction(tx);
let result = vm_tester.vm.execute(VmExecutionMode::OneTx);
assert!(!result.result.is_failed(), "Transaction wasn't successful");

vm.vm.execute(VmExecutionMode::Batch);
vm_tester.vm.execute(VmExecutionMode::Batch);

vm.vm.get_current_execution_state();
vm_tester.vm.get_current_execution_state();

// Both deployment and ordinary nonce should be incremented by one.
let account_nonce_key = get_nonce_key(&account.address);
Expand All @@ -60,18 +60,18 @@ fn test_default_aa_interaction() {

verify_required_storage(
&expected_slots,
&mut *vm.storage.borrow_mut(),
&vm.vm.inner.state_storage.storage_changes,
&mut *vm_tester.storage.borrow_mut(),
&vm_tester.vm.inner.state.storage_changes.map,
);

let expected_fee = maximal_fee
- U256::from(result.refunds.gas_refunded)
* U256::from(get_batch_base_fee(&vm.vm.batch_env));
* U256::from(get_batch_base_fee(&vm_tester.vm.batch_env));
let operator_balance = get_balance(
AccountTreeId::new(L2_BASE_TOKEN_ADDRESS),
&vm.fee_account,
&mut *vm.storage.borrow_mut(),
&vm.vm.inner.state_storage.storage_changes,
&vm_tester.fee_account,
&mut *vm_tester.storage.borrow_mut(),
&vm_tester.vm.inner.state.storage_changes.map,
);

assert_eq!(
Expand Down
2 changes: 1 addition & 1 deletion core/lib/multivm/src/versions/era_vm/tests/gas_limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn test_tx_gas_limit_offset() {

vm.vm.push_transaction(tx);

assert!(vm.vm.inner.state.running_contexts.len() == 1);
assert!(vm.vm.inner.execution.running_contexts.len() == 1);

let gas_limit_from_memory = vm
.vm
Expand Down
15 changes: 10 additions & 5 deletions core/lib/multivm/src/versions/era_vm/tests/get_used_contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ fn test_get_used_contracts() {
assert!(vm
.vm
.inner
.contract_storage
.state
.contracts_storage
.borrow()
.decommit(h256_to_u256(tx.bytecode_hash))
.is_ok());
Expand All @@ -51,7 +52,8 @@ fn test_get_used_contracts() {
assert_eq!(
vm.vm
.inner
.contract_storage
.state
.contracts_storage
.borrow()
.hash_map()
.unwrap()
Expand All @@ -64,7 +66,8 @@ fn test_get_used_contracts() {
assert_eq!(
vm.vm
.inner
.contract_storage
.state
.contracts_storage
.borrow()
.hash_map()
.unwrap()
Expand Down Expand Up @@ -108,7 +111,8 @@ fn test_get_used_contracts() {
assert!(!vm
.vm
.inner
.contract_storage
.state
.contracts_storage
.borrow()
.hash_map()
.unwrap()
Expand All @@ -120,7 +124,8 @@ fn test_get_used_contracts() {
fn known_bytecodes_without_aa_code<S: ReadStorage>(vm: &Vm<S>) -> HashSet<U256> {
let mut known_bytecodes_without_aa_code = vm
.inner
.contract_storage
.state
.contracts_storage
.borrow()
.hash_map()
.unwrap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ fn test_l1_tx_execution() {
let actual_value = vm
.vm
.inner
.state_storage
.state
.storage_changes
.map
.get(&zk_storage_key_to_lambda(&storage_location))
.unwrap();
assert_eq!(expected_value, *actual_value,);
Expand Down
38 changes: 19 additions & 19 deletions core/lib/multivm/src/versions/era_vm/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
// mod bootloader;
// mod bytecode_publishing;
// mod code_oracle;
// mod default_aa;
// mod gas_limit;
// mod get_used_contracts;
// mod is_write_initial;
// mod l1_tx_execution;
// mod l2_blocks;
// mod nonce_holder;
// mod refunds;
// mod require_eip712;
// mod rollbacks;
// mod sekp256r1;
// mod simple_execution;
// mod storage;
mod bootloader;
mod bytecode_publishing;
mod code_oracle;
mod default_aa;
mod gas_limit;
mod get_used_contracts;
mod is_write_initial;
mod l1_tx_execution;
mod l2_blocks;
mod nonce_holder;
mod refunds;
mod require_eip712;
mod rollbacks;
mod sekp256r1;
mod simple_execution;
mod storage;
mod tester;
// mod tracing_execution_error;
// mod transfer;
// mod upgrade;
mod tracing_execution_error;
mod transfer;
mod upgrade;
mod utils;
3 changes: 2 additions & 1 deletion core/lib/multivm/src/versions/era_vm/tests/require_eip712.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ impl VmTester {
);
self.vm
.inner
.state_storage
.state
.storage_changes
.map
.get(&zk_storage_key_to_lambda(&key))
.copied()
.unwrap_or_else(|| h256_to_u256(self.vm.storage.read_value(&key)))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{borrow::BorrowMut, cell::RefCell, collections::HashMap, rc::Rc};

use era_vm::rollbacks::{RollbackableHashMap, RollbackableVec};
use zksync_contracts::BaseSystemContracts;
use zksync_state::{InMemoryStorage, StoragePtr, WriteStorage};
use zksync_test_account::{Account, TxType};
Expand All @@ -22,7 +23,6 @@ use crate::{
},
vm_latest::{constants::BATCH_COMPUTATIONAL_GAS_LIMIT, utils::l2_blocks::load_last_l2_block},
};
use era_vm::rollbacks::{RollbackableHashMap, RollbackableVec};

pub(crate) struct VmTester {
pub(crate) vm: Vm<InMemoryStorage>,
Expand Down
2 changes: 1 addition & 1 deletion core/lib/multivm/src/versions/era_vm/tests/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ fn test_send_or_transfer(test_option: TestOptions) {
AccountTreeId::new(L2_BASE_TOKEN_ADDRESS),
&recipient_address,
&mut vm.vm.storage,
&vm.vm.inner.state_storage.storage_changes,
&vm.vm.inner.state.storage_changes.map,
);

assert_eq!(new_recipient_balance, value);
Expand Down
4 changes: 2 additions & 2 deletions core/lib/multivm/src/versions/era_vm/tests/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ fn test_force_deploy_upgrade() {
verify_required_storage(
&expected_slots,
&mut *vm.storage.borrow_mut(),
&vm.vm.inner.state_storage.storage_changes,
&vm.vm.inner.state.storage_changes.map,
);
}

Expand Down Expand Up @@ -224,7 +224,7 @@ fn test_complex_upgrader() {
verify_required_storage(
&expected_slots,
&mut *vm.storage.borrow_mut(),
&vm.vm.inner.state_storage.storage_changes,
&vm.vm.inner.state.storage_changes.map,
);
}

Expand Down
10 changes: 9 additions & 1 deletion core/lib/multivm/src/versions/era_vm/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ impl<S: ReadStorage + 'static> Vm<S> {
.collect()
}

pub(crate) fn read_word_from_bootloader_heap(&self, word: usize) -> U256 {
self.inner.execution.heaps.get(2).unwrap().read(word as u32)
}

pub(crate) fn insert_bytecodes<'a>(&mut self, bytecodes: impl IntoIterator<Item = &'a [u8]>) {
for code in bytecodes {
let mut program_code = vec![];
Expand Down Expand Up @@ -337,7 +341,7 @@ impl<S: ReadStorage + 'static> Vm<S> {
// #[cfg(test)]
/// Returns the current state of the VM in a format that can be compared for equality.
fn write_to_bootloader_heap(&mut self, memory: impl IntoIterator<Item = (usize, U256)>) {
pub fn write_to_bootloader_heap(&mut self, memory: impl IntoIterator<Item = (usize, U256)>) {
assert!(self.inner.execution.running_contexts.len() == 1); // No on-going far calls
if let Some(heap) = &mut self
.inner
Expand Down Expand Up @@ -608,6 +612,10 @@ impl<S: ReadStorage> era_vm::store::ContractStorage for World<S> {
.clone(),
))
}

fn hash_map(&self) -> Result<HashMap<U256, Vec<U256>>, StorageError> {
Ok(self.contract_storage.as_ref().clone().into_inner())
}
}

#[cfg(test)]
Expand Down

0 comments on commit 7667e7a

Please sign in to comment.