From 3fcbf104cfa0e834a700e98ad376b1b791c9e0ee Mon Sep 17 00:00:00 2001 From: pool2win Date: Wed, 2 Oct 2024 15:30:19 +0200 Subject: [PATCH] Re-org source tree to add integration tests --- src/lib.rs | 3 +++ src/main.rs | 14 +++----------- src/node.rs | 2 +- tests/run_nodes_test.rs | 24 ++++++++++++++++++++++++ 4 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 src/lib.rs create mode 100644 tests/run_nodes_test.rs diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..fc943d7 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,3 @@ +pub mod cli; +pub mod config; +pub mod node; diff --git a/src/main.rs b/src/main.rs index 7cd9607..9b61c35 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,12 +18,10 @@ use clap::Parser; use std::error::Error; -use tokio::sync::broadcast; -use tokio_util::bytes::Bytes; -mod cli; -mod config; -mod node; +use frost_federation::cli; +use frost_federation::config; +use frost_federation::node; #[tokio::main] async fn main() -> Result<(), Box> { @@ -35,12 +33,6 @@ async fn main() -> Result<(), Box> { setup_logging()?; setup_tracing()?; - // let manager = Arc::new(ConnectionManager::new(config.peer.max_peer_count)); - - let (send_to_all_tx, _) = broadcast::channel::(config.peer.max_pending_send_to_all); - let _connect_broadcast_sender = send_to_all_tx.clone(); - let _listen_broadcast_sender = send_to_all_tx.clone(); - let mut node = node::Node::new() .await .seeds(config.peer.seeds) diff --git a/src/node.rs b/src/node.rs index cd012a2..56a4504 100644 --- a/src/node.rs +++ b/src/node.rs @@ -53,7 +53,7 @@ pub struct Node { pub bind_address: String, pub static_key_pem: String, pub delivery_timeout: u64, - pub state: State, + pub(crate) state: State, } impl Node { diff --git a/tests/run_nodes_test.rs b/tests/run_nodes_test.rs new file mode 100644 index 0000000..96f65c0 --- /dev/null +++ b/tests/run_nodes_test.rs @@ -0,0 +1,24 @@ +use frost_federation::config; +use frost_federation::node; + +#[test] +fn test_start_a_single_node_should_complete_without_error() { + use tokio::time::{timeout, Duration}; + tokio::runtime::Builder::new_current_thread() + .enable_all() + .build() + .unwrap() + .block_on(async { + let config = config::load_config_from_file("config.run".to_string()).unwrap(); + let bind_address = config::get_bind_address(config.network); + + let mut node = node::Node::new() + .await + .seeds(config.peer.seeds) + .bind_address(bind_address) + .static_key_pem(config.noise.key) + .delivery_timeout(config.peer.delivery_timeout); + + let _ = timeout(Duration::from_millis(10), node.start()).await; + }); +}