Skip to content

Commit

Permalink
Fix / update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
slowli committed Oct 16, 2024
1 parent 6968423 commit 3612a46
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 57 deletions.
7 changes: 3 additions & 4 deletions core/lib/multivm/src/versions/testonly/l1_tx_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,8 @@ pub(crate) fn test_l1_tx_execution<VM: TestedVm>() {
let res = vm.vm.execute(VmExecutionMode::OneTx);
let storage_logs = res.logs.storage_logs;
let res = StorageWritesDeduplicator::apply_on_empty_state(&storage_logs);
// We changed one slot inside contract. However, the rewrite of the `basePubdataSpent` didn't happen, since it was the same
// as the start of the previous tx. Thus we have `+1` slot for the changed counter and `-1` slot for base pubdata spent
assert_eq!(res.initial_storage_writes, basic_initial_writes);
// We changed one slot inside contract.
assert_eq!(res.initial_storage_writes - basic_initial_writes, 1);

// No repeated writes
let repeated_writes = res.repeated_storage_writes;
Expand All @@ -131,7 +130,7 @@ pub(crate) fn test_l1_tx_execution<VM: TestedVm>() {
assert!(result.result.is_failed(), "The transaction should fail");

let res = StorageWritesDeduplicator::apply_on_empty_state(&result.logs.storage_logs);
assert_eq!(res.initial_storage_writes, basic_initial_writes);
assert_eq!(res.initial_storage_writes, basic_initial_writes + 1);
assert_eq!(res.repeated_storage_writes, 1);
}

Expand Down
43 changes: 0 additions & 43 deletions core/lib/multivm/src/versions/testonly/migration.rs

This file was deleted.

7 changes: 2 additions & 5 deletions core/lib/multivm/src/versions/testonly/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use ethabi::Contract;
use once_cell::sync::Lazy;
use zksync_contracts::{
load_contract, read_bytecode, read_yul_bytecode, read_zbin_bytecode, BaseSystemContracts,
load_contract, read_bootloader_code, read_bytecode, read_zbin_bytecode, BaseSystemContracts,
SystemContractCode,
};
use zksync_test_account::Account;
Expand Down Expand Up @@ -38,7 +38,6 @@ pub(super) mod get_used_contracts;
pub(super) mod is_write_initial;
pub(super) mod l1_tx_execution;
pub(super) mod l2_blocks;
pub(super) mod migration;
pub(super) mod nonce_holder;
pub(super) mod precompiles;
pub(super) mod refunds;
Expand Down Expand Up @@ -125,9 +124,7 @@ pub(crate) fn read_simple_transfer_contract() -> Vec<u8> {
}

pub(crate) fn get_bootloader(test: &str) -> SystemContractCode {
let artifacts_path = "contracts/system-contracts/bootloader/tests/artifacts/";
let bootloader_code = read_yul_bytecode(artifacts_path, test);

let bootloader_code = read_bootloader_code(test);
let bootloader_hash = hash_bytecode(&bootloader_code);
SystemContractCode {
code: bytes_to_be_words(bootloader_code),
Expand Down
11 changes: 6 additions & 5 deletions core/lib/multivm/src/versions/testonly/nonce_holder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ fn run_nonce_test(

pub(crate) fn test_nonce_holder<VM: TestedVm>() {
let mut account = Account::random();
let hex_addr = hex::encode(account.address.to_fixed_bytes());
let mut vm = VmTesterBuilder::new()
.with_empty_in_memory_storage()
.with_execution_mode(TxExecutionMode::VerifyExecute)
Expand All @@ -90,7 +91,7 @@ pub(crate) fn test_nonce_holder<VM: TestedVm>() {
&mut account,
1u32,
NonceHolderTestMode::SetValueUnderNonce,
Some("Previous nonce has not been used".to_string()),
Some("Error function_selector = 0x13595475, data = 0x13595475".to_string()),
"Allowed to set value under non sequential value",
);

Expand Down Expand Up @@ -141,7 +142,7 @@ pub(crate) fn test_nonce_holder<VM: TestedVm>() {
&mut account,
10u32,
NonceHolderTestMode::IncreaseMinNonceBy5,
Some("Reusing the same nonce twice".to_string()),
Some(format!("Error function_selector = 0xe90aded4, data = 0xe90aded4000000000000000000000000{hex_addr}000000000000000000000000000000000000000000000000000000000000000a")),
"Allowed to reuse nonce below the minimal one",
);

Expand All @@ -161,7 +162,7 @@ pub(crate) fn test_nonce_holder<VM: TestedVm>() {
&mut account,
13u32,
NonceHolderTestMode::IncreaseMinNonceBy5,
Some("Reusing the same nonce twice".to_string()),
Some(format!("Error function_selector = 0xe90aded4, data = 0xe90aded4000000000000000000000000{hex_addr}000000000000000000000000000000000000000000000000000000000000000d")),
"Allowed to reuse the same nonce twice",
);

Expand All @@ -181,7 +182,7 @@ pub(crate) fn test_nonce_holder<VM: TestedVm>() {
&mut account,
16u32,
NonceHolderTestMode::IncreaseMinNonceTooMuch,
Some("The value for incrementing the nonce is too high".to_string()),
Some("Error function_selector = 0x45ac24a6, data = 0x45ac24a600000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000040000000000000000000000".to_string()),
"Allowed for incrementing min nonce too much",
);

Expand All @@ -191,7 +192,7 @@ pub(crate) fn test_nonce_holder<VM: TestedVm>() {
&mut account,
16u32,
NonceHolderTestMode::LeaveNonceUnused,
Some("The nonce was not set as used".to_string()),
Some(format!("Error function_selector = 0x1f2f8478, data = 0x1f2f8478000000000000000000000000{hex_addr}0000000000000000000000000000000000000000000000000000000000000010")),
"Allowed to leave nonce as unused",
);
}

0 comments on commit 3612a46

Please sign in to comment.