moonproof_node_client/
config.rs1use std::time::Duration;
8use url::Url;
9
10#[derive(Debug, Clone)]
15pub struct Config {
16 pub node_url: Url,
19
20 pub reconnection_timeout: Duration,
24
25 pub reconnection_delay: Duration,
27}
28
29impl Config {
30 #[must_use]
33 pub fn new(node_url: Url) -> Self {
34 Self {
35 node_url,
36 reconnection_timeout: Duration::MAX,
37 reconnection_delay: Duration::from_secs(1),
38 }
39 }
40
41 #[must_use]
43 pub fn with_reconnection_timeout(mut self, timeout: Duration) -> Self {
44 self.reconnection_timeout = timeout;
45 self
46 }
47
48 #[must_use]
50 pub fn with_reconnection_delay(mut self, delay: Duration) -> Self {
51 self.reconnection_delay = delay;
52 self
53 }
54}
55
56#[cfg(test)]
57mod tests {
58 use super::*;
59
60 #[test]
61 fn new_populates_url_and_defaults_match_ts_reference() {
62 let url = Url::parse("ws://127.0.0.1:9944").unwrap();
63 let cfg = Config::new(url.clone());
64 assert_eq!(cfg.node_url, url);
65 assert_eq!(cfg.reconnection_delay, Duration::from_secs(1));
66 assert_eq!(cfg.reconnection_timeout, Duration::MAX);
68 }
69
70 #[test]
71 fn builder_overrides_apply_in_isolation() {
72 let url = Url::parse("wss://node.example:443").unwrap();
73 let cfg = Config::new(url)
74 .with_reconnection_delay(Duration::from_millis(250))
75 .with_reconnection_timeout(Duration::from_secs(30));
76 assert_eq!(cfg.reconnection_delay, Duration::from_millis(250));
77 assert_eq!(cfg.reconnection_timeout, Duration::from_secs(30));
78 }
79}