Skip to content

Commit

Permalink
test(vm): Run multivm tests with shadowing (#3137)
Browse files Browse the repository at this point in the history
## What ❔

Runs shared unit tests in the `multivm` crate for the shadowed VM.

## Why ❔

Allows to cheaply check VM divergences.

## Checklist

- [x] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [x] Tests for the changes have been added / updated.
- [x] Documentation comments have been added / updated.
- [x] Code has been formatted via `zkstack dev fmt` and `zkstack dev
lint`.
  • Loading branch information
slowli authored Oct 23, 2024
1 parent c79949b commit 84986f4
Show file tree
Hide file tree
Showing 11 changed files with 674 additions and 151 deletions.
2 changes: 2 additions & 0 deletions core/lib/multivm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ If you want to add unit tests for the VM wrapper, consider the following:
- Whenever possible, make tests reusable; declare test logic in the [`testonly`](src/versions/testonly/mod.rs) module,
and then instantiate tests using this logic for the supported VM versions. If necessary, extend the tested VM trait so
that test logic can be defined in a generic way. See the `testonly` module docs for more detailed guidelines.
- If you define a generic test, don't forget to add its instantiations for all supported VMs (`vm_latest`, `vm_fast` and
`shadow`). `shadow` tests allow checking VM divergences for free!
- Do not use an RNG where it can be avoided (e.g., for test contract addresses).
- Avoid using zero / default values in cases they can be treated specially by the tested code.
2 changes: 2 additions & 0 deletions core/lib/multivm/src/versions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#[cfg(test)]
mod shadow;
mod shared;
#[cfg(test)]
mod testonly;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ use crate::{
vm_latest::HistoryEnabled,
};

mod tests;

type ReferenceVm<S = InMemoryStorage> = vm_latest::Vm<StorageView<S>, HistoryEnabled>;
type ShadowedFastVm<S = InMemoryStorage> = crate::vm_instance::ShadowedFastVm<S>;

Expand Down
Loading

0 comments on commit 84986f4

Please sign in to comment.