-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(graph-gateway): update subgraph client with version query (#422
- Loading branch information
Showing
6 changed files
with
120 additions
and
45 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,7 @@ rdkafka = { version = "0.36.0", features = ["gssapi", "tracing"] } | |
receipts = { git = "ssh://[email protected]/edgeandnode/receipts.git", rev = "89a821c" } | ||
reqwest.workspace = true | ||
secp256k1 = { version = "0.24", default-features = false } | ||
semver = "1.0" | ||
semver = { version = "1.0", features = ["serde"] } | ||
serde.workspace = true | ||
serde_json = { version = "1.0", features = ["raw_value"] } | ||
serde_with = "3.1" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod cost_models; | ||
pub mod indexing_statuses; | ||
pub mod public_poi; | ||
pub mod version; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
pub use semver::Version; | ||
use serde::Deserialize; | ||
|
||
#[derive(Debug, Deserialize)] | ||
pub struct IndexerVersion { | ||
pub version: Version, | ||
} | ||
|
||
pub mod client { | ||
use toolshed::url::Url; | ||
|
||
use super::IndexerVersion; | ||
|
||
/// Sends a version query to the indexer and returns the version. | ||
pub async fn send_version_query( | ||
client: reqwest::Client, | ||
version_url: Url, | ||
) -> anyhow::Result<IndexerVersion> { | ||
let version = client | ||
.get(version_url.0) | ||
.send() | ||
.await | ||
.map_err(|err| anyhow::anyhow!("IndexerVersionError({err})"))? | ||
.json::<IndexerVersion>() | ||
.await | ||
.map_err(|err| anyhow::anyhow!("IndexerVersionError({err})"))?; | ||
|
||
Ok(version) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn deserialize_indexer_version_json() { | ||
//// Given | ||
let json = r#"{ | ||
"version": "0.1.0" | ||
}"#; | ||
|
||
//// When | ||
let version: IndexerVersion = | ||
serde_json::from_str(json).expect("Failed to deserialize IndexerVersion"); | ||
|
||
//// Then | ||
assert_eq!(version.version, Version::new(0, 1, 0)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use std::time::Duration; | ||
|
||
use assert_matches::assert_matches; | ||
use tokio::time::timeout; | ||
|
||
use graph_gateway::indexers_status::version::client; | ||
|
||
#[tokio::test] | ||
async fn query_indexer_public_pois() { | ||
//// Given | ||
let client = reqwest::Client::new(); | ||
let version_url = "https://testnet-indexer-03-europe-cent.thegraph.com/version" | ||
.parse() | ||
.expect("Invalid version url"); | ||
|
||
//// When | ||
let request = client::send_version_query(client, version_url); | ||
let response = timeout(Duration::from_secs(60), request) | ||
.await | ||
.expect("timeout"); | ||
|
||
//// Then | ||
// Assert version is present and greater than 0.1.0 | ||
assert_matches!(response, Ok(resp) => { | ||
assert!(resp.version > semver::Version::new(0, 1, 0)); | ||
}); | ||
} |