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