Skip to content

Commit

Permalink
Add Trampoline packet encoding test.
Browse files Browse the repository at this point in the history
  • Loading branch information
arik-so committed Dec 5, 2023
1 parent a7bdfcf commit 528dc98
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions lightning/src/ln/msgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2875,10 +2875,10 @@ mod tests {
use crate::ln::{PaymentPreimage, PaymentHash, PaymentSecret};
use crate::ln::ChannelId;
use crate::ln::features::{ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
use crate::ln::msgs::{self, FinalOnionHopData, OnionErrorPacket};
use crate::ln::msgs::{self, FinalOnionHopData, OnionErrorPacket, VariableLengthOnionPacket};
use crate::ln::msgs::SocketAddress;
use crate::routing::gossip::{NodeAlias, NodeId};
use crate::util::ser::{Writeable, Readable, ReadableArgs, Hostname, TransactionU16LenLimited};
use crate::util::ser::{Writeable, Readable, ReadableArgs, Hostname, TransactionU16LenLimited, BigSize};
use crate::util::test_utils;

use bitcoin::hashes::hex::FromHex;
Expand Down Expand Up @@ -4168,6 +4168,40 @@ mod tests {
} else { panic!(); }
}

#[test]
fn encoding_final_onion_hop_data_with_trampoline_packet() {
let secp_ctx = Secp256k1::new();
let (private_key, public_key) = get_keys_from!("0101010101010101010101010101010101010101010101010101010101010101", secp_ctx);

let compressed_public_key = public_key.serialize();
assert_eq!(compressed_public_key.len(), 33);

let trampoline_packet = VariableLengthOnionPacket {
version: 0,
public_key: Ok(public_key),
hop_data: vec![1; 650], // this should be the standard encoded length
hmac: [2; 32],
};
let encoded_trampoline_packet = trampoline_packet.encode();
assert_eq!(encoded_trampoline_packet.len(), 718);

let msg = msgs::OutboundOnionPayload::Receive {
payment_data: None,
payment_metadata: None,
keysend_preimage: None,
custom_tlvs: Vec::new(),
amt_msat: 0x0badf00d01020304,
outgoing_cltv_value: 0xffffffff,
trampoline_packet: Some(trampoline_packet)
};
let encoded_payload = msg.encode();

let trampoline_length_bytes = &encoded_payload[20..23];
let mut trampoline_length_cursor = Cursor::new(trampoline_length_bytes);
let trampoline_length_big_size: BigSize = Readable::read(&mut trampoline_length_cursor).unwrap();
assert_eq!(trampoline_length_big_size.0, encoded_trampoline_packet.len() as u64);
}

#[test]
fn query_channel_range_end_blocknum() {
let tests: Vec<(u32, u32, u32)> = vec![
Expand Down

0 comments on commit 528dc98

Please sign in to comment.