Skip to content
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

chore(derive): Hoists Test Utilities #677

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions crates/derive/src/attributes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ async fn derive_deposits(
#[cfg(test)]
mod tests {
use super::*;
use crate::{errors::ResetError, stages::test_utils::MockSystemConfigL2Fetcher};
use crate::{errors::ResetError, test_utils::TestSystemConfigL2Fetcher};
use alloc::vec;
use alloy_consensus::Header;
use alloy_primitives::{Log, LogData, B256, U256, U64};
Expand Down Expand Up @@ -444,7 +444,7 @@ mod tests {
async fn test_prepare_payload_block_mismatch_epoch_reset() {
let cfg = Arc::new(RollupConfig::default());
let l2_number = 1;
let mut fetcher = MockSystemConfigL2Fetcher::default();
let mut fetcher = TestSystemConfigL2Fetcher::default();
fetcher.insert(l2_number, SystemConfig::default());
let mut provider = TestChainProvider::default();
let header = Header::default();
Expand All @@ -469,7 +469,7 @@ mod tests {
async fn test_prepare_payload_block_mismatch() {
let cfg = Arc::new(RollupConfig::default());
let l2_number = 1;
let mut fetcher = MockSystemConfigL2Fetcher::default();
let mut fetcher = TestSystemConfigL2Fetcher::default();
fetcher.insert(l2_number, SystemConfig::default());
let mut provider = TestChainProvider::default();
let header = Header::default();
Expand All @@ -495,7 +495,7 @@ mod tests {
let timestamp = 100;
let cfg = Arc::new(RollupConfig { block_time, ..Default::default() });
let l2_number = 1;
let mut fetcher = MockSystemConfigL2Fetcher::default();
let mut fetcher = TestSystemConfigL2Fetcher::default();
fetcher.insert(l2_number, SystemConfig::default());
let mut provider = TestChainProvider::default();
let header = Header { timestamp, ..Default::default() };
Expand Down Expand Up @@ -526,7 +526,7 @@ mod tests {
let timestamp = 100;
let cfg = Arc::new(RollupConfig { block_time, ..Default::default() });
let l2_number = 1;
let mut fetcher = MockSystemConfigL2Fetcher::default();
let mut fetcher = TestSystemConfigL2Fetcher::default();
fetcher.insert(l2_number, SystemConfig::default());
let mut provider = TestChainProvider::default();
let header = Header { timestamp, ..Default::default() };
Expand Down Expand Up @@ -572,7 +572,7 @@ mod tests {
let timestamp = 100;
let cfg = Arc::new(RollupConfig { block_time, canyon_time: Some(0), ..Default::default() });
let l2_number = 1;
let mut fetcher = MockSystemConfigL2Fetcher::default();
let mut fetcher = TestSystemConfigL2Fetcher::default();
fetcher.insert(l2_number, SystemConfig::default());
let mut provider = TestChainProvider::default();
let header = Header { timestamp, ..Default::default() };
Expand Down Expand Up @@ -619,7 +619,7 @@ mod tests {
let cfg =
Arc::new(RollupConfig { block_time, ecotone_time: Some(102), ..Default::default() });
let l2_number = 1;
let mut fetcher = MockSystemConfigL2Fetcher::default();
let mut fetcher = TestSystemConfigL2Fetcher::default();
fetcher.insert(l2_number, SystemConfig::default());
let mut provider = TestChainProvider::default();
let header = Header { timestamp, ..Default::default() };
Expand Down Expand Up @@ -667,7 +667,7 @@ mod tests {
let cfg =
Arc::new(RollupConfig { block_time, fjord_time: Some(102), ..Default::default() });
let l2_number = 1;
let mut fetcher = MockSystemConfigL2Fetcher::default();
let mut fetcher = TestSystemConfigL2Fetcher::default();
fetcher.insert(l2_number, SystemConfig::default());
let mut provider = TestChainProvider::default();
let header = Header { timestamp, ..Default::default() };
Expand Down
2 changes: 1 addition & 1 deletion crates/derive/src/batch/span_batch/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ impl SpanBatch {
#[cfg(test)]
mod tests {
use super::*;
use crate::stages::test_utils::{CollectingLayer, TraceStorage};
use crate::test_utils::{CollectingLayer, TraceStorage};
use alloc::vec;
use alloy_consensus::Header;
use alloy_eips::BlockNumHash;
Expand Down
44 changes: 22 additions & 22 deletions crates/derive/src/stages/batch_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,9 @@ where
#[cfg(test)]
mod tests {
use super::*;
use crate::stages::{
channel_reader::BatchReader,
test_utils::{CollectingLayer, MockBatchQueueProvider, TraceStorage},
use crate::{
stages::channel_reader::BatchReader,
test_utils::{CollectingLayer, TestBatchQueueProvider, TraceStorage},
};
use alloc::vec;
use alloy_consensus::Header;
Expand All @@ -518,7 +518,7 @@ mod tests {
#[test]
fn test_pop_next_batch() {
let cfg = Arc::new(RollupConfig::default());
let mock = MockBatchQueueProvider::new(vec![]);
let mock = TestBatchQueueProvider::new(vec![]);
let fetcher = TestL2ChainProvider::default();
let mut bq = BatchQueue::new(cfg, mock, fetcher);
let parent = L2BlockInfo::default();
Expand All @@ -532,7 +532,7 @@ mod tests {
#[tokio::test]
async fn test_batch_queue_reset() {
let cfg = Arc::new(RollupConfig::default());
let mock = MockBatchQueueProvider::new(vec![]);
let mock = TestBatchQueueProvider::new(vec![]);
let fetcher = TestL2ChainProvider::default();
let mut bq = BatchQueue::new(cfg.clone(), mock, fetcher);
bq.l1_blocks.push(BlockInfo::default());
Expand All @@ -555,7 +555,7 @@ mod tests {
#[tokio::test]
async fn test_batch_queue_flush() {
let cfg = Arc::new(RollupConfig::default());
let mock = MockBatchQueueProvider::new(vec![]);
let mock = TestBatchQueueProvider::new(vec![]);
let fetcher = TestL2ChainProvider::default();
let mut bq = BatchQueue::new(cfg.clone(), mock, fetcher);
bq.l1_blocks.push(BlockInfo::default());
Expand Down Expand Up @@ -594,7 +594,7 @@ mod tests {

// Setup batch queue deps
let batch_vec = vec![PipelineResult::Ok(Batch::Single(batch.clone()))];
let mut mock = MockBatchQueueProvider::new(batch_vec);
let mut mock = TestBatchQueueProvider::new(batch_vec);
mock.origin = Some(BlockInfo::default());
let fetcher = TestL2ChainProvider::default();

Expand Down Expand Up @@ -625,7 +625,7 @@ mod tests {

// Setup batch queue deps
let batch_vec = vec![PipelineResult::Ok(Batch::Single(batch.clone()))];
let mut mock = MockBatchQueueProvider::new(batch_vec);
let mut mock = TestBatchQueueProvider::new(batch_vec);
mock.origin = Some(BlockInfo::default());
let fetcher = TestL2ChainProvider::default();

Expand Down Expand Up @@ -659,7 +659,7 @@ mod tests {

// Setup batch queue deps
let batch_vec = vec![PipelineResult::Ok(Batch::Single(batch.clone()))];
let mut mock = MockBatchQueueProvider::new(batch_vec);
let mut mock = TestBatchQueueProvider::new(batch_vec);
mock.origin = Some(BlockInfo::default());
let fetcher = TestL2ChainProvider::default();

Expand All @@ -678,7 +678,7 @@ mod tests {
async fn test_derive_next_batch_missing_origin() {
let data = vec![Ok(Batch::Single(SingleBatch::default()))];
let cfg = Arc::new(RollupConfig::default());
let mock = MockBatchQueueProvider::new(data);
let mock = TestBatchQueueProvider::new(data);
let fetcher = TestL2ChainProvider::default();
let mut bq = BatchQueue::new(cfg, mock, fetcher);
let parent = L2BlockInfo::default();
Expand All @@ -694,7 +694,7 @@ mod tests {
while let Some(batch) = reader.next_batch(cfg.as_ref()) {
batch_vec.push(Ok(batch));
}
let mut mock = MockBatchQueueProvider::new(batch_vec);
let mut mock = TestBatchQueueProvider::new(batch_vec);
mock.origin = Some(BlockInfo::default());
let fetcher = TestL2ChainProvider::default();
let mut bq = BatchQueue::new(cfg, mock, fetcher);
Expand All @@ -715,7 +715,7 @@ mod tests {
while let Some(batch) = reader.next_batch(cfg.as_ref()) {
batch_vec.push(Ok(batch));
}
let mut mock = MockBatchQueueProvider::new(batch_vec);
let mut mock = TestBatchQueueProvider::new(batch_vec);
mock.origin = Some(BlockInfo::default());
let fetcher = TestL2ChainProvider::default();
let mut bq = BatchQueue::new(cfg, mock, fetcher);
Expand All @@ -739,7 +739,7 @@ mod tests {
while let Some(batch) = reader.next_batch(cfg.as_ref()) {
batch_vec.push(Ok(batch));
}
let mut mock = MockBatchQueueProvider::new(batch_vec);
let mut mock = TestBatchQueueProvider::new(batch_vec);
mock.origin = Some(BlockInfo::default());
let fetcher = TestL2ChainProvider::default();
let mut bq = BatchQueue::new(cfg, mock, fetcher);
Expand All @@ -763,7 +763,7 @@ mod tests {
while let Some(batch) = reader.next_batch(cfg.as_ref()) {
batch_vec.push(Ok(batch));
}
let mut mock = MockBatchQueueProvider::new(batch_vec);
let mut mock = TestBatchQueueProvider::new(batch_vec);
mock.origin = Some(BlockInfo::default());
let fetcher = TestL2ChainProvider::default();
let mut bq = BatchQueue::new(cfg, mock, fetcher);
Expand Down Expand Up @@ -796,7 +796,7 @@ mod tests {

// Setup batch queue deps
let batch_vec = vec![PipelineResult::Ok(Batch::Single(batch.clone()))];
let mut mock = MockBatchQueueProvider::new(batch_vec);
let mut mock = TestBatchQueueProvider::new(batch_vec);
mock.origin = Some(BlockInfo::default());
let fetcher = TestL2ChainProvider::default();

Expand Down Expand Up @@ -837,7 +837,7 @@ mod tests {

// Setup batch queue deps
let batch_vec = vec![PipelineResult::Ok(Batch::Single(batch.clone()))];
let mut mock = MockBatchQueueProvider::new(batch_vec);
let mut mock = TestBatchQueueProvider::new(batch_vec);
mock.origin = Some(BlockInfo::default());
let fetcher = TestL2ChainProvider::default();

Expand Down Expand Up @@ -876,7 +876,7 @@ mod tests {
while let Some(batch) = reader.next_batch(cfg.as_ref()) {
batch_vec.push(Ok(batch));
}
let mut mock = MockBatchQueueProvider::new(batch_vec);
let mut mock = TestBatchQueueProvider::new(batch_vec);
mock.origin = Some(BlockInfo::default());
let fetcher = TestL2ChainProvider::default();
let mut bq = BatchQueue::new(cfg, mock, fetcher);
Expand All @@ -895,7 +895,7 @@ mod tests {
while let Some(batch) = reader.next_batch(cfg.as_ref()) {
batch_vec.push(Ok(batch));
}
let mut mock = MockBatchQueueProvider::new(batch_vec);
let mut mock = TestBatchQueueProvider::new(batch_vec);
mock.origin = Some(BlockInfo::default());
let fetcher = TestL2ChainProvider::default();
let mut bq = BatchQueue::new(cfg, mock, fetcher);
Expand All @@ -911,7 +911,7 @@ mod tests {
let mut reader = new_batch_reader();
let cfg = Arc::new(RollupConfig::default());
let batch = reader.next_batch(cfg.as_ref()).unwrap();
let mock = MockBatchQueueProvider::new(vec![Ok(batch)]);
let mock = TestBatchQueueProvider::new(vec![Ok(batch)]);
let fetcher = TestL2ChainProvider::default();
let mut bq = BatchQueue::new(cfg, mock, fetcher);
let res = bq.next_batch(L2BlockInfo::default()).await.unwrap_err();
Expand All @@ -927,7 +927,7 @@ mod tests {
while let Some(batch) = reader.next_batch(cfg.as_ref()) {
batch_vec.push(Ok(batch));
}
let mut mock = MockBatchQueueProvider::new(batch_vec);
let mut mock = TestBatchQueueProvider::new(batch_vec);
mock.origin = Some(BlockInfo::default());
let fetcher = TestL2ChainProvider::default();
let mut bq = BatchQueue::new(cfg, mock, fetcher);
Expand Down Expand Up @@ -997,7 +997,7 @@ mod tests {
tx.encode(&mut buf);
let prefixed = [&[OpTxType::Deposit as u8], &buf[..]].concat();
second_batch_txs.insert(0, Bytes::copy_from_slice(&prefixed));
let mut mock = MockBatchQueueProvider::new(batch_vec);
let mut mock = TestBatchQueueProvider::new(batch_vec);
let origin_check =
b256!("8527cdb6f601acf9b483817abd1da92790c92b19000000000000000000000000");
mock.origin = Some(BlockInfo {
Expand Down Expand Up @@ -1086,7 +1086,7 @@ mod tests {
async fn test_batch_queue_empty_bytes() {
let data = vec![Ok(Batch::Single(SingleBatch::default()))];
let cfg = Arc::new(RollupConfig::default());
let mock = MockBatchQueueProvider::new(data);
let mock = TestBatchQueueProvider::new(data);
let fetcher = TestL2ChainProvider::default();
let mut bq = BatchQueue::new(cfg, mock, fetcher);
let parent = L2BlockInfo::default();
Expand Down
14 changes: 7 additions & 7 deletions crates/derive/src/stages/batch_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,15 @@ mod test {
use super::*;
use crate::{
batch::{SingleBatch, SpanBatchElement},
stages::test_utils::{CollectingLayer, MockBatchStreamProvider, TraceStorage},
test_utils::{CollectingLayer, TestBatchStreamProvider, TraceStorage},
};
use kona_providers::test_utils::TestL2ChainProvider;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};

#[tokio::test]
async fn test_batch_stream_flush() {
let config = Arc::new(RollupConfig { holocene_time: Some(0), ..RollupConfig::default() });
let prev = MockBatchStreamProvider::new(vec![]);
let prev = TestBatchStreamProvider::new(vec![]);
let mut stream = BatchStream::new(prev, config, TestL2ChainProvider::default());
stream.buffer.push_back(SingleBatch::default());
stream.span = Some(SpanBatch::default());
Expand All @@ -248,7 +248,7 @@ mod test {
#[tokio::test]
async fn test_batch_stream_reset() {
let config = Arc::new(RollupConfig { holocene_time: Some(0), ..RollupConfig::default() });
let prev = MockBatchStreamProvider::new(vec![]);
let prev = TestBatchStreamProvider::new(vec![]);
let mut stream = BatchStream::new(prev, config.clone(), TestL2ChainProvider::default());
stream.buffer.push_back(SingleBatch::default());
stream.span = Some(SpanBatch::default());
Expand All @@ -262,7 +262,7 @@ mod test {
#[tokio::test]
async fn test_batch_stream_flush_channel() {
let config = Arc::new(RollupConfig { holocene_time: Some(0), ..RollupConfig::default() });
let prev = MockBatchStreamProvider::new(vec![]);
let prev = TestBatchStreamProvider::new(vec![]);
let mut stream = BatchStream::new(prev, config.clone(), TestL2ChainProvider::default());
stream.buffer.push_back(SingleBatch::default());
stream.span = Some(SpanBatch::default());
Expand All @@ -281,7 +281,7 @@ mod test {

let data = vec![Ok(Batch::Single(SingleBatch::default()))];
let config = Arc::new(RollupConfig { holocene_time: Some(100), ..RollupConfig::default() });
let prev = MockBatchStreamProvider::new(data);
let prev = TestBatchStreamProvider::new(data);
let mut stream = BatchStream::new(prev, config.clone(), TestL2ChainProvider::default());

// The stage should not be active.
Expand Down Expand Up @@ -313,7 +313,7 @@ mod test {
block_time: 2,
..RollupConfig::default()
});
let prev = MockBatchStreamProvider::new(data);
let prev = TestBatchStreamProvider::new(data);
let provider = TestL2ChainProvider::default();
let mut stream = BatchStream::new(prev, config.clone(), provider);

Expand Down Expand Up @@ -372,7 +372,7 @@ mod test {
async fn test_single_batch_pass_through() {
let data = vec![Ok(Batch::Single(SingleBatch::default()))];
let config = Arc::new(RollupConfig { holocene_time: Some(0), ..RollupConfig::default() });
let prev = MockBatchStreamProvider::new(data);
let prev = TestBatchStreamProvider::new(data);
let mut stream = BatchStream::new(prev, config.clone(), TestL2ChainProvider::default());

// The stage should be active.
Expand Down
Loading