@@ -220,10 +220,13 @@ impl_writeable_msg!(PaymentConstraints, {
220
220
221
221
#[ cfg( test) ]
222
222
mod tests {
223
- use bitcoin:: secp256k1:: PublicKey ;
223
+ use bitcoin:: network:: constants:: Network ;
224
+ use bitcoin:: secp256k1:: { PublicKey , Secp256k1 } ;
225
+ use crate :: blinded_path:: BlindedPath ;
224
226
use crate :: blinded_path:: payment:: { BlindedPaymentTlvs , PaymentConstraints , PaymentRelay } ;
225
227
use crate :: ln:: PaymentSecret ;
226
228
use crate :: ln:: features:: BlindedHopFeatures ;
229
+ use crate :: util:: test_utils;
227
230
228
231
#[ test]
229
232
fn compute_payinfo ( ) {
@@ -285,4 +288,50 @@ mod tests {
285
288
assert_eq ! ( blinded_payinfo. cltv_expiry_delta, 0 ) ;
286
289
assert_eq ! ( blinded_payinfo. htlc_minimum_msat, 1 ) ;
287
290
}
291
+
292
+ #[ test]
293
+ fn invalid_payloads ( ) {
294
+ let dummy_pk = PublicKey :: from_slice ( & [ 2 ; 33 ] ) . unwrap ( ) ;
295
+ let secp_ctx = Secp256k1 :: new ( ) ;
296
+ let keys_manager = test_utils:: TestKeysInterface :: new ( & [ 42 as u8 ; 32 ] , Network :: Testnet ) ;
297
+
298
+ let out_of_order_payloads_path = vec ! [ ( dummy_pk, BlindedPaymentTlvs :: Receive {
299
+ payment_secret: PaymentSecret ( [ 0 ; 32 ] ) ,
300
+ payment_constraints: PaymentConstraints {
301
+ max_cltv_expiry: 0 ,
302
+ htlc_minimum_msat: 1 ,
303
+ } ,
304
+ features: BlindedHopFeatures :: empty( ) ,
305
+ } ) , ( dummy_pk, BlindedPaymentTlvs :: Forward {
306
+ short_channel_id: 0 ,
307
+ payment_relay: PaymentRelay {
308
+ cltv_expiry_delta: 144 ,
309
+ fee_proportional_millionths: 500 ,
310
+ fee_base_msat: 100 ,
311
+ } ,
312
+ payment_constraints: PaymentConstraints {
313
+ max_cltv_expiry: 0 ,
314
+ htlc_minimum_msat: 100 ,
315
+ } ,
316
+ features: BlindedHopFeatures :: empty( ) ,
317
+ } ) ] ;
318
+ assert ! ( BlindedPath :: new_for_payment( & out_of_order_payloads_path[ ..] , & keys_manager, & secp_ctx) . is_err( ) ) ;
319
+
320
+ let multiple_recv_payloads_path = vec ! [ ( dummy_pk, BlindedPaymentTlvs :: Receive {
321
+ payment_secret: PaymentSecret ( [ 0 ; 32 ] ) ,
322
+ payment_constraints: PaymentConstraints {
323
+ max_cltv_expiry: 0 ,
324
+ htlc_minimum_msat: 1 ,
325
+ } ,
326
+ features: BlindedHopFeatures :: empty( ) ,
327
+ } ) , ( dummy_pk, BlindedPaymentTlvs :: Receive {
328
+ payment_secret: PaymentSecret ( [ 0 ; 32 ] ) ,
329
+ payment_constraints: PaymentConstraints {
330
+ max_cltv_expiry: 0 ,
331
+ htlc_minimum_msat: 1 ,
332
+ } ,
333
+ features: BlindedHopFeatures :: empty( ) ,
334
+ } ) ] ;
335
+ assert ! ( BlindedPath :: new_for_payment( & multiple_recv_payloads_path[ ..] , & keys_manager, & secp_ctx) . is_err( ) ) ;
336
+ }
288
337
}
0 commit comments