diff --git a/code/node/bin/main.rs b/code/node/bin/main.rs index a6e15b3af..0c8fce17f 100644 --- a/code/node/bin/main.rs +++ b/code/node/bin/main.rs @@ -1,11 +1,8 @@ -use std::net::{Ipv4Addr, SocketAddr}; - -use malachite_node::config::{Config, PeerConfig}; -use malachite_node::network::PeerId; +use malachite_node::util::make_config; use malachite_node::util::make_node; use malachite_test::utils::make_validators; -use malachite_test::{Validator, ValidatorSet}; +use malachite_test::ValidatorSet; use tracing::info; mod cli; @@ -13,19 +10,6 @@ use cli::Cli; const VOTING_PWERS: [u64; 3] = [5, 20, 10]; -fn make_config<'a>(vs: impl Iterator) -> Config { - let peers = vs - .enumerate() - .map(|(i, v)| PeerConfig { - id: PeerId::new(format!("node{}", i + 1)), - addr: SocketAddr::new(Ipv4Addr::LOCALHOST.into(), 1200 + i as u16 + 1), - public_key: v.public_key, - }) - .collect(); - - Config { peers } -} - #[tokio::main(flavor = "current_thread")] pub async fn main() { tracing_subscriber::fmt::init(); diff --git a/code/node/src/util/make_config.rs b/code/node/src/util/make_config.rs new file mode 100644 index 000000000..34ebe331c --- /dev/null +++ b/code/node/src/util/make_config.rs @@ -0,0 +1,19 @@ +use std::net::{Ipv4Addr, SocketAddr}; + +use malachite_test::Validator; + +use crate::config::{Config, PeerConfig}; +use crate::network::PeerId; + +pub fn make_config<'a>(vs: impl Iterator) -> Config { + let peers = vs + .enumerate() + .map(|(i, v)| PeerConfig { + id: PeerId::new(format!("node{}", i + 1)), + addr: SocketAddr::new(Ipv4Addr::LOCALHOST.into(), 1200 + i as u16 + 1), + public_key: v.public_key, + }) + .collect(); + + Config { peers } +} diff --git a/code/node/src/util/mod.rs b/code/node/src/util/mod.rs index ad2831098..c25fd0e1c 100644 --- a/code/node/src/util/mod.rs +++ b/code/node/src/util/mod.rs @@ -1,2 +1,5 @@ mod make_node; pub use make_node::make_node; + +mod make_config; +pub use make_config::make_config; diff --git a/code/node/tests/broadcast_n3f0.rs b/code/node/tests/broadcast_n3f0.rs index 5e671fc2e..dcead5db7 100644 --- a/code/node/tests/broadcast_n3f0.rs +++ b/code/node/tests/broadcast_n3f0.rs @@ -1,6 +1,5 @@ use malachite_common::Round; -use malachite_node::config::Config; -use malachite_node::util::make_node; +use malachite_node::util::{make_config, make_node}; use malachite_test::utils::make_validators; use malachite_test::{Height, ValidatorSet, Value}; @@ -8,11 +7,11 @@ use malachite_test::{Height, ValidatorSet, Value}; pub async fn decide_on_value() { tracing_subscriber::fmt::init(); - // Validators keys are deterministic and match the ones in the config file - let vs = make_validators([2, 3, 2]); + let voting_powers = [5, 20, 10, 30, 15, 1, 5, 25, 10, 15]; - let config = include_str!("../peers.toml"); - let config = toml::from_str::(config).expect("Error: invalid peers.toml"); + // Validators keys are deterministic and match the ones in the config file + let vs = make_validators(voting_powers); + let config = make_config(vs.iter().map(|(v, _)| v)); let mut handles = Vec::with_capacity(config.peers.len());