+ nodes[0].messenger.send_onion_message(test_msg, destination, None).unwrap();
+ nodes[3].custom_message_handler.expect_message(TestCustomMessage::Pong);
+ pass_along_path(&nodes);
+}
+
+#[test]
+fn async_response_over_one_blinded_hop() {
+ // Simulate an asynchronous interaction between two nodes, Alice and Bob.
+
+ // 1. Set up the network with two nodes: Alice and Bob.
+ let nodes = create_nodes(2);
+ let alice = &nodes[0];
+ let bob = &nodes[1];
+
+ // 2. Define the message sent from Bob to Alice.
+ let message = TestCustomMessage::Ping;
+ let path_id = Some([2; 32]);
+
+ // 3. Simulate the creation of a Blinded Reply path provided by Bob.
+ let secp_ctx = Secp256k1::new();
+ let reply_path = BlindedPath::new_for_message(&[], nodes[1].node_id, &*nodes[1].entropy_source, &secp_ctx).unwrap();
+
+ // 4. Create a responder using the reply path for Alice.
+ let responder = Some(Responder::new(reply_path, path_id));
+
+ // 5. Expect Alice to receive the message and create a response instruction for it.
+ alice.custom_message_handler.expect_message(message.clone());
+ let response_instruction = nodes[0].custom_message_handler.handle_custom_message(message, responder);
+
+ // 6. Simulate Alice asynchronously responding back to Bob with a response.
+ assert_eq!(
+ nodes[0].messenger.handle_onion_message_response(response_instruction),
+ Ok(Some(SendSuccess::Buffered)),
+ );
+
+ bob.custom_message_handler.expect_message(TestCustomMessage::Pong);
+
+ pass_along_path(&nodes);
+}
+
+#[test]
+fn async_response_with_reply_path_succeeds() {
+ // Simulate an asynchronous interaction between two nodes, Alice and Bob.
+ // Create a channel between the two nodes to establish them as announced nodes,
+ // which allows the creation of the reply_path for successful communication.
+
+ let mut nodes = create_nodes(2);
+ let alice = &nodes[0];
+ let bob = &nodes[1];
+ let secp_ctx = Secp256k1::new();
+
+ add_channel_to_graph(alice, bob, &secp_ctx, 24);
+
+ // Alice receives a message from Bob with an added reply_path for responding back.
+ let message = TestCustomMessage::Ping;
+ let path_id = Some([2; 32]);
+ let reply_path = BlindedPath::new_for_message(&[], bob.node_id, &*bob.entropy_source, &secp_ctx).unwrap();
+
+ // Alice asynchronously responds to Bob, expecting a response back from him.
+ let responder = Responder::new(reply_path, path_id);
+ alice.custom_message_handler.expect_message_and_response(message.clone());
+ let response_instruction = alice.custom_message_handler.handle_custom_message(message, Some(responder));
+
+ assert_eq!(
+ alice.messenger.handle_onion_message_response(response_instruction),
+ Ok(Some(SendSuccess::Buffered)),
+ );
+
+ // Set Bob's expectation and pass the Onion Message along the path.
+ bob.custom_message_handler.expect_message(TestCustomMessage::Pong);
+ pass_along_path(&nodes);
+
+ // Bob responds back to Alice using the reply_path she included with the OnionMessage.
+ // Set Alice's expectation and reverse the path for the response.
+ alice.custom_message_handler.expect_message(TestCustomMessage::Ping);
+ nodes.reverse();