Skip to content

Commit

Permalink
Test sending, and receiving of user_custom_data
Browse files Browse the repository at this point in the history
  • Loading branch information
shaavan committed Jan 17, 2025
1 parent 95e7559 commit 1b80dfa
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
7 changes: 5 additions & 2 deletions lightning/src/ln/blinded_payment_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1363,7 +1363,7 @@ fn invalid_keysend_payment_secret() {
}

#[test]
fn sender_custom_tlvs_to_blinded_path() {
fn custom_tlvs_to_blinded_path() {
let chanmon_cfgs = create_chanmon_cfgs(2);
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
Expand All @@ -1379,7 +1379,7 @@ fn sender_custom_tlvs_to_blinded_path() {
htlc_minimum_msat: chan_upd.htlc_minimum_msat,
},
payment_context: PaymentContext::unknown(),
custom_data: Vec::new(),
custom_data: vec![43, 43],
};
let mut secp_ctx = Secp256k1::new();
let blinded_path = BlindedPaymentPath::new(
Expand All @@ -1393,6 +1393,7 @@ fn sender_custom_tlvs_to_blinded_path() {
);

let recipient_onion_fields = RecipientOnionFields::spontaneous_empty()
.with_user_custom_data(vec![43, 43])
.with_sender_custom_tlvs(vec![((1 << 16) + 1, vec![42, 42])])
.unwrap();
nodes[0].node.send_payment(payment_hash, recipient_onion_fields.clone(),
Expand All @@ -1406,10 +1407,12 @@ fn sender_custom_tlvs_to_blinded_path() {
let path = &[&nodes[1]];
let args = PassAlongPathArgs::new(&nodes[0], path, amt_msat, payment_hash, ev)
.with_payment_secret(payment_secret)
.with_user_custom_data(recipient_onion_fields.user_custom_data.clone())
.with_sender_custom_tlvs(recipient_onion_fields.sender_custom_tlvs.clone());
do_pass_along_path(args);
claim_payment_along_route(
ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1]]], payment_preimage)
.with_user_custom_data(recipient_onion_fields.user_custom_data.clone())
.with_sender_custom_tlvs(recipient_onion_fields.sender_custom_tlvs.clone())
);
}
Expand Down
4 changes: 4 additions & 0 deletions lightning/src/ln/functional_test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2671,6 +2671,10 @@ impl<'a, 'b, 'c, 'd> PassAlongPathArgs<'a, 'b, 'c, 'd> {
self.expected_preimage = Some(payment_preimage);
self
}
pub fn with_user_custom_data(mut self, custom_tlvs: Vec<u8>) -> Self {
self.user_custom_data = custom_tlvs;
self
}
pub fn with_sender_custom_tlvs(mut self, sender_custom_tlvs: Vec<(u64, Vec<u8>)>) -> Self {
self.sender_custom_tlvs = sender_custom_tlvs;
self
Expand Down
7 changes: 5 additions & 2 deletions lightning/src/ln/payment_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3754,7 +3754,7 @@ fn do_test_sender_custom_tlvs(spontaneous: bool, even_tlvs: bool, known_tlvs: bo
}

#[test]
fn test_retry_sender_custom_tlvs() {
fn test_retry_custom_tlvs() {
// Test that sender custom TLVs are successfully sent on retries
let chanmon_cfgs = create_chanmon_cfgs(3);
let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
Expand All @@ -3776,8 +3776,9 @@ fn test_retry_sender_custom_tlvs() {
let mut route_params = route.route_params.clone().unwrap();

let sender_custom_tlvs = vec![((1 << 16) + 1, vec![0x42u8; 16])];
let user_custom_data = vec![0x43u8; 16];
let onion_fields = RecipientOnionFields::secret_only(payment_secret);
let onion_fields = onion_fields.with_sender_custom_tlvs(sender_custom_tlvs.clone()).unwrap();
let onion_fields = onion_fields.with_user_custom_data(user_custom_data.clone()).with_sender_custom_tlvs(sender_custom_tlvs.clone()).unwrap();

nodes[0].router.expect_find_route(route_params.clone(), Ok(route.clone()));
nodes[0].node.send_payment(payment_hash, onion_fields,
Expand Down Expand Up @@ -3829,10 +3830,12 @@ fn test_retry_sender_custom_tlvs() {
let path = &[&nodes[1], &nodes[2]];
let args = PassAlongPathArgs::new(&nodes[0], path, 1_000_000, payment_hash, events.pop().unwrap())
.with_payment_secret(payment_secret)
.with_user_custom_data(user_custom_data.clone())
.with_sender_custom_tlvs(sender_custom_tlvs.clone());
do_pass_along_path(args);
claim_payment_along_route(
ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[2]]], payment_preimage)
.with_user_custom_data(user_custom_data.clone())
.with_sender_custom_tlvs(sender_custom_tlvs)
);
}
Expand Down

0 comments on commit 1b80dfa

Please sign in to comment.