+ "lightning::onion_message::messenger",
+ &format!("Received an onion message with path_id None and a reply_path"), 2);
+}
+
+#[test]
+fn invalid_custom_message_type() {
+ let nodes = create_nodes(2);
+
+ struct InvalidCustomMessage{}
+ impl CustomOnionMessageContents for InvalidCustomMessage {
+ fn tlv_type(&self) -> u64 {
+ // Onion message contents must have a TLV >= 64.
+ 63
+ }
+ }
+
+ impl Writeable for InvalidCustomMessage {
+ fn write<W: Writer>(&self, _w: &mut W) -> Result<(), io::Error> { unreachable!() }
+ }
+
+ let test_msg = OnionMessageContents::Custom(InvalidCustomMessage {});
+ let err = nodes[0].messenger.send_onion_message(&[], Destination::Node(nodes[1].get_node_pk()), test_msg, None).unwrap_err();
+ assert_eq!(err, SendError::InvalidMessage);
+}
+
+#[test]
+fn peer_buffer_full() {
+ let nodes = create_nodes(2);
+ let test_msg = TestCustomMessage {};
+ for _ in 0..188 { // Based on MAX_PER_PEER_BUFFER_SIZE in OnionMessenger
+ nodes[0].messenger.send_onion_message(&[], Destination::Node(nodes[1].get_node_pk()), OnionMessageContents::Custom(test_msg.clone()), None).unwrap();
+ }
+ let err = nodes[0].messenger.send_onion_message(&[], Destination::Node(nodes[1].get_node_pk()), OnionMessageContents::Custom(test_msg), None).unwrap_err();
+ assert_eq!(err, SendError::BufferFull);
+}
+
+#[test]
+fn many_hops() {
+ // Check we can send over a route with many hops. This will exercise our logic for onion messages
+ // of size [`crate::onion_message::packet::BIG_PACKET_HOP_DATA_LEN`].
+ let num_nodes: usize = 25;
+ let nodes = create_nodes(num_nodes as u8);
+ let test_msg = OnionMessageContents::Custom(TestCustomMessage {});
+
+ let mut intermediates = vec![];
+ for i in 1..(num_nodes-1) {
+ intermediates.push(nodes[i].get_node_pk());
+ }
+
+ nodes[0].messenger.send_onion_message(&intermediates, Destination::Node(nodes[num_nodes-1].get_node_pk()), test_msg, None).unwrap();
+ pass_along_path(&nodes);