diff --git a/Cargo.lock b/Cargo.lock index 3e479644be..62ea8aeda9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10542,6 +10542,7 @@ dependencies = [ "assert_matches", "async-trait", "indexmap 2.6.0", + "itertools 0.12.1", "papyrus_base_layer", "papyrus_config", "pretty_assertions", diff --git a/crates/starknet_l1_provider/Cargo.toml b/crates/starknet_l1_provider/Cargo.toml index d9351168a1..f879e8a4cc 100644 --- a/crates/starknet_l1_provider/Cargo.toml +++ b/crates/starknet_l1_provider/Cargo.toml @@ -11,6 +11,7 @@ testing = [] [dependencies] async-trait.workspace = true indexmap.workspace = true +itertools.workspace = true papyrus_base_layer.workspace = true papyrus_config.workspace = true serde.workspace = true diff --git a/crates/starknet_l1_provider/src/test_utils.rs b/crates/starknet_l1_provider/src/test_utils.rs index a987fe7eee..b99daea435 100644 --- a/crates/starknet_l1_provider/src/test_utils.rs +++ b/crates/starknet_l1_provider/src/test_utils.rs @@ -1,6 +1,20 @@ +use std::sync::Mutex; + +use async_trait::async_trait; use indexmap::{IndexMap, IndexSet}; -use starknet_api::executable_transaction::L1HandlerTransaction; +use itertools::Itertools; +use pretty_assertions::assert_eq; +use starknet_api::executable_transaction::{ + L1HandlerTransaction as ExecutableL1HandlerTransaction, + L1HandlerTransaction, +}; use starknet_api::transaction::TransactionHash; +use starknet_l1_provider_types::{ + Event, + L1ProviderClient, + L1ProviderClientResult, + ValidationStatus, +}; use crate::{L1Provider, ProviderState, TransactionManager}; @@ -119,3 +133,35 @@ impl TransactionManagerContentBuilder { self.txs.is_none() && self.on_l2_awaiting_l1_consumption.is_none() } } + +#[derive(Default)] +pub struct FakeL1ProviderClient { + pub events_received: Mutex>, +} + +impl FakeL1ProviderClient { + #[track_caller] + pub fn assert_add_events_received_with(&self, expected: &[Event]) { + assert_eq!(self.events_received.lock().unwrap().drain(..).collect_vec(), expected); + } +} + +#[async_trait] +impl L1ProviderClient for FakeL1ProviderClient { + async fn get_txs( + &self, + _n_txs: usize, + ) -> L1ProviderClientResult> { + todo!() + } + async fn add_events(&self, events: Vec) -> L1ProviderClientResult<()> { + self.events_received.lock().unwrap().extend(events); + Ok(()) + } + async fn validate( + &self, + _tx_hash: TransactionHash, + ) -> L1ProviderClientResult { + todo!() + } +}