Skip to content

Commit

Permalink
Allow custom keys for node announcement tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
arik-so committed May 17, 2024
1 parent 6a84338 commit b45a67f
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ pub(crate) fn db_test_schema() -> String {
})
}

fn generate_node_announcement() -> NodeAnnouncement {
fn generate_node_announcement(private_key: Option<SecretKey>) -> 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);

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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]));
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit b45a67f

Please sign in to comment.