Skip to content

Commit 4c207d4

Browse files
committed
Test sending, and receiving of user_custom_tlvs
1 parent 0bf4578 commit 4c207d4

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

lightning/src/ln/blinded_payment_tests.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,7 @@ fn custom_tlvs_to_blinded_path() {
13131313
htlc_minimum_msat: chan_upd.htlc_minimum_msat,
13141314
},
13151315
payment_context: PaymentContext::unknown(),
1316-
custom_tlvs: Vec::new(),
1316+
custom_tlvs: vec![43, 43]
13171317
};
13181318
let mut secp_ctx = Secp256k1::new();
13191319
let blinded_path = BlindedPaymentPath::new(
@@ -1327,6 +1327,7 @@ fn custom_tlvs_to_blinded_path() {
13271327
);
13281328

13291329
let recipient_onion_fields = RecipientOnionFields::spontaneous_empty()
1330+
.with_user_custom_tlvs(vec![43, 43])
13301331
.with_sender_custom_tlvs(vec![((1 << 16) + 3, vec![42, 42])])
13311332
.unwrap();
13321333
nodes[0].node.send_payment(payment_hash, recipient_onion_fields.clone(),
@@ -1340,10 +1341,12 @@ fn custom_tlvs_to_blinded_path() {
13401341
let path = &[&nodes[1]];
13411342
let args = PassAlongPathArgs::new(&nodes[0], path, amt_msat, payment_hash, ev)
13421343
.with_payment_secret(payment_secret)
1344+
.with_user_custom_tlvs(recipient_onion_fields.user_custom_tlvs.clone())
13431345
.with_sender_custom_tlvs(recipient_onion_fields.sender_custom_tlvs.clone());
13441346
do_pass_along_path(args);
13451347
claim_payment_along_route(
13461348
ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1]]], payment_preimage)
1349+
.with_user_custom_tlvs(recipient_onion_fields.user_custom_tlvs.clone())
13471350
.with_sender_custom_tlvs(recipient_onion_fields.sender_custom_tlvs.clone())
13481351
);
13491352
}

lightning/src/ln/functional_test_utils.rs

+4
Original file line numberDiff line numberDiff line change
@@ -2828,6 +2828,10 @@ impl<'a, 'b, 'c, 'd> ClaimAlongRouteArgs<'a, 'b, 'c, 'd> {
28282828
self.allow_1_msat_fee_overpay = true;
28292829
self
28302830
}
2831+
pub fn with_user_custom_tlvs(mut self, custom_tlvs: Vec<u8>) -> Self {
2832+
self.user_custom_tlvs = custom_tlvs;
2833+
self
2834+
}
28312835
pub fn with_sender_custom_tlvs(mut self, custom_tlvs: Vec<(u64, Vec<u8>)>) -> Self {
28322836
self.sender_custom_tlvs = custom_tlvs;
28332837
self

lightning/src/ln/outbound_payment.rs

+5
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,11 @@ impl RecipientOnionFields {
656656
Ok(self)
657657
}
658658

659+
pub fn with_user_custom_tlvs(mut self, custom_tlvs: Vec<u8>) -> Self {
660+
self.user_custom_tlvs = custom_tlvs;
661+
self
662+
}
663+
659664
/// Gets the custom TLVs that will be sent or have been received.
660665
///
661666
/// Custom TLVs allow sending extra application-specific data with a payment. They provide

lightning/src/ln/payment_tests.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -3787,8 +3787,12 @@ fn test_retry_custom_tlvs() {
37873787
let mut route_params = route.route_params.clone().unwrap();
37883788

37893789
let sender_custom_tlvs = vec![((1 << 16) + 3, vec![0x42u8; 16])];
3790+
let user_custom_tlvs = vec![0x43u8; 16];
37903791
let onion_fields = RecipientOnionFields::secret_only(payment_secret);
3791-
let onion_fields = onion_fields.with_sender_custom_tlvs(sender_custom_tlvs.clone()).unwrap();
3792+
let onion_fields = onion_fields
3793+
.with_user_custom_tlvs(user_custom_tlvs.clone())
3794+
.with_sender_custom_tlvs(sender_custom_tlvs.clone())
3795+
.unwrap();
37923796

37933797
nodes[0].router.expect_find_route(route_params.clone(), Ok(route.clone()));
37943798
nodes[0].node.send_payment(payment_hash, onion_fields,
@@ -3840,10 +3844,12 @@ fn test_retry_custom_tlvs() {
38403844
let path = &[&nodes[1], &nodes[2]];
38413845
let args = PassAlongPathArgs::new(&nodes[0], path, 1_000_000, payment_hash, events.pop().unwrap())
38423846
.with_payment_secret(payment_secret)
3847+
.with_user_custom_tlvs(user_custom_tlvs.clone())
38433848
.with_sender_custom_tlvs(sender_custom_tlvs.clone());
38443849
do_pass_along_path(args);
38453850
claim_payment_along_route(
38463851
ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[2]]], payment_preimage)
3852+
.with_user_custom_tlvs(user_custom_tlvs)
38473853
.with_sender_custom_tlvs(sender_custom_tlvs)
38483854
);
38493855
}

0 commit comments

Comments
 (0)