Skip to content

Commit

Permalink
Mock L1 batch insertion for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
perekopskiy committed Jan 16, 2024
1 parent 299f2ea commit 1f1e5d7
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 144 deletions.
11 changes: 2 additions & 9 deletions core/bin/snapshots_creator/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use rand::{thread_rng, Rng};
use zksync_dal::StorageProcessor;
use zksync_object_store::ObjectStore;
use zksync_types::{
block::{BlockGasCount, L1BatchHeader, MiniblockHeader},
block::{L1BatchHeader, MiniblockHeader},
snapshots::{
SnapshotFactoryDependencies, SnapshotFactoryDependency, SnapshotStorageLog,
SnapshotStorageLogsChunk, SnapshotStorageLogsStorageKey,
Expand Down Expand Up @@ -172,14 +172,7 @@ async fn create_l1_batch(
);
header.is_finished = true;
conn.blocks_dal()
.insert_l1_batch(
&header,
&[],
BlockGasCount::default(),
&[],
&[],
Default::default(),
)
.insert_mock_l1_batch(&header)
.await
.unwrap();
conn.blocks_dal()
Expand Down
21 changes: 13 additions & 8 deletions core/lib/dal/src/blocks_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2287,6 +2287,18 @@ impl BlocksDal<'_, '_> {
Ok(())
}

pub async fn insert_mock_l1_batch(&mut self, header: &L1BatchHeader) -> anyhow::Result<()> {
self.insert_l1_batch(
header,
&[],
Default::default(),
&[],
&[],
Default::default(),
)
.await
}

/// Deletes all miniblocks and L1 batches, including the genesis ones. Should only be used in tests.
pub async fn delete_genesis(&mut self) -> anyhow::Result<()> {
self.delete_miniblocks_inner(None)
Expand Down Expand Up @@ -2346,14 +2358,7 @@ mod tests {
header.l2_to_l1_messages.push(vec![33; 33]);

conn.blocks_dal()
.insert_l1_batch(
&header,
&[],
BlockGasCount::default(),
&[],
&[],
Default::default(),
)
.insert_mock_l1_batch(&header)
.await
.unwrap();

Expand Down
14 changes: 2 additions & 12 deletions core/lib/dal/src/storage_logs_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -709,10 +709,7 @@ impl StorageLogsDal<'_, '_> {
#[cfg(test)]
mod tests {
use zksync_contracts::BaseSystemContractsHashes;
use zksync_types::{
block::{BlockGasCount, L1BatchHeader},
ProtocolVersion, ProtocolVersionId,
};
use zksync_types::{block::L1BatchHeader, ProtocolVersion, ProtocolVersionId};

use super::*;
use crate::{tests::create_miniblock_header, ConnectionPool};
Expand All @@ -733,14 +730,7 @@ mod tests {
);
header.is_finished = true;
conn.blocks_dal()
.insert_l1_batch(
&header,
&[],
BlockGasCount::default(),
&[],
&[],
Default::default(),
)
.insert_mock_l1_batch(&header)
.await
.unwrap();
conn.blocks_dal()
Expand Down
23 changes: 4 additions & 19 deletions core/lib/dal/src/sync_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,8 @@ impl SyncDal<'_, '_> {
#[cfg(test)]
mod tests {
use zksync_types::{
block::{BlockGasCount, L1BatchHeader},
fee::TransactionExecutionMetrics,
L1BatchNumber, ProtocolVersion, ProtocolVersionId,
block::L1BatchHeader, fee::TransactionExecutionMetrics, L1BatchNumber, ProtocolVersion,
ProtocolVersionId,
};

use super::*;
Expand Down Expand Up @@ -136,14 +135,7 @@ mod tests {
ProtocolVersionId::latest(),
);
conn.blocks_dal()
.insert_l1_batch(
&l1_batch_header,
&[],
BlockGasCount::default(),
&[],
&[],
Default::default(),
)
.insert_mock_l1_batch(&l1_batch_header)
.await
.unwrap();
conn.blocks_dal()
Expand Down Expand Up @@ -218,14 +210,7 @@ mod tests {
l1_batch_header.number = L1BatchNumber(1);
l1_batch_header.timestamp = 1;
conn.blocks_dal()
.insert_l1_batch(
&l1_batch_header,
&[],
BlockGasCount::default(),
&[],
&[],
Default::default(),
)
.insert_mock_l1_batch(&l1_batch_header)
.await
.unwrap();
conn.blocks_dal()
Expand Down
11 changes: 2 additions & 9 deletions core/lib/state/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::ops;

use zksync_dal::StorageProcessor;
use zksync_types::{
block::{BlockGasCount, L1BatchHeader, MiniblockHeader},
block::{L1BatchHeader, MiniblockHeader},
AccountTreeId, Address, L1BatchNumber, MiniblockNumber, ProtocolVersion, StorageKey,
StorageLog, H256,
};
Expand Down Expand Up @@ -104,14 +104,7 @@ pub(crate) async fn create_l1_batch(
);
header.is_finished = true;
conn.blocks_dal()
.insert_l1_batch(
&header,
&[],
BlockGasCount::default(),
&[],
&[],
Default::default(),
)
.insert_mock_l1_batch(&header)
.await
.unwrap();
conn.blocks_dal()
Expand Down
13 changes: 1 addition & 12 deletions core/lib/zksync_core/src/api_server/web3/tests/snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
use std::collections::HashSet;

use zksync_types::block::BlockGasCount;
use zksync_web3_decl::namespaces::SnapshotsNamespaceClient;

use super::*;
Expand All @@ -13,17 +12,7 @@ async fn seal_l1_batch(
number: L1BatchNumber,
) -> anyhow::Result<()> {
let header = create_l1_batch(number.0);
storage
.blocks_dal()
.insert_l1_batch(
&header,
&[],
BlockGasCount::default(),
&[],
&[],
Default::default(),
)
.await?;
storage.blocks_dal().insert_mock_l1_batch(&header).await?;
storage
.blocks_dal()
.mark_miniblocks_as_executed_in_l1_batch(number)
Expand Down
14 changes: 3 additions & 11 deletions core/lib/zksync_core/src/consistency_checker/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ use tokio::sync::mpsc;
use zksync_dal::StorageProcessor;
use zksync_eth_client::clients::MockEthereum;
use zksync_types::{
aggregated_operations::AggregatedActionType, block::BlockGasCount,
commitment::L1BatchWithMetadata, web3::contract::Options, L2ChainId, ProtocolVersion,
ProtocolVersionId, H256,
aggregated_operations::AggregatedActionType, commitment::L1BatchWithMetadata,
web3::contract::Options, L2ChainId, ProtocolVersion, ProtocolVersionId, H256,
};

use super::*;
Expand Down Expand Up @@ -195,14 +194,7 @@ impl SaveAction<'_> {
Self::InsertBatch(l1_batch) => {
storage
.blocks_dal()
.insert_l1_batch(
&l1_batch.header,
&[],
BlockGasCount::default(),
&[],
&[],
Default::default(),
)
.insert_mock_l1_batch(&l1_batch.header)
.await
.unwrap();
}
Expand Down
9 changes: 1 addition & 8 deletions core/lib/zksync_core/src/eth_sender/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -887,14 +887,7 @@ async fn insert_l1_batch(tester: &EthSenderTester, number: L1BatchNumber) -> L1B
.storage()
.await
.blocks_dal()
.insert_l1_batch(
&header,
&[],
Default::default(),
&[],
&[],
Default::default(),
)
.insert_mock_l1_batch(&header)
.await
.unwrap();
tester
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,14 +400,7 @@ async fn prepare_clean_recovery_snapshot(
);
storage
.blocks_dal()
.insert_l1_batch(
&l1_batch,
&[],
Default::default(),
&[],
&[],
Default::default(),
)
.insert_mock_l1_batch(&l1_batch)
.await
.unwrap();

Expand Down
33 changes: 5 additions & 28 deletions core/lib/zksync_core/src/metadata_calculator/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ use zksync_health_check::{CheckHealth, HealthStatus};
use zksync_merkle_tree::domain::ZkSyncTree;
use zksync_object_store::{ObjectStore, ObjectStoreFactory};
use zksync_types::{
block::{BlockGasCount, L1BatchHeader},
proofs::PrepareBasicCircuitsJob,
AccountTreeId, Address, L1BatchNumber, L2ChainId, MiniblockNumber, StorageKey, StorageLog,
H256,
block::L1BatchHeader, proofs::PrepareBasicCircuitsJob, AccountTreeId, Address, L1BatchNumber,
L2ChainId, MiniblockNumber, StorageKey, StorageLog, H256,
};
use zksync_utils::u32_to_h256;

Expand Down Expand Up @@ -282,14 +280,7 @@ async fn test_postgres_backup_recovery(
// Re-insert the last batch without metadata immediately.
storage
.blocks_dal()
.insert_l1_batch(
batch_without_metadata,
&[],
BlockGasCount::default(),
&[],
&[],
Default::default(),
)
.insert_mock_l1_batch(batch_without_metadata)
.await
.unwrap();
insert_initial_writes_for_batch(&mut storage, batch_without_metadata.number).await;
Expand All @@ -314,14 +305,7 @@ async fn test_postgres_backup_recovery(
for batch_header in &removed_batches {
let mut txn = storage.start_transaction().await.unwrap();
txn.blocks_dal()
.insert_l1_batch(
batch_header,
&[],
BlockGasCount::default(),
&[],
&[],
Default::default(),
)
.insert_mock_l1_batch(batch_header)
.await
.unwrap();
insert_initial_writes_for_batch(&mut txn, batch_header.number).await;
Expand Down Expand Up @@ -504,14 +488,7 @@ pub(super) async fn extend_db_state_from_l1_batch(

storage
.blocks_dal()
.insert_l1_batch(
&header,
&[],
BlockGasCount::default(),
&[],
&[],
Default::default(),
)
.insert_mock_l1_batch(&header)
.await
.unwrap();
storage
Expand Down
14 changes: 2 additions & 12 deletions core/lib/zksync_core/src/reorg_detector/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ use assert_matches::assert_matches;
use test_casing::{test_casing, Product};
use tokio::sync::mpsc;
use zksync_dal::StorageProcessor;
use zksync_types::{
block::{BlockGasCount, MiniblockHeader},
L2ChainId, ProtocolVersion,
};
use zksync_types::{block::MiniblockHeader, L2ChainId, ProtocolVersion};

use super::*;
use crate::{
Expand All @@ -36,14 +33,7 @@ async fn seal_l1_batch(storage: &mut StorageProcessor<'_>, number: u32, hash: H2
let header = create_l1_batch(number);
storage
.blocks_dal()
.insert_l1_batch(
&header,
&[],
BlockGasCount::default(),
&[],
&[],
Default::default(),
)
.insert_mock_l1_batch(&header)
.await
.unwrap();
storage
Expand Down
9 changes: 1 addition & 8 deletions core/lib/zksync_core/src/state_keeper/io/tests/tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,7 @@ impl Tester {
let mut storage = pool.access_storage_tagged("state_keeper").await.unwrap();
storage
.blocks_dal()
.insert_l1_batch(
&batch_header,
&[],
Default::default(),
&[],
&[],
Default::default(),
)
.insert_mock_l1_batch(&batch_header)
.await
.unwrap();
storage
Expand Down

0 comments on commit 1f1e5d7

Please sign in to comment.