Skip to content

Commit

Permalink
chore(indexer-selection): remove dependency on toolshed crate (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
LNSD authored Feb 19, 2024
1 parent 1bd66e5 commit 362ecf6
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 90 deletions.
127 changes: 46 additions & 81 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion indexer-selection/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ edition = "2021"

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

[dev-dependencies]
proptest = "1.4.0"
Expand Down
60 changes: 52 additions & 8 deletions indexer-selection/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
#[cfg(test)]
mod test;

use candidate_selection::criteria::performance::expected_value_probabilities;
pub use candidate_selection::criteria::performance::{ExpectedPerformance, Performance};
pub use candidate_selection::{ArrayVec, Normalized};
use std::collections::hash_map::DefaultHasher;
use std::f64::consts::E;
use std::fmt::Display;
use std::hash::{Hash as _, Hasher as _};

use custom_debug::CustomDebug;
use thegraph::types::{Address, DeploymentId};
use toolshed::url::Url;
use url::Url;

use candidate_selection::criteria::performance::expected_value_probabilities;
pub use candidate_selection::criteria::performance::{ExpectedPerformance, Performance};
pub use candidate_selection::{ArrayVec, Normalized};

#[derive(Debug)]
#[cfg(test)]
mod test;

#[derive(CustomDebug)]
pub struct Candidate {
pub indexer: Address,
pub deployment: DeploymentId,
#[debug(with = Display::fmt)]
pub url: Url,
pub perf: ExpectedPerformance,
pub fee: Normalized,
Expand Down Expand Up @@ -164,3 +169,42 @@ pub fn score_latency(latency_ms: u32) -> Normalized {
fn score_success_rate(success_rate: Normalized) -> Normalized {
Normalized::new(success_rate.as_f64().powi(7).max(0.01)).unwrap()
}

#[cfg(test)]
mod tests {
use candidate_selection::criteria::performance::ExpectedPerformance;
use candidate_selection::Normalized;

use super::Candidate;

#[test]
fn candidate_should_use_url_display_for_debug() {
//* Given
let expected_url = "https://example.com/candidate/test/url";

let candidate = Candidate {
indexer: Default::default(),
deployment: "QmWmyoMoctfbAaiEs2G46gpeUmhqFRDW6KWo64y5r581Vz"
.parse()
.unwrap(),
url: expected_url.parse().expect("valid url"),
perf: ExpectedPerformance {
success_rate: Normalized::ONE,
latency_success_ms: 0,
latency_failure_ms: 0,
},
fee: Normalized::ONE,
seconds_behind: 0,
slashable_usd: 0,
subgraph_versions_behind: 0,
zero_allocation: false,
};

//* When
let debug = format!("{:?}", candidate);

//* Then
// Assert that the debug string contains the url in the expected format
assert!(debug.contains(expected_url));
}
}

0 comments on commit 362ecf6

Please sign in to comment.