Skip to content

Commit

Permalink
modify underlying storage, not storage overlay in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joonazan committed Sep 26, 2024
1 parent dd425f9 commit 9078e12
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
24 changes: 12 additions & 12 deletions core/lib/multivm/src/utils/call_tracer_test_output
Original file line number Diff line number Diff line change
Expand Up @@ -9887,12 +9887,12 @@
0,
0,
6,
239,
235,
118,
196,
176,
190,
240,
1,
28,
35,
60,
110,
0
],
"output": [],
Expand Down Expand Up @@ -10277,12 +10277,12 @@
0,
0,
6,
239,
235,
118,
196,
176,
190,
240,
1,
28,
35,
60,
110,
0
],
"output": [],
Expand Down
30 changes: 16 additions & 14 deletions core/lib/multivm/src/versions/vm_latest/tests/tester/vm_tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use zksync_utils::{bytecode::hash_bytecode, u256_to_h256};

use crate::{
interface::{
storage::{InMemoryStorage, StoragePtr, StorageView, WriteStorage},
storage::{InMemoryStorage, StoragePtr, StorageView},
L1BatchEnv, L2Block, L2BlockEnv, SystemEnv, TxExecutionMode, VmExecutionMode, VmFactory,
VmInterface, VmInterfaceExt,
},
Expand Down Expand Up @@ -60,7 +60,15 @@ impl<H: HistoryMode> VmTester<H> {
}

pub(crate) fn reset_with_empty_storage(&mut self) {
self.storage = StorageView::new(get_empty_storage()).to_rc_ptr();
let mut raw_storage = get_empty_storage();
for account in self.rich_accounts.iter() {
make_account_rich(&mut raw_storage, account);
}
if let Some(deployer) = &self.deployer {
make_account_rich(&mut raw_storage, deployer);
}
self.storage = StorageView::new(raw_storage).to_rc_ptr();

self.reset_state(false);
}

Expand All @@ -70,10 +78,6 @@ impl<H: HistoryMode> VmTester<H> {
pub(crate) fn reset_state(&mut self, use_latest_l2_block: bool) {
for account in self.rich_accounts.iter_mut() {
account.nonce = Nonce(0);
make_account_rich(self.storage.clone(), account);
}
if let Some(deployer) = &self.deployer {
make_account_rich(self.storage.clone(), deployer);
}

if !self.custom_contracts.is_empty() {
Expand Down Expand Up @@ -229,15 +233,16 @@ impl<H: HistoryMode> VmTesterBuilder<H> {

let mut raw_storage = self.storage.unwrap_or_else(get_empty_storage);
insert_contracts(&mut raw_storage, &self.custom_contracts);
let storage_ptr = StorageView::new(raw_storage).to_rc_ptr();

for account in self.rich_accounts.iter() {
make_account_rich(storage_ptr.clone(), account);
make_account_rich(&mut raw_storage, account);
}
if let Some(deployer) = &self.deployer {
make_account_rich(storage_ptr.clone(), deployer);
make_account_rich(&mut raw_storage, deployer);
}
let fee_account = l1_batch_env.fee_account;

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

VmTester {
Expand All @@ -253,12 +258,9 @@ impl<H: HistoryMode> VmTesterBuilder<H> {
}
}

pub(crate) fn make_account_rich(storage: StoragePtr<InMemoryStorageView>, account: &Account) {
pub fn make_account_rich(storage: &mut InMemoryStorage, account: &Account) {
let key = storage_key_for_eth_balance(&account.address);
storage
.as_ref()
.borrow_mut()
.set_value(key, u256_to_h256(U256::from(10u64.pow(19))));
storage.set_value(key, u256_to_h256(U256::from(10u64.pow(19))));
}

pub(crate) fn get_empty_storage() -> InMemoryStorage {
Expand Down

0 comments on commit 9078e12

Please sign in to comment.