Skip to content

Commit

Permalink
chore: move test components' enums to common
Browse files Browse the repository at this point in the history
  • Loading branch information
uriel-starkware committed Jul 9, 2024
1 parent f98e476 commit ab45d5d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 45 deletions.
21 changes: 21 additions & 0 deletions crates/mempool_infra/tests/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use starknet_mempool_infra::component_client::ClientResult;

pub(crate) type ValueA = u32;
Expand All @@ -9,6 +10,26 @@ pub(crate) type ResultB = ClientResult<ValueB>;

// TODO(Tsabary): add more messages / functions to the components.

#[derive(Serialize, Deserialize, Debug)]
pub enum ComponentARequest {
AGetValue,
}

#[derive(Serialize, Deserialize, Debug)]
pub enum ComponentAResponse {
Value(ValueA),
}

#[derive(Serialize, Deserialize, Debug)]
pub enum ComponentBRequest {
BGetValue,
}

#[derive(Serialize, Deserialize, Debug)]
pub enum ComponentBResponse {
Value(ValueB),
}

#[async_trait]
pub(crate) trait ComponentAClientTrait: Send + Sync {
async fn a_get_value(&self) -> ResultA;
Expand Down
31 changes: 5 additions & 26 deletions crates/mempool_infra/tests/component_server_client_http_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ use std::net::{IpAddr, Ipv6Addr, SocketAddr};

use async_trait::async_trait;
use bincode::serialize;
use common::{ComponentAClientTrait, ComponentBClientTrait, ResultA, ResultB};
use common::{
ComponentAClientTrait, ComponentARequest, ComponentAResponse, ComponentBClientTrait,
ComponentBRequest, ComponentBResponse, ResultA, ResultB,
};
use hyper::service::{make_service_fn, service_fn};
use hyper::{Body, Request, Response, Server, StatusCode};
use serde::{Deserialize, Serialize};
use serde::Serialize;
use starknet_mempool_infra::component_client::ComponentClientHttp;
use starknet_mempool_infra::component_definitions::{ComponentRequestHandler, ServerError};
use starknet_mempool_infra::component_server::ComponentServerHttp;
Expand All @@ -25,18 +28,6 @@ const UNCONNECTED_SERVER_PORT: u16 = 10002;
const FAULTY_SERVER_REQ_DESER_PORT: u16 = 10003;
const FAULTY_SERVER_RES_DESER_PORT: u16 = 10004;

// Todo(uriel): Move to common
#[derive(Serialize, Deserialize, Debug)]
pub enum ComponentARequest {
AGetValue,
}

// Todo(uriel): Move to common
#[derive(Serialize, Deserialize, Debug)]
pub enum ComponentAResponse {
Value(ValueA),
}

#[async_trait]
impl ComponentAClientTrait for ComponentClientHttp<ComponentARequest, ComponentAResponse> {
async fn a_get_value(&self) -> ResultA {
Expand All @@ -55,18 +46,6 @@ impl ComponentRequestHandler<ComponentARequest, ComponentAResponse> for Componen
}
}

// Todo(uriel): Move to common
#[derive(Serialize, Deserialize, Debug)]
pub enum ComponentBRequest {
BGetValue,
}

// Todo(uriel): Move to common
#[derive(Serialize, Deserialize, Debug)]
pub enum ComponentBResponse {
Value(ValueB),
}

#[async_trait]
impl ComponentBClientTrait for ComponentClientHttp<ComponentBRequest, ComponentBResponse> {
async fn b_get_value(&self) -> ResultB {
Expand Down
23 changes: 4 additions & 19 deletions crates/mempool_infra/tests/component_server_client_test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
mod common;

use async_trait::async_trait;
use common::{ComponentAClientTrait, ComponentBClientTrait, ResultA, ResultB};
use common::{
ComponentAClientTrait, ComponentARequest, ComponentAResponse, ComponentBClientTrait,
ComponentBRequest, ComponentBResponse, ResultA, ResultB,
};
use starknet_mempool_infra::component_client::ComponentClient;
use starknet_mempool_infra::component_definitions::{
ComponentRequestAndResponseSender, ComponentRequestHandler,
Expand All @@ -14,14 +17,6 @@ use crate::common::{ComponentA, ComponentB, ValueA, ValueB};

// TODO(Tsabary): send messages from component b to component a.

pub enum ComponentARequest {
AGetValue,
}

pub enum ComponentAResponse {
Value(ValueA),
}

#[async_trait]
impl ComponentAClientTrait for ComponentClient<ComponentARequest, ComponentAResponse> {
async fn a_get_value(&self) -> ResultA {
Expand All @@ -41,16 +36,6 @@ impl ComponentRequestHandler<ComponentARequest, ComponentAResponse> for Componen
}
}

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum ComponentBRequest {
BGetValue,
}

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum ComponentBResponse {
Value(ValueB),
}

#[async_trait]
impl ComponentBClientTrait for ComponentClient<ComponentBRequest, ComponentBResponse> {
async fn b_get_value(&self) -> ResultB {
Expand Down

0 comments on commit ab45d5d

Please sign in to comment.