From 37d7bc8f146d46d2580d255b20c5a91a682c491f Mon Sep 17 00:00:00 2001 From: Lev Roitman Date: Wed, 3 Jul 2024 16:33:49 +0300 Subject: [PATCH] feat: implementing ComponentRunner for the gateway commit-id:f9f21462 --- crates/gateway/src/gateway.rs | 9 ++++----- crates/tests-integration/src/integration_test_setup.rs | 5 +++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/gateway/src/gateway.rs b/crates/gateway/src/gateway.rs index 352a80d51..d85cf007f 100644 --- a/crates/gateway/src/gateway.rs +++ b/crates/gateway/src/gateway.rs @@ -57,7 +57,7 @@ impl Gateway { Gateway { config, app_state } } - pub async fn run(self) -> Result<(), GatewayRunError> { + pub async fn run(&mut self) -> Result<(), GatewayRunError> { // Parses the bind address from GatewayConfig, returning an error for invalid addresses. let GatewayNetworkConfig { ip, port } = self.config.network_config; let addr = SocketAddr::new(ip, port); @@ -67,11 +67,11 @@ impl Gateway { Ok(axum::Server::bind(&addr).serve(app.into_make_service()).await?) } - pub fn app(self) -> Router { + pub fn app(&self) -> Router { Router::new() .route("/is_alive", get(is_alive)) .route("/add_tx", post(add_tx)) - .with_state(self.app_state) + .with_state(self.app_state.clone()) } } @@ -146,8 +146,7 @@ pub fn create_gateway( #[async_trait] impl ComponentRunner for Gateway { async fn start(&mut self) -> Result<(), ComponentStartError> { - // TODO(Lev, 23/07/2024): Implement the real logic. println!("Gateway::start()"); - Ok(()) + self.run().await.map_err(|_| ComponentStartError::InternalComponentError) } } diff --git a/crates/tests-integration/src/integration_test_setup.rs b/crates/tests-integration/src/integration_test_setup.rs index 196edcf29..cce1a67ef 100644 --- a/crates/tests-integration/src/integration_test_setup.rs +++ b/crates/tests-integration/src/integration_test_setup.rs @@ -30,7 +30,7 @@ pub struct IntegrationTestSetup { } impl IntegrationTestSetup { - pub async fn new(n_accounts: u16) -> Self { + pub async fn new(n_initialized_account_contracts: u16) -> Self { let handle = Handle::current(); let task_executor = TokioExecutor::new(handle); @@ -41,7 +41,8 @@ impl IntegrationTestSetup { channel::(MEMPOOL_INVOCATIONS_QUEUE_SIZE); // Build and run gateway; initialize a gateway client. let gateway_mempool_client = MempoolClientImpl::new(tx_mempool.clone()); - let gateway = create_gateway(Arc::new(gateway_mempool_client), n_accounts).await; + let mut gateway = + create_gateway(Arc::new(gateway_mempool_client), n_initialized_account_contracts).await; let GatewayNetworkConfig { ip, port } = gateway.config.network_config; let gateway_client = GatewayClient::new(SocketAddr::from((ip, port))); let gateway_handle = task_executor.spawn_with_handle(async move {