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