Skip to content

Commit

Permalink
fix bootloader tests
Browse files Browse the repository at this point in the history
  • Loading branch information
perekopskiy committed Oct 24, 2024
1 parent 37d1e0f commit fadb376
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 6 deletions.
7 changes: 7 additions & 0 deletions core/lib/multivm/src/versions/shadow/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ impl TestedVm for ShadowedFastVm {
})
}

fn finish_batch_without_pubdata(&mut self) -> VmExecutionResultAndLogs {
self.get_custom_mut("finish_batch_without_pubdata", |r| match r {
ShadowMut::Main(vm) => vm.finish_batch_without_pubdata(),
ShadowMut::Shadow(vm) => vm.finish_batch_without_pubdata(),
})
}

fn insert_bytecodes(&mut self, bytecodes: &[&[u8]]) {
self.get_mut("insert_bytecodes", |r| match r {
ShadowMut::Main(vm) => vm.insert_bytecodes(bytecodes),
Expand Down
7 changes: 3 additions & 4 deletions core/lib/multivm/src/versions/testonly/bootloader.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use assert_matches::assert_matches;
use zksync_types::U256;
use zksync_vm_interface::InspectExecutionMode;

use super::{get_bootloader, tester::VmTesterBuilder, TestedVm, BASE_SYSTEM_CONTRACTS};
use crate::interface::{ExecutionResult, Halt, TxExecutionMode, VmInterfaceExt};
use crate::interface::{ExecutionResult, Halt, TxExecutionMode};

pub(crate) fn test_dummy_bootloader<VM: TestedVm>() {
let mut base_system_contracts = BASE_SYSTEM_CONTRACTS.clone();
Expand All @@ -15,7 +14,7 @@ pub(crate) fn test_dummy_bootloader<VM: TestedVm>() {
.with_execution_mode(TxExecutionMode::VerifyExecute)
.build::<VM>();

let result = vm.vm.execute(InspectExecutionMode::Bootloader);
let result = vm.vm.finish_batch_without_pubdata();
assert!(!result.result.is_failed());

let correct_first_cell = U256::from_str_radix("123123123", 16).unwrap();
Expand All @@ -34,7 +33,7 @@ pub(crate) fn test_bootloader_out_of_gas<VM: TestedVm>() {
.with_execution_mode(TxExecutionMode::VerifyExecute)
.build::<VM>();

let res = vm.vm.execute(InspectExecutionMode::Bootloader);
let res = vm.vm.finish_batch_without_pubdata();

assert_matches!(
res.result,
Expand Down
2 changes: 2 additions & 0 deletions core/lib/multivm/src/versions/testonly/tester/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ pub(crate) trait TestedVm:
pubdata_builder: Rc<dyn PubdataBuilder>,
) -> VmExecutionResultAndLogs;

fn finish_batch_without_pubdata(&mut self) -> VmExecutionResultAndLogs;

fn insert_bytecodes(&mut self, bytecodes: &[&[u8]]);

/// Includes bytecodes that have failed to decommit. Should exclude base system contract bytecodes (default AA / EVM emulator).
Expand Down
6 changes: 5 additions & 1 deletion core/lib/multivm/src/versions/vm_fast/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use zksync_utils::h256_to_u256;
use zksync_vm2::interface::{Event, HeapId, StateInterface};
use zksync_vm_interface::{
pubdata::PubdataBuilder, storage::ReadStorage, CurrentExecutionState, L2BlockEnv,
VmExecutionResultAndLogs, VmInterface,
VmExecutionMode, VmExecutionResultAndLogs, VmInterface,
};

use super::Vm;
Expand Down Expand Up @@ -109,6 +109,10 @@ impl TestedVm for Vm<ImmutableStorageView<InMemoryStorage>> {
.block_tip_execution_result
}

fn finish_batch_without_pubdata(&mut self) -> VmExecutionResultAndLogs {
self.inspect_inner(&mut Default::default(), VmExecutionMode::Batch)
}

fn insert_bytecodes(&mut self, bytecodes: &[&[u8]]) {
self.insert_bytecodes(bytecodes.iter().copied())
}
Expand Down
2 changes: 1 addition & 1 deletion core/lib/multivm/src/versions/vm_fast/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ impl<S: ReadStorage, Tr: Tracer + Default> Vm<S, Tr> {
}
}

fn inspect_inner(
pub(crate) fn inspect_inner(
&mut self,
tracer: &mut Tr,
execution_mode: VmExecutionMode,
Expand Down
8 changes: 8 additions & 0 deletions core/lib/multivm/src/versions/vm_latest/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ impl TestedVm for TestedLatestVm {
)
}

fn finish_batch_without_pubdata(&mut self) -> VmExecutionResultAndLogs {
self.inspect_inner(
&mut TracerDispatcher::default(),
VmExecutionMode::Batch,
None,
)
}

fn insert_bytecodes(&mut self, bytecodes: &[&[u8]]) {
let bytecodes = bytecodes
.iter()
Expand Down

0 comments on commit fadb376

Please sign in to comment.