|
1 |
| -#[cfg(test)] |
2 |
| -mod test; |
3 |
| - |
4 |
| -use candidate_selection::criteria::performance::expected_value_probabilities; |
5 |
| -pub use candidate_selection::criteria::performance::{ExpectedPerformance, Performance}; |
6 |
| -pub use candidate_selection::{ArrayVec, Normalized}; |
7 | 1 | use std::collections::hash_map::DefaultHasher;
|
8 | 2 | use std::f64::consts::E;
|
| 3 | +use std::fmt::Display; |
9 | 4 | use std::hash::{Hash as _, Hasher as _};
|
| 5 | + |
| 6 | +use custom_debug::CustomDebug; |
10 | 7 | use thegraph::types::{Address, DeploymentId};
|
11 |
| -use toolshed::url::Url; |
| 8 | +use url::Url; |
| 9 | + |
| 10 | +use candidate_selection::criteria::performance::expected_value_probabilities; |
| 11 | +pub use candidate_selection::criteria::performance::{ExpectedPerformance, Performance}; |
| 12 | +pub use candidate_selection::{ArrayVec, Normalized}; |
12 | 13 |
|
13 |
| -#[derive(Debug)] |
| 14 | +#[cfg(test)] |
| 15 | +mod test; |
| 16 | + |
| 17 | +#[derive(CustomDebug)] |
14 | 18 | pub struct Candidate {
|
15 | 19 | pub indexer: Address,
|
16 | 20 | pub deployment: DeploymentId,
|
| 21 | + #[debug(with = Display::fmt)] |
17 | 22 | pub url: Url,
|
18 | 23 | pub perf: ExpectedPerformance,
|
19 | 24 | pub fee: Normalized,
|
@@ -164,3 +169,42 @@ pub fn score_latency(latency_ms: u32) -> Normalized {
|
164 | 169 | fn score_success_rate(success_rate: Normalized) -> Normalized {
|
165 | 170 | Normalized::new(success_rate.as_f64().powi(7).max(0.01)).unwrap()
|
166 | 171 | }
|
| 172 | + |
| 173 | +#[cfg(test)] |
| 174 | +mod tests { |
| 175 | + use candidate_selection::criteria::performance::ExpectedPerformance; |
| 176 | + use candidate_selection::Normalized; |
| 177 | + |
| 178 | + use super::Candidate; |
| 179 | + |
| 180 | + #[test] |
| 181 | + fn candidate_should_use_url_display_for_debug() { |
| 182 | + //* Given |
| 183 | + let expected_url = "https://example.com/candidate/test/url"; |
| 184 | + |
| 185 | + let candidate = Candidate { |
| 186 | + indexer: Default::default(), |
| 187 | + deployment: "QmWmyoMoctfbAaiEs2G46gpeUmhqFRDW6KWo64y5r581Vz" |
| 188 | + .parse() |
| 189 | + .unwrap(), |
| 190 | + url: expected_url.parse().expect("valid url"), |
| 191 | + perf: ExpectedPerformance { |
| 192 | + success_rate: Normalized::ONE, |
| 193 | + latency_success_ms: 0, |
| 194 | + latency_failure_ms: 0, |
| 195 | + }, |
| 196 | + fee: Normalized::ONE, |
| 197 | + seconds_behind: 0, |
| 198 | + slashable_usd: 0, |
| 199 | + subgraph_versions_behind: 0, |
| 200 | + zero_allocation: false, |
| 201 | + }; |
| 202 | + |
| 203 | + //* When |
| 204 | + let debug = format!("{:?}", candidate); |
| 205 | + |
| 206 | + //* Then |
| 207 | + // Assert that the debug string contains the url in the expected format |
| 208 | + assert!(debug.contains(expected_url)); |
| 209 | + } |
| 210 | +} |
0 commit comments