Skip to content

Commit 806fef5

Browse files
committed
Use OnionMessenger::send_onion_message in tests
Use OnionMessenger's public interface in tests whenever possible (i.e., when not using any intermediate_nodes in an OnionMessagePath. This allows us to exercise DefaultMessageRouter, and, in particular that a path can be found for an unannounced sender when its in the introduction node.
1 parent ad3de23 commit 806fef5

File tree

1 file changed

+20
-55
lines changed

1 file changed

+20
-55
lines changed

lightning/src/onion_message/functional_tests.rs

Lines changed: 20 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -250,12 +250,8 @@ fn one_unblinded_hop() {
250250
let nodes = create_nodes(2);
251251
let test_msg = TestCustomMessage::Response;
252252

253-
let path = OnionMessagePath {
254-
intermediate_nodes: vec![],
255-
destination: Destination::Node(nodes[1].node_id),
256-
first_node_addresses: None,
257-
};
258-
nodes[0].messenger.send_onion_message_using_path(path, test_msg, None).unwrap();
253+
let destination = Destination::Node(nodes[1].node_id);
254+
nodes[0].messenger.send_onion_message(test_msg, destination, None).unwrap();
259255
nodes[1].custom_message_handler.expect_message(TestCustomMessage::Response);
260256
pass_along_path(&nodes);
261257
}
@@ -270,6 +266,7 @@ fn two_unblinded_hops() {
270266
destination: Destination::Node(nodes[2].node_id),
271267
first_node_addresses: None,
272268
};
269+
273270
nodes[0].messenger.send_onion_message_using_path(path, test_msg, None).unwrap();
274271
nodes[2].custom_message_handler.expect_message(TestCustomMessage::Response);
275272
pass_along_path(&nodes);
@@ -282,12 +279,8 @@ fn one_blinded_hop() {
282279

283280
let secp_ctx = Secp256k1::new();
284281
let blinded_path = BlindedPath::new_for_message(&[nodes[1].node_id], &*nodes[1].entropy_source, &secp_ctx).unwrap();
285-
let path = OnionMessagePath {
286-
intermediate_nodes: vec![],
287-
destination: Destination::BlindedPath(blinded_path),
288-
first_node_addresses: None,
289-
};
290-
nodes[0].messenger.send_onion_message_using_path(path, test_msg, None).unwrap();
282+
let destination = Destination::BlindedPath(blinded_path);
283+
nodes[0].messenger.send_onion_message(test_msg, destination, None).unwrap();
291284
nodes[1].custom_message_handler.expect_message(TestCustomMessage::Response);
292285
pass_along_path(&nodes);
293286
}
@@ -317,13 +310,9 @@ fn three_blinded_hops() {
317310

318311
let secp_ctx = Secp256k1::new();
319312
let blinded_path = BlindedPath::new_for_message(&[nodes[1].node_id, nodes[2].node_id, nodes[3].node_id], &*nodes[3].entropy_source, &secp_ctx).unwrap();
320-
let path = OnionMessagePath {
321-
intermediate_nodes: vec![],
322-
destination: Destination::BlindedPath(blinded_path),
323-
first_node_addresses: None,
324-
};
313+
let destination = Destination::BlindedPath(blinded_path);
325314

326-
nodes[0].messenger.send_onion_message_using_path(path, test_msg, None).unwrap();
315+
nodes[0].messenger.send_onion_message(test_msg, destination, None).unwrap();
327316
nodes[3].custom_message_handler.expect_message(TestCustomMessage::Response);
328317
pass_along_path(&nodes);
329318
}
@@ -354,24 +343,16 @@ fn we_are_intro_node() {
354343

355344
let secp_ctx = Secp256k1::new();
356345
let blinded_path = BlindedPath::new_for_message(&[nodes[0].node_id, nodes[1].node_id, nodes[2].node_id], &*nodes[2].entropy_source, &secp_ctx).unwrap();
357-
let path = OnionMessagePath {
358-
intermediate_nodes: vec![],
359-
destination: Destination::BlindedPath(blinded_path),
360-
first_node_addresses: None,
361-
};
346+
let destination = Destination::BlindedPath(blinded_path);
362347

363-
nodes[0].messenger.send_onion_message_using_path(path, test_msg.clone(), None).unwrap();
348+
nodes[0].messenger.send_onion_message(test_msg.clone(), destination, None).unwrap();
364349
nodes[2].custom_message_handler.expect_message(TestCustomMessage::Response);
365350
pass_along_path(&nodes);
366351

367352
// Try with a two-hop blinded path where we are the introduction node.
368353
let blinded_path = BlindedPath::new_for_message(&[nodes[0].node_id, nodes[1].node_id], &*nodes[1].entropy_source, &secp_ctx).unwrap();
369-
let path = OnionMessagePath {
370-
intermediate_nodes: vec![],
371-
destination: Destination::BlindedPath(blinded_path),
372-
first_node_addresses: None,
373-
};
374-
nodes[0].messenger.send_onion_message_using_path(path, test_msg, None).unwrap();
354+
let destination = Destination::BlindedPath(blinded_path);
355+
nodes[0].messenger.send_onion_message(test_msg, destination, None).unwrap();
375356
nodes[1].custom_message_handler.expect_message(TestCustomMessage::Response);
376357
nodes.remove(2);
377358
pass_along_path(&nodes);
@@ -387,12 +368,8 @@ fn invalid_blinded_path_error() {
387368
let secp_ctx = Secp256k1::new();
388369
let mut blinded_path = BlindedPath::new_for_message(&[nodes[1].node_id, nodes[2].node_id], &*nodes[2].entropy_source, &secp_ctx).unwrap();
389370
blinded_path.blinded_hops.clear();
390-
let path = OnionMessagePath {
391-
intermediate_nodes: vec![],
392-
destination: Destination::BlindedPath(blinded_path),
393-
first_node_addresses: None,
394-
};
395-
let err = nodes[0].messenger.send_onion_message_using_path(path, test_msg.clone(), None).unwrap_err();
371+
let destination = Destination::BlindedPath(blinded_path);
372+
let err = nodes[0].messenger.send_onion_message(test_msg, destination, None).unwrap_err();
396373
assert_eq!(err, SendError::TooFewBlindedHops);
397374
}
398375

@@ -419,14 +396,10 @@ fn reply_path() {
419396

420397
// Destination::BlindedPath
421398
let blinded_path = BlindedPath::new_for_message(&[nodes[1].node_id, nodes[2].node_id, nodes[3].node_id], &*nodes[3].entropy_source, &secp_ctx).unwrap();
422-
let path = OnionMessagePath {
423-
intermediate_nodes: vec![],
424-
destination: Destination::BlindedPath(blinded_path),
425-
first_node_addresses: None,
426-
};
399+
let destination = Destination::BlindedPath(blinded_path);
427400
let reply_path = BlindedPath::new_for_message(&[nodes[2].node_id, nodes[1].node_id, nodes[0].node_id], &*nodes[0].entropy_source, &secp_ctx).unwrap();
428401

429-
nodes[0].messenger.send_onion_message_using_path(path, test_msg, Some(reply_path)).unwrap();
402+
nodes[0].messenger.send_onion_message(test_msg, destination, Some(reply_path)).unwrap();
430403
nodes[3].custom_message_handler.expect_message(TestCustomMessage::Request);
431404
pass_along_path(&nodes);
432405

@@ -454,28 +427,20 @@ fn invalid_custom_message_type() {
454427
}
455428

456429
let test_msg = InvalidCustomMessage {};
457-
let path = OnionMessagePath {
458-
intermediate_nodes: vec![],
459-
destination: Destination::Node(nodes[1].node_id),
460-
first_node_addresses: None,
461-
};
462-
let err = nodes[0].messenger.send_onion_message_using_path(path, test_msg, None).unwrap_err();
430+
let destination = Destination::Node(nodes[1].node_id);
431+
let err = nodes[0].messenger.send_onion_message(test_msg, destination, None).unwrap_err();
463432
assert_eq!(err, SendError::InvalidMessage);
464433
}
465434

466435
#[test]
467436
fn peer_buffer_full() {
468437
let nodes = create_nodes(2);
469438
let test_msg = TestCustomMessage::Request;
470-
let path = OnionMessagePath {
471-
intermediate_nodes: vec![],
472-
destination: Destination::Node(nodes[1].node_id),
473-
first_node_addresses: None,
474-
};
439+
let destination = Destination::Node(nodes[1].node_id);
475440
for _ in 0..188 { // Based on MAX_PER_PEER_BUFFER_SIZE in OnionMessenger
476-
nodes[0].messenger.send_onion_message_using_path(path.clone(), test_msg.clone(), None).unwrap();
441+
nodes[0].messenger.send_onion_message(test_msg.clone(), destination.clone(), None).unwrap();
477442
}
478-
let err = nodes[0].messenger.send_onion_message_using_path(path, test_msg, None).unwrap_err();
443+
let err = nodes[0].messenger.send_onion_message(test_msg, destination, None).unwrap_err();
479444
assert_eq!(err, SendError::BufferFull);
480445
}
481446

0 commit comments

Comments
 (0)