Skip to content

Commit

Permalink
feat(papyrus_base_layer): automock the base layer
Browse files Browse the repository at this point in the history
  • Loading branch information
guy-starkware committed Feb 13, 2025
1 parent 7eab8a9 commit 94161fb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
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/papyrus_base_layer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ alloy-transport-http.workspace = true
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
Expand Down
6 changes: 3 additions & 3 deletions crates/papyrus_base_layer/src/ethereum_base_layer_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,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<u64>,
events: &[&str],
events: &'a [&'a str],
) -> EthereumBaseLayerResult<Vec<L1Event>> {
let filter = EthEventFilter::new().select(block_range).events(events);

Expand Down
13 changes: 10 additions & 3 deletions crates/papyrus_base_layer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -55,10 +62,10 @@ pub trait BaseLayerContract {
) -> Result<Option<L1BlockReference>, 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<L1BlockNumber>,
event_identifiers: &[&str],
event_identifiers: &'a [&'a str],
) -> Result<Vec<L1Event>, Self::Error>;

async fn get_price_sample(
Expand Down

0 comments on commit 94161fb

Please sign in to comment.