Skip to content

Commit

Permalink
fix(derive): Stage Decoupling (#88)
Browse files Browse the repository at this point in the history
* fix(derive): l1 retrieval provider

* fix(derive): decouple stages using provider traits

* fix(derive): use mock providers in stage unit tests

* fix(derive): channel reader tests

* fix(derive): start batch queue tests

* fix(derive): missing origin test
  • Loading branch information
refcell authored Apr 5, 2024
1 parent 341bd27 commit 2a4038c
Show file tree
Hide file tree
Showing 18 changed files with 776 additions and 410 deletions.
16 changes: 9 additions & 7 deletions crates/derive/src/stages/attributes_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ mod tests {
RollupConfig, SingleBatch, StageError, StageResult,
};
use crate::{
stages::test_utils::{new_mock_batch_queue, MockAttributesBuilder, MockBatchQueue},
stages::test_utils::{
new_attributes_provider, MockAttributesBuilder, MockAttributesProvider,
},
traits::test_utils::TestTelemetry,
types::RawTransaction,
};
Expand All @@ -191,10 +193,10 @@ mod tests {
cfg: Option<RollupConfig>,
origin: Option<BlockInfo>,
batches: Vec<StageResult<SingleBatch>>,
) -> AttributesQueue<MockBatchQueue, TestTelemetry, MockAttributesBuilder> {
) -> AttributesQueue<MockAttributesProvider, TestTelemetry, MockAttributesBuilder> {
let cfg = cfg.unwrap_or_default();
let telemetry = TestTelemetry::new();
let mock_batch_queue = new_mock_batch_queue(origin, batches);
let mock_batch_queue = new_attributes_provider(origin, batches);
let mock_attributes_builder = MockAttributesBuilder::default();
AttributesQueue::new(cfg, mock_batch_queue, telemetry, mock_attributes_builder)
}
Expand Down Expand Up @@ -282,11 +284,11 @@ mod tests {
async fn test_create_next_attributes_success() {
let cfg = RollupConfig::default();
let telemetry = TestTelemetry::new();
let mock_batch_queue = new_mock_batch_queue(None, vec![]);
let mock = new_attributes_provider(None, vec![]);
let mut payload_attributes = PayloadAttributes::default();
let mock_builder =
MockAttributesBuilder { attributes: vec![Ok(payload_attributes.clone())] };
let mut aq = AttributesQueue::new(cfg, mock_batch_queue, telemetry, mock_builder);
let mut aq = AttributesQueue::new(cfg, mock, telemetry, mock_builder);
let parent = L2BlockInfo::default();
let txs = vec![RawTransaction::default(), RawTransaction::default()];
let batch = SingleBatch { transactions: txs.clone(), ..Default::default() };
Expand All @@ -309,10 +311,10 @@ mod tests {
async fn test_next_attributes_load_batch_last_in_span() {
let cfg = RollupConfig::default();
let telemetry = TestTelemetry::new();
let mock_batch_queue = new_mock_batch_queue(None, vec![Ok(Default::default())]);
let mock = new_attributes_provider(None, vec![Ok(Default::default())]);
let mut pa = PayloadAttributes::default();
let mock_builder = MockAttributesBuilder { attributes: vec![Ok(pa.clone())] };
let mut aq = AttributesQueue::new(cfg, mock_batch_queue, telemetry, mock_builder);
let mut aq = AttributesQueue::new(cfg, mock, telemetry, mock_builder);
// If we load the batch, we should get the last in span.
// But it won't take it so it will be available in the next_attributes call.
let _ = aq.load_batch(L2BlockInfo::default()).await.unwrap();
Expand Down
Loading

0 comments on commit 2a4038c

Please sign in to comment.