forked from matter-labs/zksync-era
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
52143c0
commit 19cc907
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
core/lib/multivm/src/versions/era_vm/tests/parallel_execution.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |