@@ -5,7 +5,7 @@ use common::{create_service_and_client_nodes, get_lsps_message};
55
66use lightning:: util:: hash_tables:: HashSet ;
77use lightning_liquidity:: events:: LiquidityEvent ;
8- use lightning_liquidity:: lsps0:: ser:: LSPSRequestId ;
8+ use lightning_liquidity:: lsps0:: ser:: { LSPSDateTime , LSPSRequestId } ;
99use lightning_liquidity:: lsps5:: client:: LSPS5ClientConfig ;
1010use lightning_liquidity:: lsps5:: event:: { LSPS5ClientEvent , LSPS5ServiceEvent } ;
1111use lightning_liquidity:: lsps5:: msgs:: WebhookNotificationMethod ;
@@ -70,7 +70,9 @@ impl HttpClient for MockHttpClientWrapper {
7070
7171#[ test]
7272fn webhook_registration_flow ( ) {
73- let lsps5_service_config: LSPS5ServiceConfig = LSPS5ServiceConfig :: default ( ) ;
73+ let mock_client = Arc :: new ( MockHttpClient :: new ( true ) ) ;
74+ let mut lsps5_service_config: LSPS5ServiceConfig = LSPS5ServiceConfig :: default ( ) ;
75+ lsps5_service_config = lsps5_service_config. with_http_client ( MockHttpClientWrapper ( mock_client) ) ;
7476 let service_config = LiquidityServiceConfig {
7577 #[ cfg( lsps1_service) ]
7678 lsps1_service_config : None ,
@@ -147,6 +149,8 @@ fn webhook_registration_flow() {
147149 _ => panic ! ( "Unexpected event" ) ,
148150 }
149151
152+ service_node. liquidity_manager . next_event ( ) . unwrap ( ) ; // Skip the WebhookNotificationSent event
153+
150154 // Test list_webhooks - now capture the request ID
151155 let list_request_id = client_handler. list_webhooks ( service_node_id)
152156 . expect ( "Failed to send list_webhooks request" ) ;
@@ -238,6 +242,8 @@ fn webhook_registration_flow() {
238242 _ => panic ! ( "Unexpected event" ) ,
239243 }
240244
245+ service_node. liquidity_manager . next_event ( ) . unwrap ( ) ; // Skip the WebhookNotificationSent event
246+
241247 // Test remove_webhook - now capture the request ID
242248 let remove_request_id = client_handler. remove_webhook ( service_node_id, app_name. to_string ( ) )
243249 . expect ( "Failed to send remove_webhook request" ) ;
@@ -278,7 +284,9 @@ fn webhook_registration_flow() {
278284
279285#[ test]
280286fn webhook_error_handling_test ( ) {
281- let lsps5_service_config: LSPS5ServiceConfig = LSPS5ServiceConfig :: default ( ) ;
287+ let mock_client = Arc :: new ( MockHttpClient :: new ( true ) ) ;
288+ let mut lsps5_service_config: LSPS5ServiceConfig = LSPS5ServiceConfig :: default ( ) ;
289+ lsps5_service_config = lsps5_service_config. with_http_client ( MockHttpClientWrapper ( mock_client) ) ;
282290 let service_config = LiquidityServiceConfig {
283291 #[ cfg( lsps1_service) ]
284292 lsps1_service_config : None ,
@@ -439,7 +447,6 @@ fn webhook_notification_delivery_test() {
439447 let mock_client = Arc :: new ( MockHttpClient :: new ( true ) ) ;
440448 let mock_client_for_verification = mock_client. clone ( ) ;
441449
442-
443450 let signing_key = SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ;
444451
445452 let mut lsps5_service_config = LSPS5ServiceConfig :: default ( ) ;
@@ -818,7 +825,7 @@ fn unknown_method_and_malformed_notification_test() {
818825
819826 // Test Case 1: Unknown notification method
820827 // Spec: "Notification delivery services MUST ignore any notification method it does not recognize."
821- let timestamp1 = Utc :: now ( ) . format ( "%Y-%m-%dT%H:%M:%S%.3fZ" ) . to_string ( ) ;
828+ let timestamp1 = LSPSDateTime :: now ( ) . to_rfc3339 ( ) ;
822829 let unknown_notification = create_notification ( "lsps5.unknown_method" , json ! ( { "some" : "data" } ) ) ;
823830 let body1 = unknown_notification. to_string ( ) ;
824831 let signature1 = sign_notification_with_key ( & body1, & timestamp1) ;
@@ -842,7 +849,7 @@ fn unknown_method_and_malformed_notification_test() {
842849 // Missing required jsonrpc field
843850 } ) . to_string ( ) ;
844851
845- let timestamp2 = Utc :: now ( ) . format ( "%Y-%m-%dT%H:%M:%S%.3fZ" ) . to_string ( ) ;
852+ let timestamp2 = LSPSDateTime :: now ( ) . to_rfc3339 ( ) ;
846853 let signature2 = sign_notification_with_key ( & invalid_jsonrpc, & timestamp2) ;
847854
848855 let invalid_jsonrpc_result = client_handler. parse_webhook_notification (
@@ -863,7 +870,7 @@ fn unknown_method_and_malformed_notification_test() {
863870 // Missing required params field
864871 } ) . to_string ( ) ;
865872
866- let timestamp3 = Utc :: now ( ) . format ( "%Y-%m-%dT%H:%M:%S%.3fZ" ) . to_string ( ) ;
873+ let timestamp3 = LSPSDateTime :: now ( ) . to_rfc3339 ( ) ;
867874 let signature3 = sign_notification_with_key ( & missing_params, & timestamp3) ;
868875
869876 let missing_params_result = client_handler. parse_webhook_notification (
@@ -878,7 +885,7 @@ fn unknown_method_and_malformed_notification_test() {
878885
879886 // Test Case 4: Extra unrecognized parameters in notification
880887 // Spec: "Notification delivery services MUST ignore any parameters it does not recognize."
881- let timestamp4 = Utc :: now ( ) . format ( "%Y-%m-%dT%H:%M:%S%.3fZ" ) . to_string ( ) ;
888+ let timestamp4 = LSPSDateTime :: now ( ) . to_rfc3339 ( ) ;
882889 let extra_params_notification = create_notification (
883890 "lsps5.expiry_soon" ,
884891 json ! ( {
@@ -902,7 +909,7 @@ fn unknown_method_and_malformed_notification_test() {
902909
903910 // Test Case 5: Valid signature verification
904911 // Spec requires validating the signature against the timestamp and notification body
905- let timestamp5 = Utc :: now ( ) . format ( "%Y-%m-%dT%H:%M:%S%.3fZ" ) . to_string ( ) ;
912+ let timestamp5 = LSPSDateTime :: now ( ) . to_rfc3339 ( ) ;
906913 let valid_notification = create_notification ( "lsps5.payment_incoming" , json ! ( { } ) ) ;
907914 let body5 = valid_notification. to_string ( ) ;
908915 let signature5 = sign_notification_with_key ( & body5, & timestamp5) ;
@@ -919,7 +926,7 @@ fn unknown_method_and_malformed_notification_test() {
919926
920927 // Test Case 6: Invalid signature
921928 // Spec: The notification delivery service "MUST validate the signature against the message template"
922- let timestamp6 = Utc :: now ( ) . format ( "%Y-%m-%dT%H:%M:%S%.3fZ" ) . to_string ( ) ;
929+ let timestamp6 = LSPSDateTime :: now ( ) . to_rfc3339 ( ) ;
923930 let notification6 = create_notification ( "lsps5.payment_incoming" , json ! ( { } ) ) ;
924931 let body6 = notification6. to_string ( ) ;
925932 let invalid_signature = "lspsig:abcdef1234567890" ; // Invalid signature
@@ -936,7 +943,7 @@ fn unknown_method_and_malformed_notification_test() {
936943
937944 // Test Case 7: Invalid JSON
938945 // Spec requires the body to be a valid JSON-RPC 2.0 Notification Object
939- let timestamp7 = Utc :: now ( ) . format ( "%Y-%m-%dT%H:%M:%S%.3fZ" ) . to_string ( ) ;
946+ let timestamp7 = LSPSDateTime :: now ( ) . to_rfc3339 ( ) ;
940947 let invalid_json = "{not valid json" ;
941948 let signature7 = sign_notification_with_key ( invalid_json, & timestamp7) ;
942949
@@ -961,7 +968,7 @@ fn unknown_method_and_malformed_notification_test() {
961968 ] ;
962969
963970 for ( method, params) in standard_methods. iter ( ) {
964- let timestamp = Utc :: now ( ) . format ( "%Y-%m-%dT%H:%M:%S%.3fZ" ) . to_string ( ) ;
971+ let timestamp = LSPSDateTime :: now ( ) . to_rfc3339 ( ) ;
965972 let notification = create_notification ( method, params. clone ( ) ) ;
966973 let body = notification. to_string ( ) ;
967974 let signature = sign_notification_with_key ( & body, & timestamp) ;
0 commit comments