Skip to content

Commit 362ecf6

Browse files
authored
chore(indexer-selection): remove dependency on toolshed crate (#3)
1 parent 1bd66e5 commit 362ecf6

File tree

3 files changed

+100
-90
lines changed

3 files changed

+100
-90
lines changed

Cargo.lock

Lines changed: 46 additions & 81 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

indexer-selection/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ edition = "2021"
55

66
[dependencies]
77
candidate-selection = { path = "../candidate-selection" }
8+
custom_debug = "0.6.1"
89
rand = { version = "0.8.5", default-features = false }
910
thegraph = { git = "https://github.com/edgeandnode/toolshed", tag = "thegraph-v0.6.0" }
10-
toolshed = { git = "https://github.com/edgeandnode/toolshed", tag = "toolshed-v0.5.0" }
11+
url = "2.5.0"
1112

1213
[dev-dependencies]
1314
proptest = "1.4.0"

indexer-selection/src/lib.rs

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
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};
71
use std::collections::hash_map::DefaultHasher;
82
use std::f64::consts::E;
3+
use std::fmt::Display;
94
use std::hash::{Hash as _, Hasher as _};
5+
6+
use custom_debug::CustomDebug;
107
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};
1213

13-
#[derive(Debug)]
14+
#[cfg(test)]
15+
mod test;
16+
17+
#[derive(CustomDebug)]
1418
pub struct Candidate {
1519
pub indexer: Address,
1620
pub deployment: DeploymentId,
21+
#[debug(with = Display::fmt)]
1722
pub url: Url,
1823
pub perf: ExpectedPerformance,
1924
pub fee: Normalized,
@@ -164,3 +169,42 @@ pub fn score_latency(latency_ms: u32) -> Normalized {
164169
fn score_success_rate(success_rate: Normalized) -> Normalized {
165170
Normalized::new(success_rate.as_f64().powi(7).max(0.01)).unwrap()
166171
}
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

Comments
 (0)