@@ -5259,3 +5259,55 @@ fn max_out_mpp_path() {
52595259	check_added_monitors ( & nodes[ 0 ] ,  2 ) ;  // one monitor update per MPP part 
52605260	nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ; 
52615261} 
5262+ 
5263+ #[ test]  
5264+ fn  test_self_payment ( )  { 
5265+ 	let  chanmon_cfgs = create_chanmon_cfgs ( 2 ) ; 
5266+ 	let  node_cfgs = create_node_cfgs ( 2 ,  & chanmon_cfgs) ; 
5267+ 	let  node_chanmgrs = create_node_chanmgrs ( 2 ,  & node_cfgs,  & [ None ,  None ] ) ; 
5268+ 	let  nodes = create_network ( 2 ,  & node_cfgs,  & node_chanmgrs) ; 
5269+ 
5270+ 	let  self_node = nodes[ 0 ] . node . get_our_node_id ( ) ; 
5271+ 	let  _other_node = nodes[ 1 ] . node . get_our_node_id ( ) ; 
5272+ 
5273+ 	create_announced_chan_between_nodes ( & nodes,  0 ,  1 ) ; 
5274+ 
5275+ 	let  amt_msat = 10_000 ; 
5276+ 	let  payment_params = PaymentParameters :: from_node_id ( self_node,  TEST_FINAL_CLTV ) 
5277+ 		. with_bolt11_features ( nodes[ 0 ] . node . bolt11_invoice_features ( ) ) 
5278+ 		. unwrap ( ) ; 
5279+ 	let  route_params = RouteParameters :: from_payment_params_and_value ( payment_params,  amt_msat) ; 
5280+ 
5281+ 	let  preimage = Some ( PaymentPreimage ( [ 42 ;  32 ] ) ) ; 
5282+ 	let  onion = RecipientOnionFields :: spontaneous_empty ( ) ; 
5283+ 	let  retry = Retry :: Attempts ( 0 ) ;  // payment to self should not be retried , it should succeed in one go ideally 
5284+ 	let  id = PaymentId ( [ 42 ;  32 ] ) ; 
5285+ 	nodes[ 0 ] . node . send_spontaneous_payment ( preimage,  onion,  id,  route_params,  retry) . unwrap ( ) ; 
5286+ 
5287+ 	check_added_monitors ! ( nodes[ 0 ] ,  0 ) ;  // Self-payments don't add monitors since no actual channel update occurs 
5288+ 
5289+ 	let  events = nodes[ 0 ] . node . get_and_clear_pending_events ( ) ; 
5290+ 	assert_eq ! ( events. len( ) ,  2 ) ; 
5291+ 
5292+ 	let  mut  claimable_found = false ; 
5293+ 	let  mut  sent_found = false ; 
5294+ 
5295+ 	for  event in  & events { 
5296+ 		match  event { 
5297+ 			Event :: PaymentClaimable  {  purpose,  .. }  => { 
5298+ 				if  let  PaymentPurpose :: SpontaneousPayment ( _preimage)  = purpose { 
5299+ 					// For self-payments, we don't need to manually claim since the payment 
5300+ 					// is automatically processed. The PaymentSent event is already generated. 
5301+ 					claimable_found = true ; 
5302+ 				} 
5303+ 			} , 
5304+ 			Event :: PaymentSent  {  .. }  => { 
5305+ 				sent_found = true ; 
5306+ 			} , 
5307+ 			_ => panic ! ( "Unexpected event: {:?}" ,  event) , 
5308+ 		} 
5309+ 	} 
5310+ 
5311+ 	assert ! ( claimable_found,  "Expected PaymentClaimable event" ) ; 
5312+ 	assert ! ( sent_found,  "Expected PaymentSent event" ) ; 
5313+ } 
0 commit comments