Skip to content

Commit

Permalink
Add test for persisting announced node
Browse files Browse the repository at this point in the history
  • Loading branch information
contrun committed Oct 21, 2024
1 parent c67a5bb commit d8405d1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/fiber/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2381,7 +2381,7 @@ impl PersistentNetworkActorState {
.saved_peer_addresses
.keys()
.into_iter()
.chain(self.saved_peer_addresses.keys().into_iter())
.chain(self.announced_peer_addresses.keys().into_iter())
.collect::<HashSet<_, RandomState>>();

nodes
Expand Down
27 changes: 27 additions & 0 deletions src/fiber/tests/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,33 @@ async fn test_persisting_bootnode() {
assert_eq!(peers.get(&boot_peer_id), Some(&vec![address]));
}

#[tokio::test]
async fn test_persisting_announced_nodes() {
let mut node = new_synced_node("test").await;

let announcement = create_fake_node_announcement_mesage_version1();
let node_pk = announcement.node_id;
let peer_id = node_pk.tentacle_peer_id();

node.network_actor
.send_message(NetworkActorMessage::Event(NetworkActorEvent::PeerMessage(
peer_id.clone(),
FiberMessage::BroadcastMessage(FiberBroadcastMessage::NodeAnnouncement(
create_fake_node_announcement_mesage_version1(),
)),
)))
.expect("send message to network actor");

// Wait for the above message to be processed.
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;

node.stop().await;
let state = node.store.clone();
let state = state.get_network_actor_state(&node.peer_id).unwrap();
let peers = state.sample_n_peers_to_connect(1);
assert!(peers.get(&peer_id).is_some());
}

#[tokio::test]
async fn test_connecting_to_bootnode() {
let boot_node = NetworkNode::new().await;
Expand Down

0 comments on commit d8405d1

Please sign in to comment.