X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fonion_message%2Ffunctional_tests.rs;h=34cc0c3959356bc5d693e44a5015b159cc10fd56;hb=15d016ac520077b01604f2ede57be83d65e08e59;hp=16f0babe3612e365accffd4c6a7ee110e65880ba;hpb=806fef5848e540b8b30ba0c374d6120942cb41c5;p=rust-lightning diff --git a/lightning/src/onion_message/functional_tests.rs b/lightning/src/onion_message/functional_tests.rs index 16f0babe..34cc0c39 100644 --- a/lightning/src/onion_message/functional_tests.rs +++ b/lightning/src/onion_message/functional_tests.rs @@ -9,7 +9,7 @@ //! Onion message testing and test utilities live here. -use crate::blinded_path::BlindedPath; +use crate::blinded_path::{BlindedPath, EmptyNodeIdLookUp}; use crate::events::{Event, EventsProvider}; use crate::ln::features::{ChannelFeatures, InitFeatures}; use crate::ln::msgs::{self, DecodeError, OnionMessageHandler}; @@ -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}; @@ -42,6 +42,7 @@ struct MessengerNode { Arc, Arc, Arc, + Arc, Arc>>, Arc, @@ -61,8 +62,8 @@ struct 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 } } @@ -84,6 +85,9 @@ impl OnionMessageContents for TestCustomMessage { TestCustomMessage::Response => CUSTOM_RESPONSE_MESSAGE_TYPE, } } + fn msg_type(&self) -> &'static str { + "Custom Message" + } } impl Writeable for TestCustomMessage { @@ -122,15 +126,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 { @@ -175,6 +183,7 @@ fn create_nodes_using_secrets(secrets: Vec) -> Vec { let entropy_source = Arc::new(test_utils::TestKeysInterface::new(&seed, Network::Testnet)); let node_signer = Arc::new(test_utils::TestNodeSigner::new(secret_key)); + let node_id_lookup = Arc::new(EmptyNodeIdLookUp {}); let message_router = Arc::new( DefaultMessageRouter::new(network_graph.clone(), entropy_source.clone()) ); @@ -185,7 +194,7 @@ fn create_nodes_using_secrets(secrets: Vec) -> Vec { node_id: node_signer.get_node_id(Recipient::Node).unwrap(), entropy_source: entropy_source.clone(), messenger: OnionMessenger::new( - entropy_source, node_signer, logger.clone(), message_router, + entropy_source, node_signer, logger.clone(), node_id_lookup, message_router, offers_message_handler, custom_message_handler.clone() ), custom_message_handler, @@ -420,6 +429,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 {