diff --git a/Cargo.lock b/Cargo.lock index 0b5d93a2be3..370cfca523d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7831,6 +7831,7 @@ dependencies = [ "colored 3.0.0", "ethers", "ethers-core", + "mockall", "papyrus_config", "pretty_assertions", "serde", diff --git a/crates/papyrus_base_layer/Cargo.toml b/crates/papyrus_base_layer/Cargo.toml index b322a078fd7..9d73eaadfd6 100644 --- a/crates/papyrus_base_layer/Cargo.toml +++ b/crates/papyrus_base_layer/Cargo.toml @@ -16,6 +16,7 @@ alloy = { workspace = true, features = ["contract", "json-rpc", "rpc-types"] } async-trait.workspace = true colored = { workspace = true, optional = true } ethers.workspace = true +mockall.workspace = true papyrus_config.workspace = true serde.workspace = true starknet-types-core.workspace = true diff --git a/crates/papyrus_base_layer/src/ethereum_base_layer_contract.rs b/crates/papyrus_base_layer/src/ethereum_base_layer_contract.rs index d5b35ac6fe3..da5e7a8bc82 100644 --- a/crates/papyrus_base_layer/src/ethereum_base_layer_contract.rs +++ b/crates/papyrus_base_layer/src/ethereum_base_layer_contract.rs @@ -92,10 +92,10 @@ impl BaseLayerContract for EthereumBaseLayerContract { self.get_proved_block_at(ethereum_block_number).await.map(Some) } - async fn events( - &self, + async fn events<'a>( + &'a self, block_range: RangeInclusive, - events: &[&str], + events: &'a [&'a str], ) -> EthereumBaseLayerResult> { let filter = EthEventFilter::new().select(block_range).events(events); diff --git a/crates/papyrus_base_layer/src/lib.rs b/crates/papyrus_base_layer/src/lib.rs index 640c0ce51f3..d0fe8f59ebe 100644 --- a/crates/papyrus_base_layer/src/lib.rs +++ b/crates/papyrus_base_layer/src/lib.rs @@ -3,11 +3,14 @@ use std::fmt::{Debug, Display}; use std::ops::RangeInclusive; use async_trait::async_trait; +#[cfg(test)] +use mockall::automock; use serde::{Deserialize, Serialize}; use starknet_api::block::BlockHashAndNumber; use starknet_api::core::{ContractAddress, EntryPointSelector, EthAddress, Nonce}; use starknet_api::transaction::fields::{Calldata, Fee}; use starknet_api::transaction::L1HandlerTransaction; +use thiserror::Error; pub mod constants; pub mod ethereum_base_layer_contract; @@ -22,7 +25,11 @@ mod base_layer_test; pub type L1BlockNumber = u64; +#[derive(Debug, Error)] +pub enum MockError {} + /// Interface for getting data from the Starknet base contract. +#[cfg_attr(test, automock(type Error = MockError;))] #[async_trait] pub trait BaseLayerContract { type Error: Error + Display + Debug; @@ -55,10 +62,10 @@ pub trait BaseLayerContract { ) -> Result, Self::Error>; /// Get specific events from the Starknet base contract between two L1 block numbers. - async fn events( - &self, + async fn events<'a>( + &'a self, block_range: RangeInclusive, - event_identifiers: &[&str], + event_identifiers: &'a [&'a str], ) -> Result, Self::Error>; async fn get_price_sample(