Add SendError enum for onion messages and error on too-big packets
[rust-lightning] / lightning / src / onion_message / functional_tests.rs
index 510852cef837860c7db7dd89600e0e5afdcc8f51..560028c5bbaaf86228b2ded9a2d4e7bec70686b1 100644 (file)
 //! Onion message testing and test utilities live here.
 
 use chain::keysinterface::{KeysInterface, Recipient};
-use super::{BlindedRoute, Destination, OnionMessenger};
+use super::{BlindedRoute, Destination, OnionMessenger, SendError};
 use util::enforcing_trait_impls::EnforcingSigner;
 use util::test_utils;
 
 use bitcoin::network::constants::Network;
-use bitcoin::secp256k1::{PublicKey, Secp256k1};
+use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey};
 
 use sync::Arc;
 
@@ -105,3 +105,17 @@ fn three_blinded_hops() {
        nodes[0].messenger.send_onion_message(&[], Destination::BlindedRoute(blinded_route)).unwrap();
        pass_along_path(nodes, None);
 }
+
+#[test]
+fn too_big_packet_error() {
+       // Make sure we error as expected if a packet is too big to send.
+       let nodes = create_nodes(1);
+
+       let hop_secret = SecretKey::from_slice(&hex::decode("0101010101010101010101010101010101010101010101010101010101010101").unwrap()[..]).unwrap();
+       let secp_ctx = Secp256k1::new();
+       let hop_node_id = PublicKey::from_secret_key(&secp_ctx, &hop_secret);
+
+       let hops = [hop_node_id; 400];
+       let err = nodes[0].messenger.send_onion_message(&hops, Destination::Node(hop_node_id)).unwrap_err();
+       assert_eq!(err, SendError::TooBigPacket);
+}