Skip to content

Commit

Permalink
Add parallel execution test
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcosNicolau committed Aug 28, 2024
1 parent 52143c0 commit 19cc907
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/lib/multivm/src/versions/era_vm/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ mod is_write_initial;
mod l1_tx_execution;
mod l2_blocks;
mod nonce_holder;
mod parallel_execution;
mod precompiles;
mod refunds;
mod require_eip712;
Expand Down
73 changes: 73 additions & 0 deletions core/lib/multivm/src/versions/era_vm/tests/parallel_execution.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
use zksync_types::Transaction;

use super::tester::VmTester;
use crate::{
era_vm::tests::tester::{TxType, VmTesterBuilder},
interface::{VmExecutionMode, VmInterface},
};

fn prepare_test() -> (VmTester, [Transaction; 3]) {
let mut vm_tester = VmTesterBuilder::new()
.with_empty_in_memory_storage()
.with_deployer()
.with_random_rich_accounts(1)
.build();

vm_tester.deploy_test_contract();

let account = &mut vm_tester.rich_accounts[0];

let txs = [
account.get_test_contract_transaction(
vm_tester.test_contract.unwrap(),
false,
Default::default(),
false,
TxType::L1 { serial_id: 1 },
),
account.get_test_contract_transaction(
vm_tester.test_contract.unwrap(),
true,
Default::default(),
false,
TxType::L1 { serial_id: 1 },
),
account.get_test_contract_transaction(
vm_tester.test_contract.unwrap(),
false,
Default::default(),
false,
TxType::L1 { serial_id: 1 },
),
];

(vm_tester, txs)
}

#[test]
fn parallel_execution() {
let normal_execution = {
let (mut vm, txs) = prepare_test();
let vm = &mut vm.vm;
for tx in &txs {
vm.push_transaction_inner(tx.clone(), 0, true);
}
vm.execute(VmExecutionMode::Batch)
};

let parallel_execution = {
let (mut vm, txs) = prepare_test();
let vm = &mut vm.vm;
for tx in txs {
vm.push_parallel_transaction(tx, 0, true);
}
vm.execute_parallel()
};

// we don't assert if statistics are equal since that would require
// sharing the gas in parallel,
// assert!(1 == 2);
assert_eq!(normal_execution.logs, parallel_execution.logs);
// assert_eq!(normal_execution.result, parallel_execution.result);
// assert_eq!(normal_execution.refunds, parallel_execution.refunds);
}

0 comments on commit 19cc907

Please sign in to comment.