From 2bc8947617bfc2f1b6aa4ee30c10cf32a43fc82e Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 28 Mar 2024 13:42:19 +0200 Subject: [PATCH] rpc/tests: Check initialized decodes correctly Signed-off-by: Alexandru Vasile --- subxt/src/backend/unstable/rpc_methods.rs | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/subxt/src/backend/unstable/rpc_methods.rs b/subxt/src/backend/unstable/rpc_methods.rs index 3da380c35c..da7bc015c0 100644 --- a/subxt/src/backend/unstable/rpc_methods.rs +++ b/subxt/src/backend/unstable/rpc_methods.rs @@ -997,4 +997,30 @@ mod test { let _ = serde_json::from_value::(from_err) .expect_err("can't deser invalid num into u32"); } + + #[test] + fn chain_head_initialized() { + // Latest format version. + let event = serde_json::json!({ + "finalizedBlockHashes": ["0x1", "0x2"], + }); + let decoded: Initialized = serde_json::from_value(event).unwrap(); + assert_eq!( + decoded.finalized_block_hashes, + vec!["0x1".to_string(), "0x2".to_string()] + ); + + // Old format. + let event = serde_json::json!({ + "finalizedBlockHash": "0x1", + }); + let decoded: Initialized = serde_json::from_value(event).unwrap(); + assert_eq!(decoded.finalized_block_hashes, vec!["0x1".to_string()]); + + // Wrong format. + let event = serde_json::json!({ + "finalizedBlockHash": ["0x1"], + }); + let _ = serde_json::from_value::>(event).unwrap_err(); + } }