MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_msat_serialization

Function test_msat_serialization

plugins/lsps-plugin/src/proto/lsps0.rs:268–293  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

266 /// Test serialization of a struct containing Msat.
267 #[test]
268 fn test_msat_serialization() {
269 let msg = TestMessage {
270 amount: Msat(12345000),
271 };
272
273 let expected_amount_json = r#""amount":"12345000""#;
274
275 // Assert that the field gets serialized as string.
276 let json_string = serde_json::to_string(&msg).expect("Serialization failed");
277 assert!(
278 json_string.contains(expected_amount_json),
279 "Serialized JSON should contain '{}'",
280 expected_amount_json
281 );
282
283 // Parse back to generic json value and check field.
284 let json_value: serde_json::Value =
285 serde_json::from_str(&json_string).expect("Failed to parse JSON back");
286 assert_eq!(
287 json_value
288 .get("amount")
289 .expect("JSON should have 'amount' field"),
290 &serde_json::Value::String("12345000".to_string()),
291 "JSON 'amount' field should have the correct string value"
292 );
293 }
294
295 /// Test deserialization into a struct containing Msat.
296 #[test]

Callers

nothing calls this directly

Calls 3

MsatClass · 0.85
expectMethod · 0.80
to_stringFunction · 0.50

Tested by

no test coverage detected