Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(starknet_state_sync): test state sync runner after refactor to p2p #2695

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/starknet_state_sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ tokio.workspace = true
validator.workspace = true

[dev-dependencies]
libp2p.workspace = true
papyrus_storage = { workspace = true, features = ["testing"] }
78 changes: 53 additions & 25 deletions crates/starknet_state_sync/src/runner/test.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,58 @@
// TODO: Refactor these to suit the change to state sync now using p2p sync.
use futures::future::{pending, ready};
use futures::FutureExt;
use papyrus_network::network_manager::NetworkError;
use papyrus_p2p_sync::client::P2PSyncClientError;
use starknet_sequencer_infra::component_definitions::ComponentStarter;

// 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;

// use super::StateSyncRunner;
#[test]
fn run_returns_when_network_future_returns() {
let network_future = ready(Ok(())).boxed();
let p2p_sync_client_future = pending().boxed();
let p2p_sync_server_future = pending().boxed();
let mut state_sync_runner =
StateSyncRunner { network_future, p2p_sync_client_future, p2p_sync_server_future };
state_sync_runner.start().now_or_never().unwrap().unwrap();
}

// const BUFFER_SIZE: usize = 1000;
#[test]
fn run_returns_when_sync_client_future_returns() {
let network_future = pending().boxed();
let p2p_sync_client_future = ready(Ok(())).boxed();
let p2p_sync_server_future = pending().boxed();
let mut state_sync_runner =
StateSyncRunner { network_future, p2p_sync_client_future, p2p_sync_server_future };
state_sync_runner.start().now_or_never().unwrap().unwrap();
}

// #[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_server_future_returns() {
let network_future = pending().boxed();
let p2p_sync_client_future = pending().boxed();
let p2p_sync_server_future = ready(()).boxed();
let mut state_sync_runner =
StateSyncRunner { network_future, p2p_sync_client_future, p2p_sync_server_future };
state_sync_runner.start().now_or_never().unwrap().unwrap_err();
}

// #[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();
// }
#[test]
fn run_returns_error_when_network_future_returns_error() {
let network_future =
ready(Err(NetworkError::DialError(libp2p::swarm::DialError::Aborted))).boxed();
let p2p_sync_client_future = pending().boxed();
let p2p_sync_server_future = pending().boxed();
let mut state_sync_runner =
StateSyncRunner { network_future, p2p_sync_client_future, p2p_sync_server_future };
state_sync_runner.start().now_or_never().unwrap().unwrap_err();
}

#[test]
fn run_returns_error_when_sync_client_future_returns_error() {
let network_future = pending().boxed();
let p2p_sync_client_future = ready(Err(P2PSyncClientError::TooManyResponses)).boxed();
let p2p_sync_server_future = pending().boxed();
let mut state_sync_runner =
StateSyncRunner { network_future, p2p_sync_client_future, p2p_sync_server_future };
state_sync_runner.start().now_or_never().unwrap().unwrap_err();
}
Loading