@@ -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,10 @@ 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 =
76+ lsps5_service_config. with_http_client ( MockHttpClientWrapper ( mock_client) ) ;
7477 let service_config = LiquidityServiceConfig {
7578 #[ cfg( lsps1_service) ]
7679 lsps1_service_config : None ,
@@ -154,6 +157,8 @@ fn webhook_registration_flow() {
154157 _ => panic ! ( "Unexpected event" ) ,
155158 }
156159
160+ service_node. liquidity_manager . next_event ( ) . unwrap ( ) ; // Skip the WebhookNotificationSent event
161+
157162 // Test list_webhooks - now capture the request ID
158163 let list_request_id = client_handler
159164 . list_webhooks ( service_node_id)
@@ -256,6 +261,8 @@ fn webhook_registration_flow() {
256261 _ => panic ! ( "Unexpected event" ) ,
257262 }
258263
264+ service_node. liquidity_manager . next_event ( ) . unwrap ( ) ; // Skip the WebhookNotificationSent event
265+
259266 // Test remove_webhook - now capture the request ID
260267 let remove_request_id = client_handler
261268 . remove_webhook ( service_node_id, app_name. to_string ( ) )
@@ -300,7 +307,10 @@ fn webhook_registration_flow() {
300307
301308#[ test]
302309fn webhook_error_handling_test ( ) {
303- let lsps5_service_config: LSPS5ServiceConfig = LSPS5ServiceConfig :: default ( ) ;
310+ let mock_client = Arc :: new ( MockHttpClient :: new ( true ) ) ;
311+ let mut lsps5_service_config: LSPS5ServiceConfig = LSPS5ServiceConfig :: default ( ) ;
312+ lsps5_service_config =
313+ lsps5_service_config. with_http_client ( MockHttpClientWrapper ( mock_client) ) ;
304314 let service_config = LiquidityServiceConfig {
305315 #[ cfg( lsps1_service) ]
306316 lsps1_service_config : None ,
@@ -987,7 +997,7 @@ fn unknown_method_and_malformed_notification_test() {
987997
988998 // Test Case 1: Unknown notification method
989999 // Spec: "Notification delivery services MUST ignore any notification method it does not recognize."
990- let timestamp1 = Utc :: now ( ) . format ( "%Y-%m-%dT%H:%M:%S%.3fZ" ) . to_string ( ) ;
1000+ let timestamp1 = LSPSDateTime :: now ( ) . to_rfc3339 ( ) ;
9911001 let unknown_notification = create_notification ( "lsps5.unknown_method" , json ! ( { "some" : "data" } ) ) ;
9921002 let body1 = unknown_notification. to_string ( ) ;
9931003 let signature1 = sign_notification_with_key ( & body1, & timestamp1) ;
@@ -1008,7 +1018,7 @@ fn unknown_method_and_malformed_notification_test() {
10081018 } )
10091019 . to_string ( ) ;
10101020
1011- let timestamp2 = Utc :: now ( ) . format ( "%Y-%m-%dT%H:%M:%S%.3fZ" ) . to_string ( ) ;
1021+ let timestamp2 = LSPSDateTime :: now ( ) . to_rfc3339 ( ) ;
10121022 let signature2 = sign_notification_with_key ( & invalid_jsonrpc, & timestamp2) ;
10131023
10141024 let invalid_jsonrpc_result = client_handler. parse_webhook_notification (
@@ -1030,7 +1040,7 @@ fn unknown_method_and_malformed_notification_test() {
10301040 } )
10311041 . to_string ( ) ;
10321042
1033- let timestamp3 = Utc :: now ( ) . format ( "%Y-%m-%dT%H:%M:%S%.3fZ" ) . to_string ( ) ;
1043+ let timestamp3 = LSPSDateTime :: now ( ) . to_rfc3339 ( ) ;
10341044 let signature3 = sign_notification_with_key ( & missing_params, & timestamp3) ;
10351045
10361046 let missing_params_result = client_handler. parse_webhook_notification (
@@ -1045,7 +1055,7 @@ fn unknown_method_and_malformed_notification_test() {
10451055
10461056 // Test Case 4: Extra unrecognized parameters in notification
10471057 // Spec: "Notification delivery services MUST ignore any parameters it does not recognize."
1048- let timestamp4 = Utc :: now ( ) . format ( "%Y-%m-%dT%H:%M:%S%.3fZ" ) . to_string ( ) ;
1058+ let timestamp4 = LSPSDateTime :: now ( ) . to_rfc3339 ( ) ;
10491059 let extra_params_notification = create_notification (
10501060 "lsps5.expiry_soon" ,
10511061 json ! ( {
@@ -1068,7 +1078,7 @@ fn unknown_method_and_malformed_notification_test() {
10681078
10691079 // Test Case 5: Valid signature verification
10701080 // Spec requires validating the signature against the timestamp and notification body
1071- let timestamp5 = Utc :: now ( ) . format ( "%Y-%m-%dT%H:%M:%S%.3fZ" ) . to_string ( ) ;
1081+ let timestamp5 = LSPSDateTime :: now ( ) . to_rfc3339 ( ) ;
10721082 let valid_notification = create_notification ( "lsps5.payment_incoming" , json ! ( { } ) ) ;
10731083 let body5 = valid_notification. to_string ( ) ;
10741084 let signature5 = sign_notification_with_key ( & body5, & timestamp5) ;
@@ -1081,7 +1091,7 @@ fn unknown_method_and_malformed_notification_test() {
10811091
10821092 // Test Case 6: Invalid signature
10831093 // Spec: The notification delivery service "MUST validate the signature against the message template"
1084- let timestamp6 = Utc :: now ( ) . format ( "%Y-%m-%dT%H:%M:%S%.3fZ" ) . to_string ( ) ;
1094+ let timestamp6 = LSPSDateTime :: now ( ) . to_rfc3339 ( ) ;
10851095 let notification6 = create_notification ( "lsps5.payment_incoming" , json ! ( { } ) ) ;
10861096 let body6 = notification6. to_string ( ) ;
10871097 let invalid_signature = "lspsig:abcdef1234567890" ; // Invalid signature
@@ -1098,7 +1108,7 @@ fn unknown_method_and_malformed_notification_test() {
10981108
10991109 // Test Case 7: Invalid JSON
11001110 // Spec requires the body to be a valid JSON-RPC 2.0 Notification Object
1101- let timestamp7 = Utc :: now ( ) . format ( "%Y-%m-%dT%H:%M:%S%.3fZ" ) . to_string ( ) ;
1111+ let timestamp7 = LSPSDateTime :: now ( ) . to_rfc3339 ( ) ;
11021112 let invalid_json = "{not valid json" ;
11031113 let signature7 = sign_notification_with_key ( invalid_json, & timestamp7) ;
11041114
@@ -1123,7 +1133,7 @@ fn unknown_method_and_malformed_notification_test() {
11231133 ] ;
11241134
11251135 for ( method, params) in standard_methods. iter ( ) {
1126- let timestamp = Utc :: now ( ) . format ( "%Y-%m-%dT%H:%M:%S%.3fZ" ) . to_string ( ) ;
1136+ let timestamp = LSPSDateTime :: now ( ) . to_rfc3339 ( ) ;
11271137 let notification = create_notification ( method, params. clone ( ) ) ;
11281138 let body = notification. to_string ( ) ;
11291139 let signature = sign_notification_with_key ( & body, & timestamp) ;
0 commit comments