Skip to content

Commit 3ea1515

Browse files
Add test for dummy hop insertion
Introduces a test to verify correct handling of dummy hops in constructed blinded paths. Ensures that the added dummy hops are properly included and do not interfere with the real path. Co-authored-by: valentinewallace <[email protected]>
1 parent fccfd04 commit 3ea1515

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

lightning/src/onion_message/functional_tests.rs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use crate::blinded_path::message::{
2626
use crate::blinded_path::utils::is_padded;
2727
use crate::blinded_path::EmptyNodeIdLookUp;
2828
use crate::events::{Event, EventsProvider};
29+
use crate::ln::inbound_payment::ExpandedKey;
2930
use crate::ln::msgs::{self, BaseMessageHandler, DecodeError, OnionMessageHandler};
3031
use crate::routing::gossip::{NetworkGraph, P2PGossipSync};
3132
use crate::routing::test_utils::{add_channel, add_or_update_node};
@@ -421,6 +422,34 @@ fn one_blinded_hop() {
421422
pass_along_path(&nodes);
422423
}
423424

425+
#[test]
426+
fn blinded_path_with_dummy() {
427+
let nodes = create_nodes(2);
428+
let test_msg = TestCustomMessage::Pong;
429+
430+
let secp_ctx = Secp256k1::new();
431+
let context = MessageContext::Custom(Vec::new());
432+
let entropy = &*nodes[1].entropy_source;
433+
let expanded_key = ExpandedKey::new([42; 32]);
434+
let blinded_path = BlindedMessagePath::new_with_dummy_hops(
435+
&[],
436+
5,
437+
nodes[1].node_id,
438+
context,
439+
entropy,
440+
&expanded_key,
441+
&secp_ctx,
442+
)
443+
.unwrap();
444+
// Ensure that dummy hops are added to the blinded path.
445+
assert_eq!(blinded_path.blinded_hops().len(), 6);
446+
let destination = Destination::BlindedPath(blinded_path);
447+
let instructions = MessageSendInstructions::WithoutReplyPath { destination };
448+
nodes[0].messenger.send_onion_message(test_msg, instructions).unwrap();
449+
nodes[1].custom_message_handler.expect_message(TestCustomMessage::Pong);
450+
pass_along_path(&nodes);
451+
}
452+
424453
#[test]
425454
fn two_unblinded_two_blinded() {
426455
let nodes = create_nodes(5);
@@ -614,11 +643,14 @@ fn test_blinded_path_padding_for_full_length_path() {
614643
// Update the context to create a larger final receive TLVs, ensuring that
615644
// the hop sizes vary before padding.
616645
let context = MessageContext::Custom(vec![0u8; 42]);
617-
let blinded_path = BlindedMessagePath::new(
646+
let expanded_key = ExpandedKey::new([42; 32]);
647+
let blinded_path = BlindedMessagePath::new_with_dummy_hops(
618648
&intermediate_nodes,
649+
5,
619650
nodes[3].node_id,
620651
context,
621652
&*nodes[3].entropy_source,
653+
&expanded_key,
622654
&secp_ctx,
623655
)
624656
.unwrap();
@@ -647,15 +679,19 @@ fn test_blinded_path_no_padding_for_compact_path() {
647679
// Update the context to create a larger final receive TLVs, ensuring that
648680
// the hop sizes vary before padding.
649681
let context = MessageContext::Custom(vec![0u8; 42]);
650-
let blinded_path = BlindedMessagePath::new(
682+
let expanded_key = ExpandedKey::new([42; 32]);
683+
let blinded_path = BlindedMessagePath::new_with_dummy_hops(
651684
&intermediate_nodes,
685+
5,
652686
nodes[3].node_id,
653687
context,
654688
&*nodes[3].entropy_source,
689+
&expanded_key,
655690
&secp_ctx,
656691
)
657692
.unwrap();
658693

694+
// Ensure that the hops are not padded.
659695
assert!(!is_padded(&blinded_path.blinded_hops(), MESSAGE_PADDING_ROUND_OFF));
660696
}
661697

0 commit comments

Comments
 (0)