onemoney_protocol/api/
chains.rs1use crate::Result;
4use crate::client::Client;
5use crate::client::config::api_path;
6use crate::client::config::endpoints::chains::CHAIN_ID;
7use crate::responses::ChainIdResponse;
8
9impl Client {
10 pub async fn get_chain_id(&self) -> Result<u64> {
32 let response: ChainIdResponse = self.get(&api_path(CHAIN_ID)).await?;
33 Ok(response.chain_id)
34 }
35}
36
37#[cfg(test)]
38mod tests {
39 use super::*;
40
41 #[test]
42 fn test_chain_id_response_structure() {
43 let chain_id_response = ChainIdResponse { chain_id: 1212101 };
45
46 let json = serde_json::to_string(&chain_id_response).expect("Test data should be valid");
47 let deserialized: ChainIdResponse =
48 serde_json::from_str(&json).expect("Test data should be valid");
49
50 assert_eq!(chain_id_response.chain_id, deserialized.chain_id);
51 }
52}