switchboard_utils/lib.rs
1pub mod measure_latency;
2pub use measure_latency::LatencyMeasure;
3pub mod utils;
4use utils::*;
5
6pub mod protos {
7 pub use prost::Message;
8}
9
10pub use rust_decimal::prelude::*;
11
12pub use switchboard_common as common;
13pub use switchboard_common::SbError;
14
15// pub use ethers;
16pub use jsonpath_rust as jsonpath;
17pub use reqwest;
18
19// pub mod amm;
20
21pub mod exchanges;
22pub use exchanges::Pair;
23
24#[macro_export]
25macro_rules! cast {
26 ($target: expr, $pat: path) => {
27 if let $pat(a) = $target {
28 Some(a)
29 } else {
30 None
31 }
32 };
33}
34
35#[cfg(test)]
36mod tests {
37
38 // #[tokio::test]
39 // async fn test_http_chain() {
40 // let json_string = r#"{"symbol":"SOLUSDT","price":"25.36000000"}"#;
41 // let json = Value::from_str(json_string).unwrap();
42 //
43 // let mut server = mockito::Server::new();
44 // let url = &format!("{}/test", server.url());
45 //
46 // // Create a mock
47 // let mock = server
48 // .mock("GET", "/test")
49 // .with_status(201)
50 // .with_header("content-type", "application/json")
51 // .with_body(json_string)
52 // .create();
53 //
54 // let http_result = http_task(url, None).await.unwrap();
55 // assert_eq!(http_result, json);
56 // mock.assert();
57 //
58 // let path = "$.price";
59 //
60 // let value = json_parse_task(http_result, path).await.unwrap();
61 // let result = f64::from_str(value.as_str().unwrap()).unwrap();
62 // assert_eq!(result, 25.36);
63 // assert_eq!(value.as_str().unwrap(), "25.36000000");
64 // }
65 //
66 // #[tokio::test]
67 // async fn test_simple_http_chain() {
68 // let json_string = r#"{"symbol":"SOLUSDT","price":"25.36000000"}"#;
69 // // let json = Value::from_str(json_string).unwrap();
70 //
71 // let mut server = mockito::Server::new();
72 // let url = &format!("{}/test", server.url());
73 //
74 // // Create a mock
75 // let mock = server
76 // .mock("GET", "/test")
77 // .with_status(201)
78 // .with_header("content-type", "application/json")
79 // .with_body(json_string)
80 // .create();
81 //
82 // let value = http_task(url, Some("$.price")).await.unwrap();
83 // mock.assert();
84 //
85 // let result = f64::from_str(value.as_str().unwrap()).unwrap();
86 // assert_eq!(result, 25.36);
87 // assert_eq!(value.as_str().unwrap(), "25.36000000");
88 // }
89}