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