@@ -770,3 +770,97 @@ fn fails_sending_invoice_without_blinded_payment_paths_for_refund() {
770
770
Err ( e) => assert_eq ! ( e, Bolt12SemanticError :: MissingPaths ) ,
771
771
}
772
772
}
773
+
774
+ #[ test]
775
+ fn fails_paying_invoice_more_than_once ( ) {
776
+ let mut accept_forward_cfg = test_default_channel_config ( ) ;
777
+ accept_forward_cfg. accept_forwards_to_priv_channels = true ;
778
+
779
+ let mut features = channelmanager:: provided_init_features ( & accept_forward_cfg) ;
780
+ features. set_onion_messages_optional ( ) ;
781
+ features. set_route_blinding_optional ( ) ;
782
+
783
+ let chanmon_cfgs = create_chanmon_cfgs ( 6 ) ;
784
+ let node_cfgs = create_node_cfgs ( 6 , & chanmon_cfgs) ;
785
+
786
+ * node_cfgs[ 1 ] . override_init_features . borrow_mut ( ) = Some ( features) ;
787
+
788
+ let node_chanmgrs = create_node_chanmgrs (
789
+ 6 , & node_cfgs, & [ None , Some ( accept_forward_cfg) , None , None , None , None ]
790
+ ) ;
791
+ let nodes = create_network ( 6 , & node_cfgs, & node_chanmgrs) ;
792
+
793
+ create_unannounced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 10_000_000 , 1_000_000_000 ) ;
794
+ create_unannounced_chan_between_nodes_with_value ( & nodes, 2 , 3 , 10_000_000 , 1_000_000_000 ) ;
795
+ create_announced_chan_between_nodes_with_value ( & nodes, 1 , 2 , 10_000_000 , 1_000_000_000 ) ;
796
+ create_announced_chan_between_nodes_with_value ( & nodes, 1 , 4 , 10_000_000 , 1_000_000_000 ) ;
797
+ create_announced_chan_between_nodes_with_value ( & nodes, 1 , 5 , 10_000_000 , 1_000_000_000 ) ;
798
+ create_announced_chan_between_nodes_with_value ( & nodes, 2 , 4 , 10_000_000 , 1_000_000_000 ) ;
799
+ create_announced_chan_between_nodes_with_value ( & nodes, 2 , 5 , 10_000_000 , 1_000_000_000 ) ;
800
+
801
+ let ( alice, bob, charlie, david) = ( & nodes[ 0 ] , & nodes[ 1 ] , & nodes[ 2 ] , & nodes[ 3 ] ) ;
802
+ let alice_id = alice. node . get_our_node_id ( ) ;
803
+ let bob_id = bob. node . get_our_node_id ( ) ;
804
+ let charlie_id = charlie. node . get_our_node_id ( ) ;
805
+ let david_id = david. node . get_our_node_id ( ) ;
806
+
807
+ disconnect_peers ( alice, & [ charlie, david, & nodes[ 4 ] , & nodes[ 5 ] ] ) ;
808
+ disconnect_peers ( david, & [ bob, & nodes[ 4 ] , & nodes[ 5 ] ] ) ;
809
+
810
+ let absolute_expiry = Duration :: from_secs ( u64:: MAX ) ;
811
+ let payment_id = PaymentId ( [ 1 ; 32 ] ) ;
812
+ let refund = david. node
813
+ . create_refund_builder (
814
+ "refund" . to_string ( ) , 10_000_000 , absolute_expiry, payment_id, Retry :: Attempts ( 0 ) , None
815
+ )
816
+ . unwrap ( )
817
+ . build ( ) . unwrap ( ) ;
818
+ expect_recent_payment ! ( david, RecentPaymentDetails :: AwaitingInvoice , payment_id) ;
819
+
820
+ // Alice sends the first invoice
821
+ alice. node . request_refund_payment ( & refund) . unwrap ( ) ;
822
+
823
+ connect_peers ( alice, charlie) ;
824
+
825
+ let onion_message = alice. onion_messenger . next_onion_message_for_peer ( charlie_id) . unwrap ( ) ;
826
+ charlie. onion_messenger . handle_onion_message ( & alice_id, & onion_message) ;
827
+
828
+ let onion_message = charlie. onion_messenger . next_onion_message_for_peer ( david_id) . unwrap ( ) ;
829
+ david. onion_messenger . handle_onion_message ( & charlie_id, & onion_message) ;
830
+
831
+ // David pays the first invoice
832
+ let invoice1 = extract_invoice ( david, & onion_message) ;
833
+
834
+ route_bolt12_payment ( david, & [ charlie, bob, alice] , & invoice1) ;
835
+ expect_recent_payment ! ( david, RecentPaymentDetails :: Pending , payment_id) ;
836
+
837
+ claim_bolt12_payment ( david, & [ charlie, bob, alice] ) ;
838
+ expect_recent_payment ! ( david, RecentPaymentDetails :: Fulfilled , payment_id) ;
839
+
840
+ disconnect_peers ( alice, & [ charlie] ) ;
841
+
842
+ // Alice sends the second invoice
843
+ alice. node . request_refund_payment ( & refund) . unwrap ( ) ;
844
+
845
+ connect_peers ( alice, charlie) ;
846
+ connect_peers ( david, bob) ;
847
+
848
+ let onion_message = alice. onion_messenger . next_onion_message_for_peer ( charlie_id) . unwrap ( ) ;
849
+ charlie. onion_messenger . handle_onion_message ( & alice_id, & onion_message) ;
850
+
851
+ let onion_message = charlie. onion_messenger . next_onion_message_for_peer ( david_id) . unwrap ( ) ;
852
+ david. onion_messenger . handle_onion_message ( & charlie_id, & onion_message) ;
853
+
854
+ let invoice2 = extract_invoice ( david, & onion_message) ;
855
+ assert_eq ! ( invoice1. payer_metadata( ) , invoice2. payer_metadata( ) ) ;
856
+
857
+ // David sends an error instead of paying the second invoice
858
+ let onion_message = david. onion_messenger . next_onion_message_for_peer ( bob_id) . unwrap ( ) ;
859
+ bob. onion_messenger . handle_onion_message ( & david_id, & onion_message) ;
860
+
861
+ let onion_message = bob. onion_messenger . next_onion_message_for_peer ( alice_id) . unwrap ( ) ;
862
+ alice. onion_messenger . handle_onion_message ( & bob_id, & onion_message) ;
863
+
864
+ let invoice_error = extract_invoice_error ( alice, & onion_message) ;
865
+ assert_eq ! ( invoice_error, InvoiceError :: from_string( "DuplicateInvoice" . to_string( ) ) ) ;
866
+ }
0 commit comments