X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fonion_message%2Ffunctional_tests.rs;h=df13aa2cbec24e5068b7a3cdca31da609a3136aa;hb=efed905a4f90a3ca86b08cd6fb111e7c790ce20d;hp=aee7f562defc5915517d696cf032353deee4e3d6;hpb=f71daed02d159e051e065802155d3ad77edbc124;p=rust-lightning diff --git a/lightning/src/onion_message/functional_tests.rs b/lightning/src/onion_message/functional_tests.rs index aee7f562..df13aa2c 100644 --- a/lightning/src/onion_message/functional_tests.rs +++ b/lightning/src/onion_message/functional_tests.rs @@ -9,10 +9,11 @@ //! Onion message testing and test utilities live here. +use crate::blinded_path::BlindedPath; use crate::chain::keysinterface::{NodeSigner, Recipient}; use crate::ln::features::InitFeatures; use crate::ln::msgs::{self, DecodeError, OnionMessageHandler}; -use super::{BlindedPath, CustomOnionMessageContents, CustomOnionMessageHandler, Destination, OnionMessageContents, OnionMessenger, SendError}; +use super::{CustomOnionMessageContents, CustomOnionMessageHandler, Destination, OnionMessageContents, OnionMessenger, SendError}; use crate::util::ser::{Writeable, Writer}; use crate::util::test_utils; @@ -20,6 +21,7 @@ use bitcoin::network::constants::Network; use bitcoin::secp256k1::{PublicKey, Secp256k1}; use crate::io; +use crate::io_extras::read_to_end; use crate::sync::Arc; struct MessengerNode { @@ -59,8 +61,7 @@ impl CustomOnionMessageHandler for TestCustomMessageHandler { fn handle_custom_message(&self, _msg: Self::CustomMessage) {} fn read_custom_message(&self, message_type: u64, buffer: &mut R) -> Result, DecodeError> where Self: Sized { if message_type == CUSTOM_MESSAGE_TYPE { - let mut buf = Vec::new(); - buffer.read_to_end(&mut buf)?; + let buf = read_to_end(buffer)?; assert_eq!(buf, CUSTOM_MESSAGE_CONTENTS); return Ok(Some(TestCustomMessage {})) } @@ -104,8 +105,8 @@ fn pass_along_path(path: &Vec, expected_path_id: Option<[u8; 32]> node.messenger.handle_onion_message(&prev_node.get_node_pk(), &onion_msg); if idx == num_nodes - 1 { node.logger.assert_log_contains( - "lightning::onion_message::messenger".to_string(), - format!("Received an onion message with path_id: {:02x?}", expected_path_id).to_string(), 1); + "lightning::onion_message::messenger", + &format!("Received an onion message with path_id: {:02x?}", expected_path_id), 1); } prev_node = node; } @@ -218,8 +219,8 @@ fn reply_path() { pass_along_path(&nodes, None); // Make sure the last node successfully decoded the reply path. nodes[3].logger.assert_log_contains( - "lightning::onion_message::messenger".to_string(), - format!("Received an onion message with path_id None and a reply_path").to_string(), 1); + "lightning::onion_message::messenger", + &format!("Received an onion message with path_id None and a reply_path"), 1); // Destination::BlindedPath let blinded_path = BlindedPath::new(&[nodes[1].get_node_pk(), nodes[2].get_node_pk(), nodes[3].get_node_pk()], &*nodes[3].keys_manager, &secp_ctx).unwrap(); @@ -228,8 +229,8 @@ fn reply_path() { nodes[0].messenger.send_onion_message(&[], Destination::BlindedPath(blinded_path), OnionMessageContents::Custom(test_msg), Some(reply_path)).unwrap(); pass_along_path(&nodes, None); nodes[3].logger.assert_log_contains( - "lightning::onion_message::messenger".to_string(), - format!("Received an onion message with path_id None and a reply_path").to_string(), 2); + "lightning::onion_message::messenger", + &format!("Received an onion message with path_id None and a reply_path"), 2); } #[test]