diff --git a/docs b/docs index 5d53f4b22ab..c7b61befc0e 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 5d53f4b22ab659f659bb3d8dd07afcb51b9781fe +Subproject commit c7b61befc0ed3fb3b22d0154ae0f0658cb74eb4c diff --git a/massa-client/src/repl.rs b/massa-client/src/repl.rs index cffd66d6e79..d46e0582530 100644 --- a/massa-client/src/repl.rs +++ b/massa-client/src/repl.rs @@ -83,7 +83,7 @@ impl CommandHistory { } } - fn write_to_saved_history(command: &String) { + fn write_to_saved_history(command: &str) { if let Ok(mut file) = OpenOptions::new() .write(true) .append(true) diff --git a/massa-network/src/peer_info_database.rs b/massa-network/src/peer_info_database.rs index 77dfb8f24c3..84bb8923ac9 100644 --- a/massa-network/src/peer_info_database.rs +++ b/massa-network/src/peer_info_database.rs @@ -888,8 +888,10 @@ mod tests { #[tokio::test] #[serial] async fn test_try_new_in_connection_in_connection_closed() { - let mut network_settings = NetworkSettings::default(); - network_settings.target_out_nonbootstrap_connections = 5; + let network_settings = NetworkSettings { + target_out_nonbootstrap_connections: 5, + ..Default::default() + }; let mut peers: HashMap = HashMap::new(); // add peers @@ -906,14 +908,8 @@ mod tests { let wakeup_interval = network_settings.wakeup_interval; let (saver_watch_tx, mut saver_watch_rx) = watch::channel(peers.clone()); - let saver_join_handle = tokio::spawn(async move { - loop { - match saver_watch_rx.changed().await { - Ok(()) => (), - _ => break, - } - } - }); + let saver_join_handle = + tokio::spawn(async move { while let Ok(()) = saver_watch_rx.changed().await {} }); let mut db = PeerInfoDatabase { network_settings, @@ -937,7 +933,7 @@ mod tests { { assert_eq!(IpAddr::V4(std::net::Ipv4Addr::new(169, 202, 0, 11)), ip_err); } else { - assert!(false, "ToManyConnectionAttempt error not return"); + panic!("ToManyConnectionAttempt error not return"); } let res = db @@ -966,7 +962,7 @@ mod tests { { assert_eq!(IpAddr::V4(std::net::Ipv4Addr::new(169, 202, 0, 12)), ip_err); } else { - assert!(false, "ToManyConnectionAttempt error not return"); + panic!("ToManyConnectionAttempt error not return"); } // test with a not connected peer @@ -977,7 +973,7 @@ mod tests { { assert_eq!(IpAddr::V4(std::net::Ipv4Addr::new(169, 202, 0, 13)), ip_err); } else { - assert!(false, "PeerInfoNotFoundError error not return"); + panic!("PeerInfoNotFoundError error not return"); } db.in_connection_closed(&IpAddr::V4(std::net::Ipv4Addr::new(169, 202, 0, 11))) @@ -989,15 +985,17 @@ mod tests { { assert_eq!(IpAddr::V4(std::net::Ipv4Addr::new(169, 202, 0, 11)), ip_err); } else { - assert!(false, "ToManyConnectionAttempt error not return"); + panic!("ToManyConnectionAttempt error not return"); } } #[tokio::test] #[serial] async fn test_out_connection_attempt_failed() { - let mut network_settings = NetworkSettings::default(); - network_settings.target_out_nonbootstrap_connections = 5; + let network_settings = NetworkSettings { + target_out_nonbootstrap_connections: 5, + ..Default::default() + }; let mut peers: HashMap = HashMap::new(); // add peers @@ -1014,14 +1012,8 @@ mod tests { let wakeup_interval = network_settings.wakeup_interval; let (saver_watch_tx, mut saver_watch_rx) = watch::channel(peers.clone()); - let saver_join_handle = tokio::spawn(async move { - loop { - match saver_watch_rx.changed().await { - Ok(()) => (), - _ => break, - } - } - }); + let saver_join_handle = + tokio::spawn(async move { while let Ok(()) = saver_watch_rx.changed().await {} }); let mut db = PeerInfoDatabase { network_settings, @@ -1047,7 +1039,7 @@ mod tests { assert_eq!(IpAddr::V4(std::net::Ipv4Addr::new(169, 202, 0, 11)), ip_err); } else { println!("res: {:?}", res); - assert!(false, "ToManyConnectionFailure error not return"); + panic!("ToManyConnectionFailure error not return"); } db.new_out_connection_attempt(&IpAddr::V4(std::net::Ipv4Addr::new(169, 202, 0, 11))) @@ -1063,7 +1055,7 @@ mod tests { assert_eq!(IpAddr::V4(std::net::Ipv4Addr::new(169, 202, 0, 13)), ip_err); } else { println!("res: {:?}", res); - assert!(false, "PeerInfoNotFoundError error not return"); + panic!("PeerInfoNotFoundError error not return"); } // peer with no attempt. let res = @@ -1075,7 +1067,7 @@ mod tests { assert_eq!(IpAddr::V4(std::net::Ipv4Addr::new(169, 202, 0, 12)), ip_err); } else { println!("res: {:?}", res); - assert!(false, "ToManyConnectionFailure error not return"); + panic!("ToManyConnectionFailure error not return"); } // call ok. @@ -1090,15 +1082,17 @@ mod tests { { assert_eq!(IpAddr::V4(std::net::Ipv4Addr::new(169, 202, 0, 11)), ip_err); } else { - assert!(false, "ToManyConnectionFailure error not return"); + panic!("ToManyConnectionFailure error not return"); } } #[tokio::test] #[serial] async fn test_try_out_connection_attempt_success() { - let mut network_settings = NetworkSettings::default(); - network_settings.target_out_nonbootstrap_connections = 5; + let network_settings = NetworkSettings { + target_out_nonbootstrap_connections: 5, + ..Default::default() + }; let mut peers: HashMap = HashMap::new(); // add peers @@ -1115,14 +1109,8 @@ mod tests { let wakeup_interval = network_settings.wakeup_interval; let (saver_watch_tx, mut saver_watch_rx) = watch::channel(peers.clone()); - let saver_join_handle = tokio::spawn(async move { - loop { - match saver_watch_rx.changed().await { - Ok(()) => (), - _ => break, - } - } - }); + let saver_join_handle = + tokio::spawn(async move { while let Ok(()) = saver_watch_rx.changed().await {} }); let mut db = PeerInfoDatabase { network_settings, @@ -1148,7 +1136,7 @@ mod tests { { assert_eq!(IpAddr::V4(std::net::Ipv4Addr::new(169, 202, 0, 11)), ip_err); } else { - assert!(false, "ToManyConnectionAttempt error not return"); + panic!("ToManyConnectionAttempt error not return"); } db.new_out_connection_attempt(&IpAddr::V4(std::net::Ipv4Addr::new(169, 202, 0, 11))) @@ -1165,7 +1153,7 @@ mod tests { assert_eq!(IpAddr::V4(std::net::Ipv4Addr::new(169, 202, 0, 13)), ip_err); } else { println!("res: {:?}", res); - assert!(false, "PeerInfoNotFoundError error not return"); + panic!("PeerInfoNotFoundError error not return"); } let res = db @@ -1184,7 +1172,7 @@ mod tests { { assert_eq!(IpAddr::V4(std::net::Ipv4Addr::new(169, 202, 0, 12)), ip_err); } else { - assert!(false, "PeerInfoNotFoundError error not return"); + panic!("PeerInfoNotFoundError error not return"); } db.new_out_connection_attempt(&IpAddr::V4(std::net::Ipv4Addr::new(169, 202, 0, 12))) @@ -1200,8 +1188,10 @@ mod tests { #[tokio::test] #[serial] async fn test_new_out_connection_closed() { - let mut network_settings = NetworkSettings::default(); - network_settings.max_out_nonbootstrap_connection_attempts = 5; + let network_settings = NetworkSettings { + max_out_nonbootstrap_connection_attempts: 5, + ..Default::default() + }; let mut peers: HashMap = HashMap::new(); // add peers @@ -1211,14 +1201,8 @@ mod tests { peers.insert(connected_peers1.ip, connected_peers1); let wakeup_interval = network_settings.wakeup_interval; let (saver_watch_tx, mut saver_watch_rx) = watch::channel(peers.clone()); - let saver_join_handle = tokio::spawn(async move { - loop { - match saver_watch_rx.changed().await { - Ok(()) => (), - _ => break, - } - } - }); + let saver_join_handle = + tokio::spawn(async move { while let Ok(()) = saver_watch_rx.changed().await {} }); let mut db = PeerInfoDatabase { network_settings, @@ -1242,10 +1226,7 @@ mod tests { { assert_eq!(IpAddr::V4(std::net::Ipv4Addr::new(169, 202, 0, 11)), ip_err); } else { - assert!( - false, - "CloseConnectionWithNoConnectionToClose error not return" - ); + panic!("CloseConnectionWithNoConnectionToClose error not return"); } // add a new connection attempt @@ -1265,7 +1246,7 @@ mod tests { { assert_eq!(IpAddr::V4(std::net::Ipv4Addr::new(169, 202, 0, 12)), ip_err); } else { - assert!(false, "PeerInfoNotFoundError error not return"); + panic!("PeerInfoNotFoundError error not return"); } db.out_connection_closed(&IpAddr::V4(std::net::Ipv4Addr::new(169, 202, 0, 11))) @@ -1277,18 +1258,17 @@ mod tests { { assert_eq!(IpAddr::V4(std::net::Ipv4Addr::new(169, 202, 0, 11)), ip_err); } else { - assert!( - false, - "CloseConnectionWithNoConnectionToClose error not return" - ); + panic!("CloseConnectionWithNoConnectionToClose error not return"); } } #[tokio::test] #[serial] async fn test_new_out_connection_attempt() { - let mut network_settings = NetworkSettings::default(); - network_settings.max_out_nonbootstrap_connection_attempts = 5; + let network_settings = NetworkSettings { + max_out_nonbootstrap_connection_attempts: 5, + ..Default::default() + }; let mut peers: HashMap = HashMap::new(); // add peers @@ -1320,7 +1300,7 @@ mod tests { if let Err(NetworkError::InvalidIpError(ip_err)) = res { assert_eq!(IpAddr::V4(std::net::Ipv4Addr::new(192, 168, 0, 11)), ip_err); } else { - assert!(false, "InvalidIpError not return"); + panic!("InvalidIpError not return"); } let res = @@ -1331,7 +1311,7 @@ mod tests { { assert_eq!(IpAddr::V4(std::net::Ipv4Addr::new(169, 202, 0, 12)), ip_err); } else { - assert!(false, "PeerInfoNotFoundError error not return"); + panic!("PeerInfoNotFoundError error not return"); } (0..5).for_each(|_| { @@ -1346,7 +1326,7 @@ mod tests { { assert_eq!(IpAddr::V4(std::net::Ipv4Addr::new(169, 202, 0, 11)), ip_err); } else { - assert!(false, "ToManyConnectionAttempt error not return"); + panic!("ToManyConnectionAttempt error not return"); } } @@ -1551,9 +1531,11 @@ mod tests { #[tokio::test] #[serial] async fn test_cleanup_peers() { - let mut network_settings = NetworkSettings::default(); - network_settings.max_banned_peers = 1; - network_settings.max_idle_peers = 1; + let mut network_settings = NetworkSettings { + max_banned_peers: 1, + max_idle_peers: 1, + ..Default::default() + }; let mut peers = HashMap::new(); // Call with empty db. @@ -1679,7 +1661,7 @@ mod tests { async fn test() { let peer_db = PeerInfoDatabase::from(5); let p = peer_db.peers.values().next().unwrap(); - assert_eq!(p.is_active(), false); + assert!(!p.is_active()); } fn default_peer_info_connected(ip: IpAddr) -> PeerInfo { diff --git a/massa-network/src/tests/mock_establisher.rs b/massa-network/src/tests/mock_establisher.rs index 7e92a7dea68..3b9883bf23c 100644 --- a/massa-network/src/tests/mock_establisher.rs +++ b/massa-network/src/tests/mock_establisher.rs @@ -39,14 +39,12 @@ pub struct MockListener { impl MockListener { pub async fn accept(&mut self) -> std::io::Result<(ReadHalf, WriteHalf, SocketAddr)> { - let (addr, sender) = self - .connection_listener_rx - .recv() - .await - .ok_or(io::Error::new( + let (addr, sender) = self.connection_listener_rx.recv().await.ok_or_else(|| { + io::Error::new( io::ErrorKind::Other, "MockListener accept channel from Establisher closed".to_string(), - ))?; + ) + })?; let (duplex_controller, duplex_mock) = tokio::io::duplex(MAX_DUPLEX_BUFFER_SIZE); let (duplex_mock_read, duplex_mock_write) = tokio::io::split(duplex_controller); let (duplex_controller_read, duplex_controller_write) = tokio::io::split(duplex_mock); @@ -151,10 +149,12 @@ impl MockEstablisherInterface { &self, addr: &SocketAddr, ) -> io::Result<(ReadHalf, WriteHalf)> { - let sender = self.connection_listener_tx.as_ref().ok_or(io::Error::new( - io::ErrorKind::Other, - "mock connect_to_controller_listener channel not initialized".to_string(), - ))?; + let sender = self.connection_listener_tx.as_ref().ok_or_else(|| { + io::Error::new( + io::ErrorKind::Other, + "mock connect_to_controller_listener channel not initialized".to_string(), + ) + })?; let (response_tx, response_rx) = oneshot::channel::<(ReadHalf, WriteHalf)>(); sender.send((*addr, response_tx)).await.map_err(|_err| { io::Error::new( @@ -175,13 +175,12 @@ impl MockEstablisherInterface { pub async fn wait_connection_attempt_from_controller( &mut self, ) -> io::Result<(ReadHalf, WriteHalf, SocketAddr, oneshot::Sender)> { - self.connection_connector_rx - .recv() - .await - .ok_or(io::Error::new( + self.connection_connector_rx.recv().await.ok_or_else(|| { + io::Error::new( io::ErrorKind::Other, "MockListener get_connect_stream channel from connector closed".to_string(), - )) + ) + }) } /* diff --git a/massa-network/src/tests/scenarios.rs b/massa-network/src/tests/scenarios.rs index 9b5cfe8304d..a9124de31c1 100644 --- a/massa-network/src/tests/scenarios.rs +++ b/massa-network/src/tests/scenarios.rs @@ -31,7 +31,7 @@ use tracing::trace; #[serial] async fn test_node_worker_shutdown() { let bind_port: u16 = 50_000; - let temp_peers_file = super::tools::generate_peers_file(&vec![]); + let temp_peers_file = super::tools::generate_peers_file(&[]); let network_conf = super::tools::create_network_config(bind_port, temp_peers_file.path()); let (duplex_controller, _duplex_mock) = tokio::io::duplex(1); let (duplex_mock_read, duplex_mock_write) = tokio::io::split(duplex_controller); @@ -94,7 +94,7 @@ async fn test_multiple_connections_to_controller() { // test config let bind_port: u16 = 50_000; - let temp_peers_file = super::tools::generate_peers_file(&vec![]); + let temp_peers_file = super::tools::generate_peers_file(&[]); let mut network_conf = super::tools::create_network_config(bind_port, temp_peers_file.path()); network_conf.max_in_nonbootstrap_connections = 2; network_conf.max_in_connections_per_ip = 1; @@ -196,7 +196,7 @@ async fn test_peer_ban() { let mock_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(169, 202, 0, 11)), bind_port); // add advertised peer to controller - let temp_peers_file = super::tools::generate_peers_file(&vec![PeerInfo { + let temp_peers_file = super::tools::generate_peers_file(&[PeerInfo { ip: mock_addr.ip(), banned: false, bootstrap: false, @@ -335,7 +335,7 @@ async fn test_peer_ban_by_ip() { let mock_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(169, 202, 0, 11)), bind_port); // add advertised peer to controller - let temp_peers_file = super::tools::generate_peers_file(&vec![PeerInfo { + let temp_peers_file = super::tools::generate_peers_file(&[PeerInfo { ip: mock_addr.ip(), banned: false, bootstrap: false, @@ -472,7 +472,7 @@ async fn test_advertised_and_wakeup_interval() { let bind_port: u16 = 50_000; let mock_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(169, 202, 0, 12)), bind_port); let mock_ignore_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(169, 202, 0, 13)), bind_port); - let temp_peers_file = super::tools::generate_peers_file(&vec![PeerInfo { + let temp_peers_file = super::tools::generate_peers_file(&[PeerInfo { ip: mock_ignore_addr.ip(), banned: false, bootstrap: true, @@ -603,7 +603,7 @@ async fn test_block_not_found() { let mock_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(169, 202, 0, 11)), bind_port); // add advertised peer to controller - let temp_peers_file = super::tools::generate_peers_file(&vec![PeerInfo { + let temp_peers_file = super::tools::generate_peers_file(&[PeerInfo { ip: mock_addr.ip(), banned: false, bootstrap: true, @@ -679,21 +679,22 @@ async fn test_block_not_found() { tokio::select! { evt = conn1_r.next() => { let evt = evt.unwrap().unwrap().1; - match evt { - Message::BlockNotFound(hash) => {assert_eq!(hash, wanted_hash); break;} - _ => {} - }}, + if let Message::BlockNotFound(hash) = evt {assert_eq!(hash, wanted_hash); + break; + } + }, _ = &mut timer => panic!("timeout reached waiting for message") } } // test send AskForBlocks with more max_ask_blocks_per_message using node_worker split in several message function. let mut block_list: HashMap> = HashMap::new(); - let mut hash_list = vec![]; - hash_list.push(get_dummy_block_id("default_val1")); - hash_list.push(get_dummy_block_id("default_val2")); - hash_list.push(get_dummy_block_id("default_val3")); - hash_list.push(get_dummy_block_id("default_val4")); + let hash_list = vec![ + get_dummy_block_id("default_val1"), + get_dummy_block_id("default_val2"), + get_dummy_block_id("default_val3"), + get_dummy_block_id("default_val4"), + ]; block_list.insert(conn1_id, hash_list); network_command_sender @@ -707,15 +708,12 @@ async fn test_block_not_found() { tokio::select! { evt = conn1_r.next() => { let evt = evt.unwrap().unwrap().1; - match evt { - Message::AskForBlocks(list1) => { - assert!(list1.contains(&get_dummy_block_id("default_val1"))); - assert!(list1.contains(&get_dummy_block_id("default_val2"))); - assert!(list1.contains(&get_dummy_block_id("default_val3"))); - break; - } - _ => {} - }}, + if let Message::AskForBlocks(list1) = evt { + assert!(list1.contains(&get_dummy_block_id("default_val1"))); + assert!(list1.contains(&get_dummy_block_id("default_val2"))); + assert!(list1.contains(&get_dummy_block_id("default_val3"))); + break; + }}, _ = &mut timer => panic!("timeout reached waiting for message") } } @@ -725,10 +723,11 @@ async fn test_block_not_found() { tokio::select! { evt = conn1_r.next() => { let evt = evt.unwrap().unwrap().1; - match evt { - Message::AskForBlocks(list2) => {assert!(list2.contains(&get_dummy_block_id("default_val4"))); break;} - _ => {} - }}, + if let Message::AskForBlocks(list2) = evt { + assert!(list2.contains(&get_dummy_block_id("default_val4"))); + break; + } + }, _ = &mut timer => panic!("timeout reached waiting for message") } } @@ -749,17 +748,26 @@ async fn test_block_not_found() { .await .unwrap(); // assert it is sent to protocol - if tools::wait_network_event(&mut network_event_receiver, 1000.into(), |msg| match msg - { + if tools::wait_network_event( + &mut network_event_receiver, + 1000.into(), + |msg| match msg { NetworkEvent::AskedForBlocks { list, node } => Some((list, node)), _ => None, - }) - .await.is_some() + }, + ) + .await + .is_some() { panic!("AskedForBlocks with more max_ask_blocks_per_message forward blocks"); } let conn1_drain = tools::incoming_message_drain_start(conn1_r).await; - (network_event_receiver, network_manager, mock_interface, vec![conn1_drain]) + ( + network_event_receiver, + network_manager, + mock_interface, + vec![conn1_drain], + ) }, ) .await; @@ -780,7 +788,7 @@ async fn test_retry_connection_closed() { let mock_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(169, 202, 0, 11)), bind_port); // add advertised peer to controller - let temp_peers_file = super::tools::generate_peers_file(&vec![PeerInfo { + let temp_peers_file = super::tools::generate_peers_file(&[PeerInfo { ip: mock_addr.ip(), banned: false, bootstrap: true, @@ -877,7 +885,7 @@ async fn test_operation_messages() { let mock_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(169, 202, 0, 11)), bind_port); // add advertised peer to controller - let temp_peers_file = super::tools::generate_peers_file(&vec![PeerInfo { + let temp_peers_file = super::tools::generate_peers_file(&[PeerInfo { ip: mock_addr.ip(), banned: false, bootstrap: true, @@ -960,14 +968,13 @@ async fn test_operation_messages() { tokio::select! { evt = conn1_r.next() => { let evt = evt.unwrap().unwrap().1; - match evt { - Message::Operations(op) => { + if let Message::Operations(op) = evt { assert_eq!(op.len(), 1); let res_id = op[0].verify_integrity().unwrap(); assert_eq!(ref_id2, res_id); - break;} - _ => {} - }}, + break; + } + }, _ = &mut timer => panic!("timeout reached waiting for message") } } @@ -998,7 +1005,7 @@ async fn test_endorsements_messages() { let mock_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(169, 202, 0, 11)), bind_port); // add advertised peer to controller - let temp_peers_file = super::tools::generate_peers_file(&vec![PeerInfo { + let temp_peers_file = super::tools::generate_peers_file(&[PeerInfo { ip: mock_addr.ip(), banned: false, bootstrap: true, @@ -1106,14 +1113,13 @@ async fn test_endorsements_messages() { tokio::select! { evt = conn1_r.next() => { let evt = evt.unwrap().unwrap().1; - match evt { - Message::Endorsements(endorsements) => { + if let Message::Endorsements(endorsements) = evt { assert_eq!(endorsements.len(), 1); let res_id = endorsements[0].compute_endorsement_id().unwrap(); assert_eq!(ref_id, res_id); - break;} - _ => {} - }}, + break; + } + }, _ = &mut timer => panic!("timeout reached waiting for message") } } diff --git a/massa-network/src/tests/tools.rs b/massa-network/src/tests/tools.rs index 0e752c8546f..c5cef17abb1 100644 --- a/massa-network/src/tests/tools.rs +++ b/massa-network/src/tests/tools.rs @@ -33,7 +33,7 @@ pub fn get_dummy_block_id(s: &str) -> BlockId { } /// generate a named temporary JSON peers file -pub fn generate_peers_file(peer_vec: &Vec) -> NamedTempFile { +pub fn generate_peers_file(peer_vec: &[PeerInfo]) -> NamedTempFile { use std::io::prelude::*; let peers_file_named = NamedTempFile::new().expect("cannot create temp file"); serde_json::to_writer_pretty(peers_file_named.as_file(), &peer_vec) diff --git a/massa-protocol-worker/src/tests/ban_nodes_scenarios.rs b/massa-protocol-worker/src/tests/ban_nodes_scenarios.rs index abef543d524..95bd4aea094 100644 --- a/massa-protocol-worker/src/tests/ban_nodes_scenarios.rs +++ b/massa-protocol-worker/src/tests/ban_nodes_scenarios.rs @@ -324,9 +324,9 @@ async fn test_protocol_does_not_send_blocks_when_asked_for_by_banned_node() { .expect("Failed to compute hash."); // 3. Simulate two nodes asking for a block. - for n in 0..2 { + for node in nodes.iter().take(2) { network_controller - .send_ask_for_block(nodes[n].id, vec![expected_hash]) + .send_ask_for_block(node.id, vec![expected_hash]) .await; // Check protocol sends get block event to consensus. diff --git a/massa-protocol-worker/src/tests/endorsements_scenarios.rs b/massa-protocol-worker/src/tests/endorsements_scenarios.rs index 6edec9f46dd..44fc2169b8d 100644 --- a/massa-protocol-worker/src/tests/endorsements_scenarios.rs +++ b/massa-protocol-worker/src/tests/endorsements_scenarios.rs @@ -93,20 +93,18 @@ async fn test_protocol_does_not_send_invalid_endorsements_it_receives_to_pool() .await; // Check protocol does not send endorsements to pool. - match tools::wait_protocol_pool_event( - &mut protocol_pool_event_receiver, - 1000.into(), - |evt| match evt { - evt @ ProtocolPoolEvent::ReceivedEndorsements { .. } => Some(evt), - _ => None, - }, - ) - .await + if let Some(ProtocolPoolEvent::ReceivedEndorsements { .. }) = + tools::wait_protocol_pool_event( + &mut protocol_pool_event_receiver, + 1000.into(), + |evt| match evt { + evt @ ProtocolPoolEvent::ReceivedEndorsements { .. } => Some(evt), + _ => None, + }, + ) + .await { - Some(ProtocolPoolEvent::ReceivedEndorsements { .. }) => { - panic!("Protocol send invalid endorsements.") - } - _ => {} + panic!("Protocol send invalid endorsements.") }; ( diff --git a/massa-protocol-worker/src/tests/operations_scenarios.rs b/massa-protocol-worker/src/tests/operations_scenarios.rs index df11e66d525..bc2231e5650 100644 --- a/massa-protocol-worker/src/tests/operations_scenarios.rs +++ b/massa-protocol-worker/src/tests/operations_scenarios.rs @@ -96,20 +96,18 @@ async fn test_protocol_does_not_send_invalid_operations_it_receives_to_consensus .await; // Check protocol does not send operations to consensus. - match tools::wait_protocol_pool_event( - &mut protocol_pool_event_receiver, - 1000.into(), - |evt| match evt { - evt @ ProtocolPoolEvent::ReceivedOperations { .. } => Some(evt), - _ => None, - }, - ) - .await + if let Some(ProtocolPoolEvent::ReceivedOperations { .. }) = + tools::wait_protocol_pool_event( + &mut protocol_pool_event_receiver, + 1000.into(), + |evt| match evt { + evt @ ProtocolPoolEvent::ReceivedOperations { .. } => Some(evt), + _ => None, + }, + ) + .await { - Some(ProtocolPoolEvent::ReceivedOperations { .. }) => { - panic!("Protocol send invalid operations.") - } - _ => {} + panic!("Protocol send invalid operations.") }; ( @@ -738,7 +736,7 @@ async fn test_protocol_does_not_propagates_operations_when_receiving_those_insid operations, }) => { let expected_id = operation.verify_integrity().unwrap(); - assert_eq!(propagate, false); + assert!(!propagate); assert_eq!( operations .get(&expected_id) diff --git a/massa-protocol-worker/src/tests/scenarios.rs b/massa-protocol-worker/src/tests/scenarios.rs index afb5da3eb72..4665dbec1ce 100644 --- a/massa-protocol-worker/src/tests/scenarios.rs +++ b/massa-protocol-worker/src/tests/scenarios.rs @@ -136,9 +136,9 @@ async fn test_protocol_sends_blocks_when_asked_for() { let expected_hash = block.header.compute_block_id().unwrap(); // 3. Simulate two nodes asking for a block. - for n in 0..2 { + for node in nodes.iter().take(2) { network_controller - .send_ask_for_block(nodes[n].id, vec![expected_hash]) + .send_ask_for_block(node.id, vec![expected_hash]) .await; // Check protocol sends get block event to consensus.