@@ -572,3 +572,71 @@ fn fails_creating_invoice_request_without_blinded_reply_path() {
572
572
573
573
assert ! ( nodes[ 0 ] . node. list_recent_payments( ) . is_empty( ) ) ;
574
574
}
575
+
576
+ #[ test]
577
+ fn fails_creating_invoice_request_with_duplicate_payment_id ( ) {
578
+ let chanmon_cfgs = create_chanmon_cfgs ( 6 ) ;
579
+ let node_cfgs = create_node_cfgs ( 6 , & chanmon_cfgs) ;
580
+ let node_chanmgrs = create_node_chanmgrs ( 6 , & node_cfgs, & [ None , None , None , None , None , None ] ) ;
581
+ let nodes = create_network ( 6 , & node_cfgs, & node_chanmgrs) ;
582
+
583
+ create_unannounced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 10_000_000 , 1_000_000_000 ) ;
584
+ create_unannounced_chan_between_nodes_with_value ( & nodes, 2 , 3 , 10_000_000 , 1_000_000_000 ) ;
585
+ create_announced_chan_between_nodes_with_value ( & nodes, 1 , 2 , 10_000_000 , 1_000_000_000 ) ;
586
+ create_announced_chan_between_nodes_with_value ( & nodes, 1 , 4 , 10_000_000 , 1_000_000_000 ) ;
587
+ create_announced_chan_between_nodes_with_value ( & nodes, 1 , 5 , 10_000_000 , 1_000_000_000 ) ;
588
+ create_announced_chan_between_nodes_with_value ( & nodes, 2 , 4 , 10_000_000 , 1_000_000_000 ) ;
589
+ create_announced_chan_between_nodes_with_value ( & nodes, 2 , 5 , 10_000_000 , 1_000_000_000 ) ;
590
+
591
+ let ( alice, _bob, charlie, david) = ( & nodes[ 0 ] , & nodes[ 1 ] , & nodes[ 2 ] , & nodes[ 3 ] ) ;
592
+
593
+ disconnect_peers ( alice, & [ charlie, david, & nodes[ 4 ] , & nodes[ 5 ] ] ) ;
594
+
595
+ let offer = alice. node
596
+ . create_offer_builder ( "coffee" . to_string ( ) ) . unwrap ( )
597
+ . amount_msats ( 10_000_000 )
598
+ . build ( ) . unwrap ( ) ;
599
+
600
+ let payment_id = PaymentId ( [ 1 ; 32 ] ) ;
601
+ assert ! (
602
+ david. node. pay_for_offer(
603
+ & offer, None , None , None , payment_id, Retry :: Attempts ( 0 ) , None
604
+ ) . is_ok( )
605
+ ) ;
606
+ expect_recent_payment ! ( david, RecentPaymentDetails :: AwaitingInvoice , payment_id) ;
607
+
608
+ match david. node . pay_for_offer ( & offer, None , None , None , payment_id, Retry :: Attempts ( 0 ) , None ) {
609
+ Ok ( _) => panic ! ( "Expected error" ) ,
610
+ Err ( e) => assert_eq ! ( e, Bolt12SemanticError :: DuplicatePaymentId ) ,
611
+ }
612
+
613
+ expect_recent_payment ! ( david, RecentPaymentDetails :: AwaitingInvoice , payment_id) ;
614
+ }
615
+
616
+ #[ test]
617
+ fn fails_creating_refund_with_duplicate_payment_id ( ) {
618
+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
619
+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
620
+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
621
+ let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
622
+
623
+ create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 10_000_000 , 1_000_000_000 ) ;
624
+
625
+ let absolute_expiry = Duration :: from_secs ( u64:: MAX ) ;
626
+ let payment_id = PaymentId ( [ 1 ; 32 ] ) ;
627
+ assert ! (
628
+ nodes[ 0 ] . node. create_refund_builder(
629
+ "refund" . to_string( ) , 10_000 , absolute_expiry, payment_id, Retry :: Attempts ( 0 ) , None
630
+ ) . is_ok( )
631
+ ) ;
632
+ expect_recent_payment ! ( nodes[ 0 ] , RecentPaymentDetails :: AwaitingInvoice , payment_id) ;
633
+
634
+ match nodes[ 0 ] . node . create_refund_builder (
635
+ "refund" . to_string ( ) , 10_000 , absolute_expiry, payment_id, Retry :: Attempts ( 0 ) , None
636
+ ) {
637
+ Ok ( _) => panic ! ( "Expected error" ) ,
638
+ Err ( e) => assert_eq ! ( e, Bolt12SemanticError :: DuplicatePaymentId ) ,
639
+ }
640
+
641
+ expect_recent_payment ! ( nodes[ 0 ] , RecentPaymentDetails :: AwaitingInvoice , payment_id) ;
642
+ }
0 commit comments