Skip to content

Commit

Permalink
chore(deps): update rust crate thegraph to 0.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
LNSD committed Feb 19, 2024
1 parent 7370989 commit b3cbb38
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 95 deletions.
133 changes: 49 additions & 84 deletions Cargo.lock

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

5 changes: 3 additions & 2 deletions 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.5.0" }
toolshed = { git = "https://github.com/edgeandnode/toolshed", tag = "toolshed-v0.5.0" }
thegraph = { git = "https://github.com/edgeandnode/toolshed", tag = "thegraph-v0.6.0" }
url = "2.5.0"

[dev-dependencies]
proptest = "1.4.0"
Expand Down
58 changes: 50 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;

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

#[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,40 @@ 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));
}
}
2 changes: 1 addition & 1 deletion simulator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ edition = "2021"
candidate-selection = { path = "../candidate-selection" }
indexer-selection = { path = "../indexer-selection" }
rand = { version = "0.8.5", default-features = true, features = ["small_rng"] }
thegraph = { git = "https://github.com/edgeandnode/toolshed", tag = "thegraph-v0.5.0" }
thegraph = { git = "https://github.com/edgeandnode/toolshed", tag = "thegraph-v0.6.0" }

0 comments on commit b3cbb38

Please sign in to comment.