-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: clean component server client tests
- Loading branch information
1 parent
dbc0b15
commit 7541c67
Showing
10 changed files
with
102 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
pub mod component_client; | ||
pub mod component_client_rpc; | ||
pub mod component_definitions; | ||
pub mod component_runner; | ||
pub mod component_server; | ||
pub mod component_server_rpc; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,46 @@ | ||
use async_trait::async_trait; | ||
use starknet_mempool_infra::component_client::ClientError; | ||
|
||
pub(crate) type ValueA = u32; | ||
pub(crate) type ValueB = u8; | ||
|
||
// TODO(Tsabary): add more messages / functions to the components. | ||
|
||
#[async_trait] | ||
pub(crate) trait ComponentATrait: Send + Sync { | ||
async fn a_get_value(&self) -> ValueA; | ||
pub(crate) trait AClientTrait: Send + Sync { | ||
async fn a_get_value(&self) -> Result<ValueA, ClientError>; | ||
} | ||
|
||
#[async_trait] | ||
pub(crate) trait ComponentBTrait: Send + Sync { | ||
async fn b_get_value(&self) -> ValueB; | ||
pub(crate) trait BClientTrait: Send + Sync { | ||
async fn b_get_value(&self) -> Result<ValueB, ClientError>; | ||
} | ||
|
||
pub(crate) struct ComponentA { | ||
b: Box<dyn ComponentBTrait>, | ||
} | ||
|
||
#[async_trait] | ||
impl ComponentATrait for ComponentA { | ||
async fn a_get_value(&self) -> ValueA { | ||
let b_value = self.b.b_get_value().await; | ||
b_value.into() | ||
} | ||
b: Box<dyn BClientTrait>, | ||
} | ||
|
||
impl ComponentA { | ||
pub fn new(b: Box<dyn ComponentBTrait>) -> Self { | ||
pub fn new(b: Box<dyn BClientTrait>) -> Self { | ||
Self { b } | ||
} | ||
|
||
pub async fn a_get_value(&self) -> ValueA { | ||
let b_value = self.b.b_get_value().await.unwrap(); | ||
b_value.into() | ||
} | ||
} | ||
|
||
pub(crate) struct ComponentB { | ||
value: ValueB, | ||
_a: Box<dyn ComponentATrait>, | ||
} | ||
|
||
#[async_trait] | ||
impl ComponentBTrait for ComponentB { | ||
async fn b_get_value(&self) -> ValueB { | ||
self.value | ||
} | ||
_a: Box<dyn AClientTrait>, | ||
} | ||
|
||
impl ComponentB { | ||
pub fn new(value: ValueB, a: Box<dyn ComponentATrait>) -> Self { | ||
pub fn new(value: ValueB, a: Box<dyn AClientTrait>) -> Self { | ||
Self { value, _a: a } | ||
} | ||
pub async fn b_get_value(&self) -> ValueB { | ||
self.value | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.