@@ -437,6 +437,73 @@ fn async_response_over_one_blinded_hop() {
437437 pass_along_path ( & nodes) ;
438438}
439439
440+ #[ test]
441+ fn async_response_with_reply_path_succeeds ( ) {
442+ // Simulate an asynchronous interaction between two nodes, Alice and Bob.
443+ // Create a channel between the two nodes to establish them as announced nodes,
444+ // which allows the creation of the reply_path for successful communication.
445+
446+ let mut nodes = create_nodes ( 2 ) ;
447+ let alice = & nodes[ 0 ] ;
448+ let bob = & nodes[ 1 ] ;
449+ let secp_ctx = Secp256k1 :: new ( ) ;
450+
451+ add_channel_to_graph ( alice, bob, & secp_ctx, 24 ) ;
452+
453+ // Alice receives a message from Bob with an added reply_path for responding back.
454+ let message = TestCustomMessage :: Ping ;
455+ let path_id = Some ( [ 2 ; 32 ] ) ;
456+ let reply_path = BlindedPath :: new_for_message ( & [ ] , bob. node_id , & * bob. entropy_source , & secp_ctx) . unwrap ( ) ;
457+
458+ // Alice asynchronously responds to Bob, expecting a response back from him.
459+ let responder = Responder :: new ( reply_path, path_id) ;
460+ alice. custom_message_handler . expect_message_and_response ( message. clone ( ) ) ;
461+ let response_instruction = alice. custom_message_handler . handle_custom_message ( message, Some ( responder) ) ;
462+
463+ assert_eq ! (
464+ alice. messenger. handle_onion_message_response( response_instruction) ,
465+ Ok ( Some ( SendSuccess :: Buffered ) ) ,
466+ ) ;
467+
468+ // Set Bob's expectation and pass the Onion Message along the path.
469+ bob. custom_message_handler . expect_message ( TestCustomMessage :: Pong ) ;
470+ pass_along_path ( & nodes) ;
471+
472+ // Bob responds back to Alice using the reply_path she included with the OnionMessage.
473+ // Set Alice's expectation and reverse the path for the response.
474+ alice. custom_message_handler . expect_message ( TestCustomMessage :: Ping ) ;
475+ nodes. reverse ( ) ;
476+ pass_along_path ( & nodes) ;
477+ }
478+
479+ #[ test]
480+ fn async_response_with_reply_path_fails ( ) {
481+ // Simulate an asynchronous interaction between two unannounced nodes, Alice and Bob.
482+ // Since the nodes are unannounced, attempting to respond using a reply_path
483+ // will fail, leading to an expected failure in communication.
484+
485+ let nodes = create_nodes ( 2 ) ;
486+ let alice = & nodes[ 0 ] ;
487+ let bob = & nodes[ 1 ] ;
488+ let secp_ctx = Secp256k1 :: new ( ) ;
489+
490+ // Alice receives a message from Bob with an added reply_path for responding back.
491+ let message = TestCustomMessage :: Ping ;
492+ let path_id = Some ( [ 2 ; 32 ] ) ;
493+ let reply_path = BlindedPath :: new_for_message ( & [ ] , bob. node_id , & * bob. entropy_source , & secp_ctx) . unwrap ( ) ;
494+
495+ // Alice tries to asynchronously respond to Bob, but fails because the nodes are unannounced.
496+ // Therefore, the reply_path cannot be used for the response.
497+ let responder = Responder :: new ( reply_path, path_id) ;
498+ alice. custom_message_handler . expect_message_and_response ( message. clone ( ) ) ;
499+ let response_instruction = alice. custom_message_handler . handle_custom_message ( message, Some ( responder) ) ;
500+
501+ assert_eq ! (
502+ alice. messenger. handle_onion_message_response( response_instruction) ,
503+ Err ( SendError :: PathNotFound ) ,
504+ ) ;
505+ }
506+
440507#[ test]
441508fn too_big_packet_error ( ) {
442509 // Make sure we error as expected if a packet is too big to send.
0 commit comments