From 0957e41df6f963389eb37c3bce4058e294ebcb41 Mon Sep 17 00:00:00 2001 From: ShahakShama <70578257+ShahakShama@users.noreply.github.com> Date: Thu, 21 Nov 2024 13:47:59 +0200 Subject: [PATCH] test(sync): add test that checks StateSyncRunner runs sync future (#2120) --- crates/starknet_state_sync/Cargo.toml | 3 ++ crates/starknet_state_sync/src/runner/mod.rs | 3 ++ crates/starknet_state_sync/src/runner/test.rs | 28 +++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 crates/starknet_state_sync/src/runner/test.rs diff --git a/crates/starknet_state_sync/Cargo.toml b/crates/starknet_state_sync/Cargo.toml index e4e7461bcd..d746a8446a 100644 --- a/crates/starknet_state_sync/Cargo.toml +++ b/crates/starknet_state_sync/Cargo.toml @@ -23,3 +23,6 @@ starknet_sequencer_infra.workspace = true starknet_state_sync_types.workspace = true tokio.workspace = true validator.workspace = true + +[dev-dependencies] +papyrus_storage = { workspace = true, features = ["testing"] } diff --git a/crates/starknet_state_sync/src/runner/mod.rs b/crates/starknet_state_sync/src/runner/mod.rs index a1429cafb6..caa6333759 100644 --- a/crates/starknet_state_sync/src/runner/mod.rs +++ b/crates/starknet_state_sync/src/runner/mod.rs @@ -1,3 +1,6 @@ +#[cfg(test)] +mod test; + use std::sync::Arc; use async_trait::async_trait; diff --git a/crates/starknet_state_sync/src/runner/test.rs b/crates/starknet_state_sync/src/runner/test.rs new file mode 100644 index 0000000000..aeba980d66 --- /dev/null +++ b/crates/starknet_state_sync/src/runner/test.rs @@ -0,0 +1,28 @@ +use futures::channel::mpsc; +use futures::future::ready; +use futures::FutureExt; +use papyrus_storage::test_utils::get_test_storage; +use papyrus_sync::StateSyncError as PapyrusStateSyncError; +use starknet_sequencer_infra::component_definitions::ComponentStarter; + +use super::StateSyncRunner; + +const BUFFER_SIZE: usize = 1000; + +#[test] +fn run_returns_when_sync_future_returns() { + let (_request_sender, request_receiver) = mpsc::channel(BUFFER_SIZE); + let (storage_reader, _storage_writer) = get_test_storage().0; + let sync_future = ready(Ok(())).boxed(); + let mut state_sync_runner = StateSyncRunner { request_receiver, storage_reader, sync_future }; + state_sync_runner.start().now_or_never().unwrap().unwrap(); +} + +#[test] +fn run_returns_error_when_sync_future_returns_error() { + let (_request_sender, request_receiver) = mpsc::channel(BUFFER_SIZE); + let (storage_reader, _storage_writer) = get_test_storage().0; + let sync_future = ready(Err(PapyrusStateSyncError::NoProgress)).boxed(); + let mut state_sync_runner = StateSyncRunner { request_receiver, storage_reader, sync_future }; + state_sync_runner.start().now_or_never().unwrap().unwrap_err(); +}