Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit f55c6f2

Browse files
committed
Add test parsing all LSPS2 examples/test vectors
1 parent dae8dc1 commit f55c6f2

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

src/lsps2/msgs.rs

+52
Original file line numberDiff line numberDiff line change
@@ -375,4 +375,56 @@ mod tests {
375375
let json_str = r#"{"opening_fee_params":{"max_client_to_self_delay":128,"max_payment_size_msat":"100000000","min_fee_msat":"100","min_lifetime":144,"min_payment_size_msat":"1","promise":"1134a5c51e3ba2e8f4259610d5e12c1bf4c50ddcd3f8af563e0a00d1fff41dea","proportional":21,"valid_until":"2023-05-20T08:30:45Z"},"payment_size_msat":null}"#;
376376
assert_eq!(buy_request_variable, serde_json::from_str(json_str).unwrap());
377377
}
378+
379+
#[test]
380+
fn parse_spec_test_vectors() {
381+
// Here, we simply assert that we're able to parse all examples given in LSPS2.
382+
let json_str = r#"{
383+
"opening_fee_params_menu": [
384+
{
385+
"min_fee_msat": "546000",
386+
"proportional": 1200,
387+
"valid_until": "2023-02-23T08:47:30.511Z",
388+
"min_lifetime": 1008,
389+
"max_client_to_self_delay": 2016,
390+
"min_payment_size_msat": "1000",
391+
"max_payment_size_msat": "1000000",
392+
"promise": "abcdefghijklmnopqrstuvwxyz"
393+
},
394+
{
395+
"min_fee_msat": "1092000",
396+
"proportional": 2400,
397+
"valid_until": "2023-02-27T21:23:57.984Z",
398+
"min_lifetime": 1008,
399+
"max_client_to_self_delay": 2016,
400+
"min_payment_size_msat": "1000",
401+
"max_payment_size_msat": "1000000",
402+
"promise": "abcdefghijklmnopqrstuvwxyz"
403+
}
404+
]
405+
}"#;
406+
let _get_info_response: GetInfoResponse = serde_json::from_str(json_str).unwrap();
407+
408+
let json_str = r#"{
409+
"opening_fee_params": {
410+
"min_fee_msat": "546000",
411+
"proportional": 1200,
412+
"valid_until": "2023-02-23T08:47:30.511Z",
413+
"min_lifetime": 1008,
414+
"max_client_to_self_delay": 2016,
415+
"min_payment_size_msat": "1000",
416+
"max_payment_size_msat": "1000000",
417+
"promise": "abcdefghijklmnopqrstuvwxyz"
418+
},
419+
"payment_size_msat": "42000"
420+
}"#;
421+
let _buy_request: BuyRequest = serde_json::from_str(json_str).unwrap();
422+
423+
let json_str = r#"{
424+
"jit_channel_scid": "29451x4815x1",
425+
"lsp_cltv_expiry_delta" : 144,
426+
"client_trusts_lsp": false
427+
}"#;
428+
let _buy_response: BuyResponse = serde_json::from_str(json_str).unwrap();
429+
}
378430
}

0 commit comments

Comments
 (0)