diff --git a/src/tests/mod.rs b/src/tests/mod.rs index eefedd5..bf5cd4a 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -47,10 +47,10 @@ pub(crate) fn db_test_schema() -> String { }) } -fn generate_node_announcement() -> NodeAnnouncement { +fn generate_node_announcement(private_key: Option) -> NodeAnnouncement { let secp_context = Secp256k1::new(); - let random_private_key = SecretKey::from_slice(&[1; 32]).unwrap(); + let random_private_key = private_key.unwrap_or(SecretKey::from_slice(&[1; 32]).unwrap()); let random_public_key = random_private_key.public_key(&secp_context); let node_id = NodeId::from_pubkey(&random_public_key); @@ -303,7 +303,7 @@ async fn test_node_announcement_persistence() { let (mut persister, receiver) = GossipPersister::new(network_graph_arc.clone(), logger.clone()); { // seed the db - let mut announcement = generate_node_announcement(); + let mut announcement = generate_node_announcement(None); receiver.send(GossipMessage::NodeAnnouncement(announcement.clone(), None)).await.unwrap(); receiver.send(GossipMessage::NodeAnnouncement(announcement.clone(), Some(12345))).await.unwrap(); @@ -346,16 +346,29 @@ async fn test_node_announcement_delta_detection() { let timestamp = current_time() - 10; { // seed the db - let mut announcement = generate_node_announcement(); + let mut announcement = generate_node_announcement(None); receiver.send(GossipMessage::NodeAnnouncement(announcement.clone(), Some(timestamp - 10))).await.unwrap(); receiver.send(GossipMessage::NodeAnnouncement(announcement.clone(), Some(timestamp - 8))).await.unwrap(); + { + let mut current_announcement = generate_node_announcement(Some(SecretKey::from_slice(&[2; 32]).unwrap())); + current_announcement.contents.features = NodeFeatures::from_be_bytes(vec![23, 48]); + receiver.send(GossipMessage::NodeAnnouncement(current_announcement, Some(timestamp))).await.unwrap(); + } + + { + let mut current_announcement = generate_node_announcement(Some(SecretKey::from_slice(&[3; 32]).unwrap())); + current_announcement.contents.features = NodeFeatures::from_be_bytes(vec![22, 49]); + receiver.send(GossipMessage::NodeAnnouncement(current_announcement, Some(timestamp))).await.unwrap(); + } + { // modify announcement to contain a bunch of addresses announcement.contents.addresses.push(SocketAddress::Hostname { hostname: "google.com".to_string().try_into().unwrap(), port: 443, }); + announcement.contents.features = NodeFeatures::from_be_bytes(vec![23, 48]); announcement.contents.addresses.push(SocketAddress::TcpIpV4 { addr: [127, 0, 0, 1], port: 9635 }); announcement.contents.addresses.push(SocketAddress::TcpIpV6 { addr: [1; 16], port: 1337 }); announcement.contents.addresses.push(SocketAddress::OnionV2([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])); @@ -397,7 +410,7 @@ async fn test_node_announcement_delta_detection() { assert_eq!(serialization.message_count, 3); assert_eq!(serialization.node_announcement_count, 3); assert_eq!(serialization.node_update_count, 1); - assert_eq!(serialization.node_feature_update_count, 0); + assert_eq!(serialization.node_feature_update_count, 1); assert_eq!(serialization.node_address_update_count, 1); } @@ -602,7 +615,7 @@ async fn test_channel_reminders() { logger.assert_log_contains("rapid_gossip_sync_server::lookup", "Processed intermediate rows (2)", 1); assert_eq!(serialization.message_count, 4); - assert_eq!(serialization.announcement_count, 0); + assert_eq!(serialization.channel_announcement_count, 0); assert_eq!(serialization.update_count, 4); assert_eq!(serialization.update_count_full, 0); assert_eq!(serialization.update_count_incremental, 4);