forked from matter-labs/zksync-era
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add basic test setup for era_vm #229
Closed
Closed
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
62d4e8b
Add basic test setup for era_vm
MarcosNicolau fbcdde8
Add bootloader test
MarcosNicolau 96e729f
Fix bootloader test
MarcosNicolau 96dc0be
Adapt utils test functions to era_vm
MarcosNicolau 7ebe3f6
Fix test util verify_required_storage
MarcosNicolau 1d3f68c
Add upgrade tests
MarcosNicolau 5465991
Add code_oracle tests
MarcosNicolau 9601ca9
Add default_aa tests
MarcosNicolau 8ac9e9a
Add gas_limit tests
MarcosNicolau 0f66a1b
Add is_write_initial test
MarcosNicolau ec1df4a
Add read_word_from_bootloader_heap to vm
MarcosNicolau 02b62ad
Add l1_tx_execution tests
MarcosNicolau 65222fa
Add bytecode_publishing and transfer tests
MarcosNicolau 0d780be
make and restore snapshots
juan518munoz c285a85
make and restore snapshots
juan518munoz b365644
add storage & tracing execution tests
juan518munoz 69524ff
add rollbacks, sekp & simple_execution
juan518munoz 8c74d62
Add nonce_holder & require_eip712 tests
MarcosNicolau 5cae6ed
Run zk fmt
MarcosNicolau 995eb86
Add refunds tests
MarcosNicolau c4590ba
fix test bytecode_publishing
juan518munoz 12eae0a
Add get_used_contracts tests
MarcosNicolau a517830
Add l2_blocks tests
MarcosNicolau 93ad045
Add todo!() to pubdatarequested hook
MarcosNicolau 0e8e466
Add NearCallCatch hook
MarcosNicolau 7066bdc
initial integration to world
juan518munoz 7667e7a
re-enable tests
juan518munoz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,26 @@ | ||
use zksync_types::l2_to_l1_log::{L2ToL1Log, SystemL2ToL1Log}; | ||
use zksync_utils::u256_to_h256; | ||
|
||
use crate::glue::GlueFrom; | ||
|
||
impl GlueFrom<&era_vm::state::L2ToL1Log> for SystemL2ToL1Log { | ||
fn glue_from(value: &era_vm::state::L2ToL1Log) -> Self { | ||
let era_vm::state::L2ToL1Log { | ||
key, | ||
value, | ||
is_service, | ||
address, | ||
shard_id, | ||
tx_number, | ||
} = *value; | ||
|
||
Self(L2ToL1Log { | ||
shard_id, | ||
is_service, | ||
tx_number_in_block: tx_number, | ||
sender: address, | ||
key: u256_to_h256(key), | ||
value: u256_to_h256(value), | ||
}) | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,8 +1,11 @@ | ||
pub mod bootloader_state; | ||
mod bytecode; | ||
mod event; | ||
mod glue; | ||
mod hook; | ||
mod initial_bootloader_memory; | ||
mod snapshot; | ||
#[cfg(test)] | ||
mod tests; | ||
mod transaction_data; | ||
pub mod vm; |
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
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,52 @@ | ||
use zksync_types::U256; | ||
|
||
use crate::{ | ||
interface::{ExecutionResult, Halt, TxExecutionMode, VmExecutionMode, VmInterface}, | ||
versions::era_vm::tests::{ | ||
tester::VmTesterBuilder, | ||
utils::{get_bootloader, verify_required_memory, BASE_SYSTEM_CONTRACTS}, | ||
}, | ||
}; | ||
|
||
#[test] | ||
fn test_dummy_bootloader() { | ||
let mut base_system_contracts = BASE_SYSTEM_CONTRACTS.clone(); | ||
base_system_contracts.bootloader = get_bootloader("dummy"); | ||
|
||
let mut vm = VmTesterBuilder::new() | ||
.with_empty_in_memory_storage() | ||
.with_base_system_smart_contracts(base_system_contracts) | ||
.with_execution_mode(TxExecutionMode::VerifyExecute) | ||
.build(); | ||
|
||
let result = vm.vm.execute(VmExecutionMode::Batch); | ||
assert!(!result.result.is_failed()); | ||
|
||
let correct_first_cell = U256::from_str_radix("123123123", 16).unwrap(); | ||
|
||
verify_required_memory( | ||
&vm.vm.inner.execution, | ||
vec![(correct_first_cell, vm2::FIRST_HEAP, 0)], | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_bootloader_out_of_gas() { | ||
let mut base_system_contracts = BASE_SYSTEM_CONTRACTS.clone(); | ||
base_system_contracts.bootloader = get_bootloader("dummy"); | ||
|
||
let mut vm = VmTesterBuilder::new() | ||
.with_empty_in_memory_storage() | ||
.with_base_system_smart_contracts(base_system_contracts) | ||
.with_bootloader_gas_limit(10) | ||
.with_execution_mode(TxExecutionMode::VerifyExecute) | ||
.build(); | ||
|
||
let res = vm.vm.execute(VmExecutionMode::Batch); | ||
assert!(matches!( | ||
res.result, | ||
ExecutionResult::Halt { | ||
reason: Halt::BootloaderOutOfGas | ||
} | ||
)); | ||
} |
40 changes: 40 additions & 0 deletions
40
core/lib/multivm/src/versions/era_vm/tests/bytecode_publishing.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,40 @@ | ||
use zksync_types::event::extract_long_l2_to_l1_messages; | ||
use zksync_utils::bytecode::compress_bytecode; | ||
|
||
use crate::{ | ||
era_vm::tests::{ | ||
tester::{DeployContractsTx, TxType, VmTesterBuilder}, | ||
utils::read_test_contract, | ||
}, | ||
interface::{TxExecutionMode, VmExecutionMode, VmInterface}, | ||
}; | ||
|
||
#[test] | ||
fn test_bytecode_publishing() { | ||
// In this test, we aim to ensure that the contents of the compressed bytecodes | ||
// are included as part of the L2->L1 long messages | ||
let mut vm = VmTesterBuilder::new() | ||
.with_empty_in_memory_storage() | ||
.with_execution_mode(TxExecutionMode::VerifyExecute) | ||
.with_random_rich_accounts(1) | ||
.build(); | ||
|
||
let counter = read_test_contract(); | ||
let account = &mut vm.rich_accounts[0]; | ||
|
||
let compressed_bytecode = compress_bytecode(&counter).unwrap(); | ||
|
||
let DeployContractsTx { tx, .. } = account.get_deploy_tx(&counter, None, TxType::L2); | ||
vm.vm.push_transaction(tx); | ||
let result = vm.vm.execute(VmExecutionMode::OneTx); | ||
assert!(!result.result.is_failed(), "Transaction wasn't successful"); | ||
|
||
vm.vm.execute(VmExecutionMode::Batch); | ||
|
||
let state = vm.vm.get_current_execution_state(); | ||
let long_messages = extract_long_l2_to_l1_messages(&state.events); | ||
assert!( | ||
long_messages.contains(&compressed_bytecode), | ||
"Bytecode not published" | ||
); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will not work when zksync-era is used as a submodule for era_vm, believe me I've tried. Please restore this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When developing, we can modify this as needed.