From b163d1f86e996218793164f843532ba8e36c41bb Mon Sep 17 00:00:00 2001 From: Itay Tsabary Date: Mon, 18 Nov 2024 21:41:13 +0200 Subject: [PATCH] chore: add testing feature, use automock only as test commit-id:c208af25 --- Cargo.lock | 1 + crates/starknet_gateway_types/Cargo.toml | 10 +++++++++- crates/starknet_gateway_types/src/communication.rs | 6 +++--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 35456ffd83..dd1f701520 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10259,6 +10259,7 @@ dependencies = [ "serde", "serde_json", "starknet_api", + "starknet_gateway_types", "starknet_sequencer_infra", "thiserror", "tracing", diff --git a/crates/starknet_gateway_types/Cargo.toml b/crates/starknet_gateway_types/Cargo.toml index 4c591bb21f..3c228296e2 100644 --- a/crates/starknet_gateway_types/Cargo.toml +++ b/crates/starknet_gateway_types/Cargo.toml @@ -5,6 +5,10 @@ edition.workspace = true license.workspace = true repository.workspace = true +[features] +testing = ["mockall"] + + [lints] workspace = true @@ -12,7 +16,7 @@ workspace = true async-trait.workspace = true axum.workspace = true enum-assoc.workspace = true -mockall.workspace = true +mockall = { workspace = true, optional = true } papyrus_network_types.workspace = true papyrus_proc_macros.workspace = true papyrus_rpc.workspace = true @@ -22,3 +26,7 @@ starknet_api.workspace = true starknet_sequencer_infra.workspace = true thiserror.workspace = true tracing.workspace = true + +[dev-dependencies] +# Enable self with "testing" feature in tests. +starknet_gateway_types = { workspace = true, features = ["testing"] } diff --git a/crates/starknet_gateway_types/src/communication.rs b/crates/starknet_gateway_types/src/communication.rs index 682629b3fc..75a6b56a87 100644 --- a/crates/starknet_gateway_types/src/communication.rs +++ b/crates/starknet_gateway_types/src/communication.rs @@ -1,8 +1,8 @@ use std::sync::Arc; use async_trait::async_trait; -use mockall::predicate::*; -use mockall::*; +#[cfg(any(feature = "testing", test))] +use mockall::automock; use papyrus_proc_macros::handle_response_variants; use serde::{Deserialize, Serialize}; use starknet_api::transaction::TransactionHash; @@ -30,7 +30,7 @@ use tracing::{error, instrument}; /// Serves as the gateway's shared interface. Requires `Send + Sync` to allow transferring /// and sharing resources (inputs, futures) across threads. -#[automock] +#[cfg_attr(any(feature = "testing", test), automock)] #[async_trait] pub trait GatewayClient: Send + Sync { async fn add_tx(&self, gateway_input: GatewayInput) -> GatewayClientResult;