//! Onion message testing and test utilities live here.
use crate::blinded_path::BlindedPath;
-use crate::events::OnionMessageProvider;
use crate::ln::features::InitFeatures;
use crate::ln::msgs::{self, DecodeError, OnionMessageHandler};
use crate::sign::{NodeSigner, Recipient};
use crate::util::ser::{FixedLengthReader, LengthReadable, Writeable, Writer};
use crate::util::test_utils;
-use super::{CustomOnionMessageContents, CustomOnionMessageHandler, Destination, MessageRouter, OffersMessage, OffersMessageHandler, OnionMessageContents, OnionMessagePath, OnionMessenger, SendError};
+use super::{CustomOnionMessageHandler, Destination, MessageRouter, OffersMessage, OffersMessageHandler, OnionMessageContents, OnionMessagePath, OnionMessenger, PendingOnionMessage, SendError};
use bitcoin::network::constants::Network;
use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey};
const CUSTOM_REQUEST_MESSAGE_CONTENTS: [u8; 32] = [42; 32];
const CUSTOM_RESPONSE_MESSAGE_CONTENTS: [u8; 32] = [43; 32];
-impl CustomOnionMessageContents for TestCustomMessage {
+impl OnionMessageContents for TestCustomMessage {
fn tlv_type(&self) -> u64 {
match self {
TestCustomMessage::Request => CUSTOM_REQUEST_MESSAGE_TYPE,
_ => Ok(None),
}
}
+ fn release_pending_custom_messages(&self) -> Vec<PendingOnionMessage<Self::CustomMessage>> {
+ vec![]
+ }
}
fn create_nodes(num_messengers: u8) -> Vec<MessengerNode> {
}
#[test]
-fn one_hop() {
+fn one_unblinded_hop() {
let nodes = create_nodes(2);
- let test_msg = OnionMessageContents::Custom(TestCustomMessage::Response);
+ let test_msg = TestCustomMessage::Response;
let path = OnionMessagePath {
intermediate_nodes: vec![],
#[test]
fn two_unblinded_hops() {
let nodes = create_nodes(3);
- let test_msg = OnionMessageContents::Custom(TestCustomMessage::Response);
+ let test_msg = TestCustomMessage::Response;
let path = OnionMessagePath {
intermediate_nodes: vec![nodes[1].get_node_pk()],
pass_along_path(&nodes);
}
+#[test]
+fn one_blinded_hop() {
+ let nodes = create_nodes(2);
+ let test_msg = TestCustomMessage::Response;
+
+ let secp_ctx = Secp256k1::new();
+ let blinded_path = BlindedPath::new_for_message(&[nodes[1].get_node_pk()], &*nodes[1].keys_manager, &secp_ctx).unwrap();
+ let path = OnionMessagePath {
+ intermediate_nodes: vec![],
+ destination: Destination::BlindedPath(blinded_path),
+ };
+ nodes[0].messenger.send_onion_message(path, test_msg, None).unwrap();
+ nodes[1].custom_message_handler.expect_message(TestCustomMessage::Response);
+ pass_along_path(&nodes);
+}
+
#[test]
fn two_unblinded_two_blinded() {
let nodes = create_nodes(5);
- let test_msg = OnionMessageContents::Custom(TestCustomMessage::Response);
+ let test_msg = TestCustomMessage::Response;
let secp_ctx = Secp256k1::new();
let blinded_path = BlindedPath::new_for_message(&[nodes[3].get_node_pk(), nodes[4].get_node_pk()], &*nodes[4].keys_manager, &secp_ctx).unwrap();
#[test]
fn three_blinded_hops() {
let nodes = create_nodes(4);
- let test_msg = OnionMessageContents::Custom(TestCustomMessage::Response);
+ let test_msg = TestCustomMessage::Response;
let secp_ctx = Secp256k1::new();
let blinded_path = BlindedPath::new_for_message(&[nodes[1].get_node_pk(), nodes[2].get_node_pk(), nodes[3].get_node_pk()], &*nodes[3].keys_manager, &secp_ctx).unwrap();
fn too_big_packet_error() {
// Make sure we error as expected if a packet is too big to send.
let nodes = create_nodes(2);
- let test_msg = OnionMessageContents::Custom(TestCustomMessage::Response);
+ let test_msg = TestCustomMessage::Response;
let hop_node_id = nodes[1].get_node_pk();
let hops = vec![hop_node_id; 400];
destination: Destination::BlindedPath(blinded_path),
};
- nodes[0].messenger.send_onion_message(path, OnionMessageContents::Custom(test_msg.clone()), None).unwrap();
+ nodes[0].messenger.send_onion_message(path, test_msg.clone(), None).unwrap();
nodes[2].custom_message_handler.expect_message(TestCustomMessage::Response);
pass_along_path(&nodes);
intermediate_nodes: vec![],
destination: Destination::BlindedPath(blinded_path),
};
- nodes[0].messenger.send_onion_message(path, OnionMessageContents::Custom(test_msg), None).unwrap();
+ nodes[0].messenger.send_onion_message(path, test_msg, None).unwrap();
nodes[1].custom_message_handler.expect_message(TestCustomMessage::Response);
nodes.remove(2);
pass_along_path(&nodes);
intermediate_nodes: vec![],
destination: Destination::BlindedPath(blinded_path),
};
- let err = nodes[0].messenger.send_onion_message(path, OnionMessageContents::Custom(test_msg.clone()), None).unwrap_err();
- assert_eq!(err, SendError::TooFewBlindedHops);
-
- // 1 hop
- let mut blinded_path = BlindedPath::new_for_message(&[nodes[1].get_node_pk(), nodes[2].get_node_pk()], &*nodes[2].keys_manager, &secp_ctx).unwrap();
- blinded_path.blinded_hops.remove(0);
- assert_eq!(blinded_path.blinded_hops.len(), 1);
- let path = OnionMessagePath {
- intermediate_nodes: vec![],
- destination: Destination::BlindedPath(blinded_path),
- };
- let err = nodes[0].messenger.send_onion_message(path, OnionMessageContents::Custom(test_msg), None).unwrap_err();
+ let err = nodes[0].messenger.send_onion_message(path, test_msg.clone(), None).unwrap_err();
assert_eq!(err, SendError::TooFewBlindedHops);
}
destination: Destination::Node(nodes[3].get_node_pk()),
};
let reply_path = BlindedPath::new_for_message(&[nodes[2].get_node_pk(), nodes[1].get_node_pk(), nodes[0].get_node_pk()], &*nodes[0].keys_manager, &secp_ctx).unwrap();
- nodes[0].messenger.send_onion_message(path, OnionMessageContents::Custom(test_msg.clone()), Some(reply_path)).unwrap();
+ nodes[0].messenger.send_onion_message(path, test_msg.clone(), Some(reply_path)).unwrap();
nodes[3].custom_message_handler.expect_message(TestCustomMessage::Request);
pass_along_path(&nodes);
// Make sure the last node successfully decoded the reply path.
};
let reply_path = BlindedPath::new_for_message(&[nodes[2].get_node_pk(), nodes[1].get_node_pk(), nodes[0].get_node_pk()], &*nodes[0].keys_manager, &secp_ctx).unwrap();
- nodes[0].messenger.send_onion_message(path, OnionMessageContents::Custom(test_msg), Some(reply_path)).unwrap();
+ nodes[0].messenger.send_onion_message(path, test_msg, Some(reply_path)).unwrap();
nodes[3].custom_message_handler.expect_message(TestCustomMessage::Request);
pass_along_path(&nodes);
let nodes = create_nodes(2);
struct InvalidCustomMessage{}
- impl CustomOnionMessageContents for InvalidCustomMessage {
+ impl OnionMessageContents for InvalidCustomMessage {
fn tlv_type(&self) -> u64 {
// Onion message contents must have a TLV >= 64.
63
fn write<W: Writer>(&self, _w: &mut W) -> Result<(), io::Error> { unreachable!() }
}
- let test_msg = OnionMessageContents::Custom(InvalidCustomMessage {});
+ let test_msg = InvalidCustomMessage {};
let path = OnionMessagePath {
intermediate_nodes: vec![],
destination: Destination::Node(nodes[1].get_node_pk()),
destination: Destination::Node(nodes[1].get_node_pk()),
};
for _ in 0..188 { // Based on MAX_PER_PEER_BUFFER_SIZE in OnionMessenger
- nodes[0].messenger.send_onion_message(path.clone(), OnionMessageContents::Custom(test_msg.clone()), None).unwrap();
+ nodes[0].messenger.send_onion_message(path.clone(), test_msg.clone(), None).unwrap();
}
- let err = nodes[0].messenger.send_onion_message(path, OnionMessageContents::Custom(test_msg), None).unwrap_err();
+ let err = nodes[0].messenger.send_onion_message(path, test_msg, None).unwrap_err();
assert_eq!(err, SendError::BufferFull);
}
intermediate_nodes,
destination: Destination::Node(nodes[num_nodes-1].get_node_pk()),
};
- nodes[0].messenger.send_onion_message(path, OnionMessageContents::Custom(test_msg), None).unwrap();
+ nodes[0].messenger.send_onion_message(path, test_msg, None).unwrap();
nodes[num_nodes-1].custom_message_handler.expect_message(TestCustomMessage::Response);
pass_along_path(&nodes);
}