Remove `sign/type_resolver.rs` from `rustfmt` exclusion list
[rust-lightning] / fuzz / src / onion_message.rs
index d9d5c0a90376c2cabf5c50ac26b9cd50af23d8a0..f2bae246fabeb09f6a2ab827c078b6046c2cd8e5 100644 (file)
@@ -1,21 +1,24 @@
 // Imports that need to be added manually
 use bitcoin::bech32::u5;
-use bitcoin::blockdata::script::Script;
-use bitcoin::secp256k1::{PublicKey, Scalar, Secp256k1, SecretKey};
+use bitcoin::blockdata::script::ScriptBuf;
+use bitcoin::secp256k1::{PublicKey, Scalar, Secp256k1, SecretKey, self};
 use bitcoin::secp256k1::ecdh::SharedSecret;
 use bitcoin::secp256k1::ecdsa::RecoverableSignature;
 use bitcoin::secp256k1::schnorr;
 
-use lightning::sign::{Recipient, KeyMaterial, EntropySource, NodeSigner, SignerProvider};
+use lightning::blinded_path::BlindedPath;
 use lightning::ln::features::InitFeatures;
 use lightning::ln::msgs::{self, DecodeError, OnionMessageHandler};
 use lightning::ln::script::ShutdownScript;
 use lightning::offers::invoice::UnsignedBolt12Invoice;
 use lightning::offers::invoice_request::UnsignedInvoiceRequest;
+use lightning::sign::{Recipient, KeyMaterial, EntropySource, NodeSigner, SignerProvider};
 use lightning::util::test_channel_signer::TestChannelSigner;
 use lightning::util::logger::Logger;
 use lightning::util::ser::{Readable, Writeable, Writer};
-use lightning::onion_message::{CustomOnionMessageHandler, Destination, MessageRouter, OffersMessage, OffersMessageHandler, OnionMessageContents, OnionMessagePath, OnionMessenger, PendingOnionMessage};
+use lightning::onion_message::messenger::{CustomOnionMessageHandler, Destination, MessageRouter, OnionMessagePath, OnionMessenger, PendingOnionMessage};
+use lightning::onion_message::offers::{OffersMessage, OffersMessageHandler};
+use lightning::onion_message::packet::OnionMessageContents;
 
 use crate::utils::test_logger;
 
@@ -79,8 +82,15 @@ impl MessageRouter for TestMessageRouter {
                Ok(OnionMessagePath {
                        intermediate_nodes: vec![],
                        destination,
+                       first_node_addresses: None,
                })
        }
+
+       fn create_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
+               &self, _recipient: PublicKey, _peers: Vec<PublicKey>, _secp_ctx: &Secp256k1<T>,
+       ) -> Result<Vec<BlindedPath>, ()> {
+               unreachable!()
+       }
 }
 
 struct TestOffersMessageHandler {}
@@ -91,6 +101,7 @@ impl OffersMessageHandler for TestOffersMessageHandler {
        }
 }
 
+#[derive(Debug)]
 struct TestCustomMessage {}
 
 const CUSTOM_MESSAGE_TYPE: u64 = 4242;
@@ -189,23 +200,26 @@ impl NodeSigner for KeyProvider {
 }
 
 impl SignerProvider for KeyProvider {
-       type Signer = TestChannelSigner;
+       type EcdsaSigner = TestChannelSigner;
+       #[cfg(taproot)]
+       type TaprootSigner = TestChannelSigner;
 
        fn generate_channel_keys_id(&self, _inbound: bool, _channel_value_satoshis: u64, _user_channel_id: u128) -> [u8; 32] { unreachable!() }
 
-       fn derive_channel_signer(&self, _channel_value_satoshis: u64, _channel_keys_id: [u8; 32]) -> Self::Signer {
+       fn derive_channel_signer(&self, _channel_value_satoshis: u64, _channel_keys_id: [u8; 32]) -> Self::EcdsaSigner {
                unreachable!()
        }
 
        fn read_chan_signer(&self, _data: &[u8]) -> Result<TestChannelSigner, DecodeError> { unreachable!() }
 
-       fn get_destination_script(&self) -> Result<Script, ()> { unreachable!() }
+       fn get_destination_script(&self, _channel_keys_id: [u8; 32]) -> Result<ScriptBuf, ()> { unreachable!() }
 
        fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> { unreachable!() }
 }
 
 #[cfg(test)]
 mod tests {
+       use bitcoin::hashes::hex::FromHex;
        use lightning::util::logger::{Logger, Record};
        use std::collections::HashMap;
        use std::sync::Mutex;
@@ -215,7 +229,7 @@ mod tests {
                pub lines: Mutex<HashMap<(String, String), usize>>,
        }
        impl Logger for TrackingLogger {
-               fn log(&self, record: &Record) {
+               fn log(&self, record: Record) {
                        *self.lines.lock().unwrap().entry((record.module_path.to_string(), format!("{}", record.args))).or_insert(0) += 1;
                        println!("{:<5} [{} : {}, {}] {}", record.level.to_string(), record.module_path, record.file, record.line, record.args);
                }
@@ -258,13 +272,16 @@ mod tests {
                        000000000000000000000000000000000000000005600000000000000000000000000000000000000000000\
                        000000000000000000";
                let logger = TrackingLogger { lines: Mutex::new(HashMap::new()) };
-               super::do_test(&::hex::decode(one_hop_om).unwrap(), &logger);
+               super::do_test(&<Vec<u8>>::from_hex(one_hop_om).unwrap(), &logger);
                {
                        let log_entries = logger.lines.lock().unwrap();
                        assert_eq!(log_entries.get(&("lightning::onion_message::messenger".to_string(),
-                                               "Received an onion message with path_id None and a reply_path".to_string())), Some(&1));
+                                               "Received an onion message with path_id None and a reply_path: Custom(TestCustomMessage)"
+                                               .to_string())), Some(&1));
+                       assert_eq!(log_entries.get(&("lightning::onion_message::messenger".to_string(),
+                                               "Constructing onion message when responding to Custom onion message with path_id None: TestCustomMessage".to_string())), Some(&1));
                        assert_eq!(log_entries.get(&("lightning::onion_message::messenger".to_string(),
-                                               "Sending onion message when responding to Custom onion message with path_id None".to_string())), Some(&1));
+                                               "Buffered onion message when responding to Custom onion message with path_id None".to_string())), Some(&1));
                }
 
                let two_unblinded_hops_om = "\
@@ -302,7 +319,7 @@ mod tests {
                        000000000000000000000000000000000000000004800000000000000000000000000000000000000000000\
                        000000000000000000";
                let logger = TrackingLogger { lines: Mutex::new(HashMap::new()) };
-               super::do_test(&::hex::decode(two_unblinded_hops_om).unwrap(), &logger);
+               super::do_test(&<Vec<u8>>::from_hex(two_unblinded_hops_om).unwrap(), &logger);
                {
                        let log_entries = logger.lines.lock().unwrap();
                        assert_eq!(log_entries.get(&("lightning::onion_message::messenger".to_string(), "Forwarding an onion message to peer 020202020202020202020202020202020202020202020202020202020202020202".to_string())), Some(&1));
@@ -343,7 +360,7 @@ mod tests {
                        000000000000000000000000000000000000000004800000000000000000000000000000000000000000000\
                        000000000000000000";
                let logger = TrackingLogger { lines: Mutex::new(HashMap::new()) };
-               super::do_test(&::hex::decode(two_unblinded_two_blinded_om).unwrap(), &logger);
+               super::do_test(&<Vec<u8>>::from_hex(two_unblinded_two_blinded_om).unwrap(), &logger);
                {
                        let log_entries = logger.lines.lock().unwrap();
                        assert_eq!(log_entries.get(&("lightning::onion_message::messenger".to_string(), "Forwarding an onion message to peer 020202020202020202020202020202020202020202020202020202020202020202".to_string())), Some(&1));
@@ -384,7 +401,7 @@ mod tests {
                        000000000000000000000000000000000000000004800000000000000000000000000000000000000000000\
                        000000000000000000";
                let logger = TrackingLogger { lines: Mutex::new(HashMap::new()) };
-               super::do_test(&::hex::decode(three_blinded_om).unwrap(), &logger);
+               super::do_test(&<Vec<u8>>::from_hex(three_blinded_om).unwrap(), &logger);
                {
                        let log_entries = logger.lines.lock().unwrap();
                        assert_eq!(log_entries.get(&("lightning::onion_message::messenger".to_string(), "Forwarding an onion message to peer 020202020202020202020202020202020202020202020202020202020202020202".to_string())), Some(&1));