]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Test Trampoline onion (de)serialization round trip.
authorArik Sosman <git@arik.io>
Thu, 18 Apr 2024 06:16:11 +0000 (23:16 -0700)
committerArik Sosman <git@arik.io>
Tue, 21 May 2024 00:32:21 +0000 (17:32 -0700)
lightning/src/ln/msgs.rs

index 9af5ec527fa9ae06519fe69b9bea8dc401381762..3d6f9d3fe71fdfd0527db4213f945d18b7a97ba6 100644 (file)
@@ -3200,7 +3200,7 @@ mod tests {
        use crate::ln::msgs::{self, FinalOnionHopData, OnionErrorPacket, CommonOpenChannelFields, CommonAcceptChannelFields, TrampolineOnionPacket};
        use crate::ln::msgs::SocketAddress;
        use crate::routing::gossip::{NodeAlias, NodeId};
-       use crate::util::ser::{BigSize, Hostname, Readable, ReadableArgs, TransactionU16LenLimited, Writeable};
+       use crate::util::ser::{BigSize, FixedLengthReader, Hostname, LengthReadable, Readable, ReadableArgs, TransactionU16LenLimited, Writeable};
        use crate::util::test_utils;
 
        use bitcoin::hashes::hex::FromHex;
@@ -4516,6 +4516,13 @@ mod tests {
                let encoded_trampoline_packet = trampoline_packet.encode();
                assert_eq!(encoded_trampoline_packet.len(), 716);
 
+               { // verify that a codec round trip works
+                       let mut reader = Cursor::new(&encoded_trampoline_packet);
+                       let mut trampoline_packet_reader = FixedLengthReader::new(&mut reader, encoded_trampoline_packet.len() as u64);
+                       let decoded_trampoline_packet: TrampolineOnionPacket = <TrampolineOnionPacket as LengthReadable>::read(&mut trampoline_packet_reader).unwrap();
+                       assert_eq!(decoded_trampoline_packet.encode(), encoded_trampoline_packet);
+               }
+
                let msg = msgs::OutboundOnionPayload::TrampolineEntrypoint {
                        multipath_trampoline_data: None,
                        amt_to_forward: 0x0badf00d01020304,