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

Add test node herself in reserved nodes. #2390

Merged
merged 13 commits into from
Nov 14, 2024
Merged
Changes from 4 commits
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
30 changes: 30 additions & 0 deletions crates/services/p2p/src/p2p_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,7 @@ mod tests {
Topic,
},
identity::Keypair,
multiaddr::multiaddr,
swarm::{
ListenError,
SwarmEvent,
Expand All @@ -893,6 +894,10 @@ mod tests {
use rand::Rng;
use std::{
collections::HashSet,
net::{
IpAddr,
Ipv4Addr,
},
ops::Range,
sync::Arc,
time::Duration,
Expand Down Expand Up @@ -1036,6 +1041,31 @@ mod tests {
stop_sender.send(()).unwrap();
}

#[tokio::test]
#[instrument]
async fn our_node_in_reserved_nodes() {
let mut p2p_config = Config::default_initialized("own_node_in_reserved_nodes");
p2p_config.address = IpAddr::V4(Ipv4Addr::from([0, 0, 0, 0]));
p2p_config.tcp_port = 11111;
AurelienFT marked this conversation as resolved.
Show resolved Hide resolved
let multiaddr = multiaddr!(Ip4([127, 0, 0, 1]), Tcp(11111u16))
.with_p2p(p2p_config.keypair.public().to_peer_id())
.unwrap();
p2p_config.public_address = Some(multiaddr.clone());
p2p_config.reserved_nodes = vec![multiaddr];

let mut node = build_service_from_config(p2p_config).await;
tokio::time::timeout(Duration::from_secs(2), async move {
loop {
let event = node.next_event().await;
if let Some(FuelP2PEvent::PeerConnected(_)) = event {
panic!("The node should not connect to itself");
}
}
})
.await
.expect_err("The node should not connect to itself");
}

// We start with two nodes, node_a and node_b, bootstrapped with `bootstrap_nodes_count` other nodes.
// Yet node_a and node_b are only allowed to connect to specified amount of nodes.
#[tokio::test]
Expand Down
Loading