Skip to content

Commit

Permalink
chore(starknet_l1_provider): add fake l1 provider client
Browse files Browse the repository at this point in the history
  • Loading branch information
Gilad Chase committed Dec 24, 2024
1 parent 1a8875a commit ef44633
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/starknet_l1_provider/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 47 additions & 1 deletion crates/starknet_l1_provider/src/test_utils.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -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<Vec<Event>>,
}

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<Vec<ExecutableL1HandlerTransaction>> {
todo!()
}
async fn add_events(&self, events: Vec<Event>) -> L1ProviderClientResult<()> {
self.events_received.lock().unwrap().extend(events);
Ok(())
}
async fn validate(
&self,
_tx_hash: TransactionHash,
) -> L1ProviderClientResult<ValidationStatus> {
todo!()
}
}

0 comments on commit ef44633

Please sign in to comment.