X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fonion_message%2Ffunctional_tests.rs;h=764a2bdcbdcd198f901e722e388d3d3bcc4e86b6;hb=a95338a8f69a9298356c55bff26eab0972776155;hp=eb0b17246c3f2eac9f8c93afd5857235adf0e973;hpb=be31e632c2cb89dc94db7f6b5859213c8e04febd;p=rust-lightning diff --git a/lightning/src/onion_message/functional_tests.rs b/lightning/src/onion_message/functional_tests.rs index eb0b1724..764a2bdc 100644 --- a/lightning/src/onion_message/functional_tests.rs +++ b/lightning/src/onion_message/functional_tests.rs @@ -18,7 +18,7 @@ use crate::routing::test_utils::{add_channel, add_or_update_node}; use crate::sign::{NodeSigner, Recipient}; use crate::util::ser::{FixedLengthReader, LengthReadable, Writeable, Writer}; use crate::util::test_utils; -use super::messenger::{CustomOnionMessageHandler, DefaultMessageRouter, Destination, OnionMessagePath, OnionMessenger, PendingOnionMessage, SendError}; +use super::messenger::{CustomOnionMessageHandler, DefaultMessageRouter, Destination, OnionMessagePath, OnionMessenger, PendingOnionMessage, Responder, ResponseInstruction, SendError}; use super::offers::{OffersMessage, OffersMessageHandler}; use super::packet::{OnionMessageContents, Packet}; @@ -73,8 +73,8 @@ impl Drop for MessengerNode { struct TestOffersMessageHandler {} impl OffersMessageHandler for TestOffersMessageHandler { - fn handle_message(&self, _message: OffersMessage) -> Option { - None + fn handle_message(&self, _message: OffersMessage, _responder: Option) -> ResponseInstruction { + ResponseInstruction::NoResponse } } @@ -96,6 +96,9 @@ impl OnionMessageContents for TestCustomMessage { TestCustomMessage::Response => CUSTOM_RESPONSE_MESSAGE_TYPE, } } + fn msg_type(&self) -> &'static str { + "Custom Message" + } } impl Writeable for TestCustomMessage { @@ -134,15 +137,19 @@ impl Drop for TestCustomMessageHandler { impl CustomOnionMessageHandler for TestCustomMessageHandler { type CustomMessage = TestCustomMessage; - fn handle_custom_message(&self, msg: Self::CustomMessage) -> Option { + fn handle_custom_message(&self, msg: Self::CustomMessage, responder: Option) -> ResponseInstruction { match self.expected_messages.lock().unwrap().pop_front() { Some(expected_msg) => assert_eq!(expected_msg, msg), None => panic!("Unexpected message: {:?}", msg), } - - match msg { + let response_option = match msg { TestCustomMessage::Request => Some(TestCustomMessage::Response), TestCustomMessage::Response => None, + }; + if let (Some(response), Some(responder)) = (response_option, responder) { + responder.respond(response) + } else { + ResponseInstruction::NoResponse } } fn read_custom_message(&self, message_type: u64, buffer: &mut R) -> Result, DecodeError> where Self: Sized { @@ -461,6 +468,9 @@ fn invalid_custom_message_type() { // Onion message contents must have a TLV >= 64. 63 } + fn msg_type(&self) -> &'static str { + "Invalid Message" + } } impl Writeable for InvalidCustomMessage {