Skip to content

Commit 4fe5ad0

Browse files
committed
Introduce test for padding
1. Add test to verify blinded path padding.
1 parent 667a237 commit 4fe5ad0

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

lightning/src/onion_message/functional_tests.rs

+30
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,13 @@ fn pass_along_path(path: &Vec<MessengerNode>) {
339339
}
340340
}
341341

342+
/// Checks if all the packets in the blinded path are properly padded, ensuring they are of equal size.
343+
fn is_properly_padded(path: &BlindedPath) -> bool {
344+
let first_hop = path.blinded_hops.first().expect("BlindedPath must have at least one hop");
345+
let first_payload_size = first_hop.encrypted_payload.len();
346+
path.blinded_hops.iter().all(|hop| hop.encrypted_payload.len() == first_payload_size)
347+
}
348+
342349
#[test]
343350
fn one_unblinded_hop() {
344351
let nodes = create_nodes(2);
@@ -539,6 +546,29 @@ fn too_big_packet_error() {
539546
assert_eq!(err, SendError::TooBigPacket);
540547
}
541548

549+
#[test]
550+
fn blinded_path_padding() {
551+
// Make sure that for a blinded path, all encrypted payloads are padded to equal lengths.
552+
let nodes = create_nodes(4);
553+
let test_msg = TestCustomMessage::Pong;
554+
555+
let secp_ctx = Secp256k1::new();
556+
let intermediate_nodes = [
557+
ForwardNode { node_id: nodes[1].node_id, short_channel_id: None },
558+
ForwardNode { node_id: nodes[2].node_id, short_channel_id: None },
559+
];
560+
let context = MessageContext::Custom(Vec::new());
561+
let blinded_path = BlindedPath::new_for_message(&intermediate_nodes, nodes[3].node_id, context, &*nodes[3].entropy_source, &secp_ctx).unwrap();
562+
563+
assert!(is_properly_padded(&blinded_path));
564+
565+
let destination = Destination::BlindedPath(blinded_path);
566+
567+
nodes[0].messenger.send_onion_message(test_msg, destination, None).unwrap();
568+
nodes[3].custom_message_handler.expect_message(TestCustomMessage::Pong);
569+
pass_along_path(&nodes);
570+
}
571+
542572
#[test]
543573
fn we_are_intro_node() {
544574
// If we are sending straight to a blinded path and we are the introduction node, we need to

0 commit comments

Comments
 (0)