use crate::{
BatchProvider, PipelineResult,
test_utils::{TestChainProvider, TestL2ChainProvider},
};
use alloc::{boxed::Box, sync::Arc};
use kona_genesis::RollupConfig;
use kona_protocol::{BlockInfo, L2BlockInfo, OpAttributesWithParent};
use crate::{
AttributesQueue, BatchStream, ChannelProvider, ChannelReader, DerivationPipeline, FrameQueue,
L1Retrieval, NextAttributes, OriginAdvancer, OriginProvider, PipelineBuilder, PipelineError,
PollingTraversal, Signal, SignalReceiver,
test_utils::{TestAttributesBuilder, TestDAP},
};
#[derive(Default, Debug, Clone)]
pub struct TestNextAttributes {
pub next_attributes: Option<OpAttributesWithParent>,
}
#[async_trait::async_trait]
impl SignalReceiver for TestNextAttributes {
async fn signal(&mut self, _: Signal) -> PipelineResult<()> {
Ok(())
}
}
#[async_trait::async_trait]
impl OriginProvider for TestNextAttributes {
fn origin(&self) -> Option<BlockInfo> {
Some(BlockInfo::default())
}
}
#[async_trait::async_trait]
impl OriginAdvancer for TestNextAttributes {
async fn advance_origin(&mut self) -> PipelineResult<()> {
Ok(())
}
}
#[async_trait::async_trait]
impl NextAttributes for TestNextAttributes {
async fn next_attributes(&mut self, _: L2BlockInfo) -> PipelineResult<OpAttributesWithParent> {
self.next_attributes.take().ok_or(PipelineError::Eof.temp())
}
}
pub type TestPollingTraversal = PollingTraversal<TestChainProvider>;
pub type TestL1Retrieval = L1Retrieval<TestDAP, TestPollingTraversal>;
pub type TestFrameQueue = FrameQueue<TestL1Retrieval>;
pub type TestChannelProvider = ChannelProvider<TestFrameQueue>;
pub type TestChannelReader = ChannelReader<TestChannelProvider>;
pub type TestBatchStream = BatchStream<TestChannelReader, TestL2ChainProvider>;
pub type TestBatchProvider = BatchProvider<TestBatchStream, TestL2ChainProvider>;
pub type TestAttributesQueue = AttributesQueue<TestBatchProvider, TestAttributesBuilder>;
pub type TestPipeline = DerivationPipeline<TestAttributesQueue, TestL2ChainProvider>;
pub fn new_test_pipeline() -> TestPipeline {
PipelineBuilder::new()
.rollup_config(Arc::new(RollupConfig::default()))
.origin(BlockInfo::default())
.dap_source(TestDAP::default())
.builder(TestAttributesBuilder::default())
.chain_provider(TestChainProvider::default())
.l2_chain_provider(TestL2ChainProvider::default())
.build_polled()
}