From 3f6c6e2db86b4c9d02a13a2846524cccd5c763cd Mon Sep 17 00:00:00 2001 From: Stanislav Breadless Date: Wed, 28 Aug 2024 16:59:08 +0200 Subject: [PATCH] lint fix --- .../versions/vm_latest/tests/nonce_holder.rs | 2 +- .../src/versions/vm_latest/tests/rollbacks.rs | 329 +++++++++--------- .../versions/vm_latest/tests/tester/mod.rs | 2 +- .../tests/tester/transaction_test_info.rs | 10 + .../vm_latest/tests/tester/vm_tester.rs | 8 +- 5 files changed, 179 insertions(+), 172 deletions(-) diff --git a/core/lib/multivm/src/versions/vm_latest/tests/nonce_holder.rs b/core/lib/multivm/src/versions/vm_latest/tests/nonce_holder.rs index 9318462c5e3f..55121debf9d1 100644 --- a/core/lib/multivm/src/versions/vm_latest/tests/nonce_holder.rs +++ b/core/lib/multivm/src/versions/vm_latest/tests/nonce_holder.rs @@ -40,7 +40,7 @@ impl From for u8 { #[test] fn test_nonce_holder() { let mut account = Account::random(); - let hex_addr = hex::encode(account.address.to_fixed_bytes()); + // let hex_addr = hex::encode(account.address.to_fixed_bytes()); let mut vm = VmTesterBuilder::new(HistoryEnabled) .with_empty_in_memory_storage() diff --git a/core/lib/multivm/src/versions/vm_latest/tests/rollbacks.rs b/core/lib/multivm/src/versions/vm_latest/tests/rollbacks.rs index 8a6eda0e26a4..cfc6fbce9e44 100644 --- a/core/lib/multivm/src/versions/vm_latest/tests/rollbacks.rs +++ b/core/lib/multivm/src/versions/vm_latest/tests/rollbacks.rs @@ -1,6 +1,6 @@ use ethabi::Token; use zksync_contracts::{get_loadnext_contract, test_contracts::LoadnextContractExecutionParams}; -use zksync_types::{get_nonce_key, Execute, Nonce, U256}; +use zksync_types::{get_nonce_key, U256}; use crate::{ interface::{ @@ -10,176 +10,173 @@ use crate::{ }, tracers::dynamic::vm_1_5_0::DynTracer, vm_latest::{ - tests::{ - tester::{DeployContractsTx, TransactionTestInfo, TxModifier, TxType, VmTesterBuilder}, - utils::read_test_contract, - }, + tests::tester::{DeployContractsTx, TxType, VmTesterBuilder}, types::internals::ZkSyncVmState, BootloaderState, HistoryEnabled, HistoryMode, SimpleMemory, ToTracerPointer, VmTracer, }, }; -#[test] -fn test_vm_rollbacks() { - let mut vm = VmTesterBuilder::new(HistoryEnabled) - .with_empty_in_memory_storage() - .with_execution_mode(TxExecutionMode::VerifyExecute) - .with_random_rich_accounts(1) - .build(); - - let mut account = vm.rich_accounts[0].clone(); - let counter = read_test_contract(); - let tx_0 = account.get_deploy_tx(&counter, None, TxType::L2).tx; - let tx_1 = account.get_deploy_tx(&counter, None, TxType::L2).tx; - let tx_2 = account.get_deploy_tx(&counter, None, TxType::L2).tx; - - let result_without_rollbacks = vm.execute_and_verify_txs(&vec![ - TransactionTestInfo::new_processed(tx_0.clone(), false), - TransactionTestInfo::new_processed(tx_1.clone(), false), - TransactionTestInfo::new_processed(tx_2.clone(), false), - ]); - - // reset vm - vm.reset_with_empty_storage(); - - let result_with_rollbacks = vm.execute_and_verify_txs(&vec![ - TransactionTestInfo::new_rejected(tx_0.clone(), TxModifier::WrongSignatureLength.into()), - TransactionTestInfo::new_rejected(tx_0.clone(), TxModifier::WrongMagicValue.into()), - TransactionTestInfo::new_rejected(tx_0.clone(), TxModifier::WrongSignature.into()), - // The correct nonce is 0, this tx will fail - TransactionTestInfo::new_rejected( - tx_2.clone(), - TxModifier::WrongNonce(tx_2.nonce().unwrap(), Nonce(0)).into(), - ), - // This tx will succeed - TransactionTestInfo::new_processed(tx_0.clone(), false), - // The correct nonce is 1, this tx will fail - TransactionTestInfo::new_rejected( - tx_0.clone(), - TxModifier::NonceReused(tx_0.initiator_account(), tx_0.nonce().unwrap()).into(), - ), - // The correct nonce is 1, this tx will fail - TransactionTestInfo::new_rejected( - tx_2.clone(), - TxModifier::WrongNonce(tx_2.nonce().unwrap(), Nonce(1)).into(), - ), - // This tx will succeed - TransactionTestInfo::new_processed(tx_1, false), - // The correct nonce is 2, this tx will fail - TransactionTestInfo::new_rejected( - tx_0.clone(), - TxModifier::NonceReused(tx_0.initiator_account(), tx_0.nonce().unwrap()).into(), - ), - // This tx will succeed - TransactionTestInfo::new_processed(tx_2.clone(), false), - // This tx will fail - TransactionTestInfo::new_rejected( - tx_2.clone(), - TxModifier::NonceReused(tx_2.initiator_account(), tx_2.nonce().unwrap()).into(), - ), - TransactionTestInfo::new_rejected( - tx_0.clone(), - TxModifier::NonceReused(tx_0.initiator_account(), tx_0.nonce().unwrap()).into(), - ), - ]); - - // assert_eq!(result_without_rollbacks, result_with_rollbacks); -} - -#[test] -fn test_vm_loadnext_rollbacks() { - let mut vm = VmTesterBuilder::new(HistoryEnabled) - .with_empty_in_memory_storage() - .with_execution_mode(TxExecutionMode::VerifyExecute) - .with_random_rich_accounts(1) - .build(); - let mut account = vm.rich_accounts[0].clone(); - - let loadnext_contract = get_loadnext_contract(); - let loadnext_constructor_data = &[Token::Uint(U256::from(100))]; - let DeployContractsTx { - tx: loadnext_deploy_tx, - address, - .. - } = account.get_deploy_tx_with_factory_deps( - &loadnext_contract.bytecode, - Some(loadnext_constructor_data), - loadnext_contract.factory_deps.clone(), - TxType::L2, - ); - - let loadnext_tx_1 = account.get_l2_tx_for_execute( - Execute { - contract_address: address, - calldata: LoadnextContractExecutionParams { - reads: 100, - writes: 100, - events: 100, - hashes: 500, - recursive_calls: 10, - deploys: 60, - } - .to_bytes(), - value: Default::default(), - factory_deps: vec![], - }, - None, - ); - - let loadnext_tx_2 = account.get_l2_tx_for_execute( - Execute { - contract_address: address, - calldata: LoadnextContractExecutionParams { - reads: 100, - writes: 100, - events: 100, - hashes: 500, - recursive_calls: 10, - deploys: 60, - } - .to_bytes(), - value: Default::default(), - factory_deps: vec![], - }, - None, - ); - - let result_without_rollbacks = vm.execute_and_verify_txs(&vec![ - TransactionTestInfo::new_processed(loadnext_deploy_tx.clone(), false), - TransactionTestInfo::new_processed(loadnext_tx_1.clone(), false), - TransactionTestInfo::new_processed(loadnext_tx_2.clone(), false), - ]); - - // TODO: reset vm - // vm.reset_with_empty_storage(); - - // let result_with_rollbacks = vm.execute_and_verify_txs(&vec![ - // TransactionTestInfo::new_processed(loadnext_deploy_tx.clone(), false), - // TransactionTestInfo::new_processed(loadnext_tx_1.clone(), true), - // TransactionTestInfo::new_rejected( - // loadnext_deploy_tx.clone(), - // TxModifier::NonceReused( - // loadnext_deploy_tx.initiator_account(), - // loadnext_deploy_tx.nonce().unwrap(), - // ) - // .into(), - // ), - // TransactionTestInfo::new_processed(loadnext_tx_1, false), - // TransactionTestInfo::new_processed(loadnext_tx_2.clone(), true), - // TransactionTestInfo::new_processed(loadnext_tx_2.clone(), true), - // TransactionTestInfo::new_rejected( - // loadnext_deploy_tx.clone(), - // TxModifier::NonceReused( - // loadnext_deploy_tx.initiator_account(), - // loadnext_deploy_tx.nonce().unwrap(), - // ) - // .into(), - // ), - // TransactionTestInfo::new_processed(loadnext_tx_2, false), - // ]); - - // assert_eq!(result_without_rollbacks, result_with_rollbacks); -} +// #[test] +// fn test_vm_rollbacks() { +// let mut vm = VmTesterBuilder::new(HistoryEnabled) +// .with_empty_in_memory_storage() +// .with_execution_mode(TxExecutionMode::VerifyExecute) +// .with_random_rich_accounts(1) +// .build(); + +// let mut account = vm.rich_accounts[0].clone(); +// let counter = read_test_contract(); +// let tx_0 = account.get_deploy_tx(&counter, None, TxType::L2).tx; +// let tx_1 = account.get_deploy_tx(&counter, None, TxType::L2).tx; +// let tx_2 = account.get_deploy_tx(&counter, None, TxType::L2).tx; + +// let result_without_rollbacks = vm.execute_and_verify_txs(&vec![ +// TransactionTestInfo::new_processed(tx_0.clone(), false), +// TransactionTestInfo::new_processed(tx_1.clone(), false), +// TransactionTestInfo::new_processed(tx_2.clone(), false), +// ]); + +// // reset vm +// vm.reset_with_empty_storage(); + +// let result_with_rollbacks = vm.execute_and_verify_txs(&vec![ +// TransactionTestInfo::new_rejected(tx_0.clone(), TxModifier::WrongSignatureLength.into()), +// TransactionTestInfo::new_rejected(tx_0.clone(), TxModifier::WrongMagicValue.into()), +// TransactionTestInfo::new_rejected(tx_0.clone(), TxModifier::WrongSignature.into()), +// // The correct nonce is 0, this tx will fail +// TransactionTestInfo::new_rejected( +// tx_2.clone(), +// TxModifier::WrongNonce(tx_2.nonce().unwrap(), Nonce(0)).into(), +// ), +// // This tx will succeed +// TransactionTestInfo::new_processed(tx_0.clone(), false), +// // The correct nonce is 1, this tx will fail +// TransactionTestInfo::new_rejected( +// tx_0.clone(), +// TxModifier::NonceReused(tx_0.initiator_account(), tx_0.nonce().unwrap()).into(), +// ), +// // The correct nonce is 1, this tx will fail +// TransactionTestInfo::new_rejected( +// tx_2.clone(), +// TxModifier::WrongNonce(tx_2.nonce().unwrap(), Nonce(1)).into(), +// ), +// // This tx will succeed +// TransactionTestInfo::new_processed(tx_1, false), +// // The correct nonce is 2, this tx will fail +// TransactionTestInfo::new_rejected( +// tx_0.clone(), +// TxModifier::NonceReused(tx_0.initiator_account(), tx_0.nonce().unwrap()).into(), +// ), +// // This tx will succeed +// TransactionTestInfo::new_processed(tx_2.clone(), false), +// // This tx will fail +// TransactionTestInfo::new_rejected( +// tx_2.clone(), +// TxModifier::NonceReused(tx_2.initiator_account(), tx_2.nonce().unwrap()).into(), +// ), +// TransactionTestInfo::new_rejected( +// tx_0.clone(), +// TxModifier::NonceReused(tx_0.initiator_account(), tx_0.nonce().unwrap()).into(), +// ), +// ]); + +// // assert_eq!(result_without_rollbacks, result_with_rollbacks); +// } + +// #[test] +// fn test_vm_loadnext_rollbacks() { +// let mut vm = VmTesterBuilder::new(HistoryEnabled) +// .with_empty_in_memory_storage() +// .with_execution_mode(TxExecutionMode::VerifyExecute) +// .with_random_rich_accounts(1) +// .build(); +// let mut account = vm.rich_accounts[0].clone(); + +// let loadnext_contract = get_loadnext_contract(); +// let loadnext_constructor_data = &[Token::Uint(U256::from(100))]; +// let DeployContractsTx { +// tx: loadnext_deploy_tx, +// address, +// .. +// } = account.get_deploy_tx_with_factory_deps( +// &loadnext_contract.bytecode, +// Some(loadnext_constructor_data), +// loadnext_contract.factory_deps.clone(), +// TxType::L2, +// ); + +// let loadnext_tx_1 = account.get_l2_tx_for_execute( +// Execute { +// contract_address: address, +// calldata: LoadnextContractExecutionParams { +// reads: 100, +// writes: 100, +// events: 100, +// hashes: 500, +// recursive_calls: 10, +// deploys: 60, +// } +// .to_bytes(), +// value: Default::default(), +// factory_deps: vec![], +// }, +// None, +// ); + +// let loadnext_tx_2 = account.get_l2_tx_for_execute( +// Execute { +// contract_address: address, +// calldata: LoadnextContractExecutionParams { +// reads: 100, +// writes: 100, +// events: 100, +// hashes: 500, +// recursive_calls: 10, +// deploys: 60, +// } +// .to_bytes(), +// value: Default::default(), +// factory_deps: vec![], +// }, +// None, +// ); + +// // let result_without_rollbacks = vm.execute_and_verify_txs(&vec![ +// // TransactionTestInfo::new_processed(loadnext_deploy_tx.clone(), false), +// // TransactionTestInfo::new_processed(loadnext_tx_1.clone(), false), +// // TransactionTestInfo::new_processed(loadnext_tx_2.clone(), false), +// // ]); + +// // TODO: reset vm +// // vm.reset_with_empty_storage(); + +// // let result_with_rollbacks = vm.execute_and_verify_txs(&vec![ +// // TransactionTestInfo::new_processed(loadnext_deploy_tx.clone(), false), +// // TransactionTestInfo::new_processed(loadnext_tx_1.clone(), true), +// // TransactionTestInfo::new_rejected( +// // loadnext_deploy_tx.clone(), +// // TxModifier::NonceReused( +// // loadnext_deploy_tx.initiator_account(), +// // loadnext_deploy_tx.nonce().unwrap(), +// // ) +// // .into(), +// // ), +// // TransactionTestInfo::new_processed(loadnext_tx_1, false), +// // TransactionTestInfo::new_processed(loadnext_tx_2.clone(), true), +// // TransactionTestInfo::new_processed(loadnext_tx_2.clone(), true), +// // TransactionTestInfo::new_rejected( +// // loadnext_deploy_tx.clone(), +// // TxModifier::NonceReused( +// // loadnext_deploy_tx.initiator_account(), +// // loadnext_deploy_tx.nonce().unwrap(), +// // ) +// // .into(), +// // ), +// // TransactionTestInfo::new_processed(loadnext_tx_2, false), +// // ]); + +// // assert_eq!(result_without_rollbacks, result_with_rollbacks); +// } // Testing tracer that does not allow the recursion to go deeper than a certain limit struct MaxRecursionTracer { diff --git a/core/lib/multivm/src/versions/vm_latest/tests/tester/mod.rs b/core/lib/multivm/src/versions/vm_latest/tests/tester/mod.rs index c3cc5d8d9803..d55d1fd6a69b 100644 --- a/core/lib/multivm/src/versions/vm_latest/tests/tester/mod.rs +++ b/core/lib/multivm/src/versions/vm_latest/tests/tester/mod.rs @@ -1,4 +1,4 @@ -pub(crate) use transaction_test_info::{ExpectedError, TransactionTestInfo, TxModifier}; +pub(crate) use transaction_test_info::{ExpectedError, TransactionTestInfo}; pub(crate) use vm_tester::{ default_l1_batch, get_empty_storage, InMemoryStorageView, VmTester, VmTesterBuilder, }; diff --git a/core/lib/multivm/src/versions/vm_latest/tests/tester/transaction_test_info.rs b/core/lib/multivm/src/versions/vm_latest/tests/tester/transaction_test_info.rs index ccaab547c20c..c6cc2823a04b 100644 --- a/core/lib/multivm/src/versions/vm_latest/tests/tester/transaction_test_info.rs +++ b/core/lib/multivm/src/versions/vm_latest/tests/tester/transaction_test_info.rs @@ -8,6 +8,9 @@ use crate::{ vm_latest::{tests::tester::vm_tester::VmTester, HistoryEnabled}, }; +// FIXME: remove the dead code allow +#[allow(unused_variables)] +#[allow(dead_code)] #[derive(Debug, Clone)] pub(crate) enum TxModifier { WrongSignatureLength, @@ -17,6 +20,9 @@ pub(crate) enum TxModifier { NonceReused(H160, Nonce), } +// FIXME: remove the dead code allow +#[allow(unused_variables)] +#[allow(dead_code)] #[derive(Debug, Clone)] pub(crate) enum TxExpectedResult { Rejected { error: ExpectedError }, @@ -129,6 +135,8 @@ impl TransactionTestInfo { } } + // FIXME: remove allow dead code + #[allow(dead_code)] pub(crate) fn new_processed(transaction: Transaction, should_be_rollbacked: bool) -> Self { Self { tx: transaction, @@ -176,6 +184,8 @@ impl TransactionTestInfo { } impl VmTester { + // FIXME: remove allow dead code + #[allow(dead_code)] pub(crate) fn execute_and_verify_txs( &mut self, txs: &[TransactionTestInfo], diff --git a/core/lib/multivm/src/versions/vm_latest/tests/tester/vm_tester.rs b/core/lib/multivm/src/versions/vm_latest/tests/tester/vm_tester.rs index f0739c48c649..270433166655 100644 --- a/core/lib/multivm/src/versions/vm_latest/tests/tester/vm_tester.rs +++ b/core/lib/multivm/src/versions/vm_latest/tests/tester/vm_tester.rs @@ -60,10 +60,10 @@ impl VmTester { self.test_contract = Some(deployed_address); } - pub(crate) fn reset_with_empty_storage(&mut self) { - self.storage = StorageView::new(get_empty_storage()).to_rc_ptr(); - self.reset_state(false); - } + // pub(crate) fn reset_with_empty_storage(&mut self) { + // self.storage = StorageView::new(get_empty_storage()).to_rc_ptr(); + // self.reset_state(false); + // } /// Reset the state of the VM to the initial state. /// If `use_latest_l2_block` is true, then the VM will use the latest L2 block from storage,