@@ -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 ;
@@ -14,7 +14,7 @@ use lightning_liquidity::lsps5::utils::sign_notification;
1414use lightning_liquidity:: { LiquidityClientConfig , LiquidityServiceConfig } ;
1515
1616use bitcoin:: secp256k1:: SecretKey ;
17- use chrono:: { Duration , Utc } ;
17+ use chrono:: Duration ;
1818use lightning:: ln:: peer_handler:: CustomMessageHandler ;
1919use serde_json:: json;
2020use std:: sync:: atomic:: { AtomicBool , Ordering } ;
@@ -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) ;
@@ -1139,9 +1149,10 @@ fn unknown_method_and_malformed_notification_test() {
11391149 // Spec requires timestamp to be within 10 minutes of local time
11401150
11411151 let generate_timestamp_with_offset = |offset_minutes : i64 | -> String {
1142- let now = Utc :: now ( ) ;
1143- let adjusted_time = now + chrono:: Duration :: minutes ( offset_minutes) ;
1144- adjusted_time. format ( "%Y-%m-%dT%H:%M:%S%.3fZ" ) . to_string ( )
1152+ LSPSDateTime :: now ( )
1153+ . checked_add_signed ( Duration :: minutes ( offset_minutes) )
1154+ . unwrap ( )
1155+ . to_rfc3339 ( )
11451156 } ;
11461157
11471158 // Test with timestamp too old (more than 10 minutes in the past)
@@ -1646,11 +1657,11 @@ fn out_of_window_timestamp_test() {
16461657 // Create timestamps outside the 10-minute window
16471658 // Past timestamp (20 minutes ago)
16481659 let past_timestamp =
1649- ( Utc :: now ( ) - Duration :: minutes ( 20 ) ) . format ( "%Y-%m-%dT%H:%M:%S%.3fZ" ) . to_string ( ) ;
1660+ LSPSDateTime :: now ( ) . checked_sub_signed ( Duration :: minutes ( 20 ) ) . unwrap ( ) . to_rfc3339 ( ) ;
16501661
16511662 // Future timestamp (15 minutes in future)
16521663 let future_timestamp =
1653- ( Utc :: now ( ) + Duration :: minutes ( 15 ) ) . format ( "%Y-%m-%dT%H:%M:%S%.3fZ" ) . to_string ( ) ;
1664+ LSPSDateTime :: now ( ) . checked_add_signed ( Duration :: minutes ( 15 ) ) . unwrap ( ) . to_rfc3339 ( ) ;
16541665
16551666 // Try past timestamp
16561667 let past_result = client_handler. parse_webhook_notification (
0 commit comments