Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type network subgraph deployment strongly #67

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions common/src/allocations/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,11 @@ mod test {
let mock_server = MockServer::start().await;
let network_subgraph_endpoint = NetworkSubgraph::local_deployment_endpoint(
&mock_server.uri(),
test_vectors::NETWORK_SUBGRAPH_ID,
&test_vectors::NETWORK_SUBGRAPH_DEPLOYMENT,
);
let network_subgraph = NetworkSubgraph::new(
Some(&mock_server.uri()),
Some(test_vectors::NETWORK_SUBGRAPH_ID),
Some(&test_vectors::NETWORK_SUBGRAPH_DEPLOYMENT),
network_subgraph_endpoint.as_ref(),
);

Expand All @@ -224,7 +224,7 @@ mod test {
Mock::given(method("POST"))
.and(path(format!(
"/subgraphs/id/{}",
test_vectors::NETWORK_SUBGRAPH_ID
*test_vectors::NETWORK_SUBGRAPH_DEPLOYMENT
)))
.and(body_string_contains("currentEpoch"))
.respond_with(ResponseTemplate::new(200).set_body_json(
Expand All @@ -239,7 +239,7 @@ mod test {
Mock::given(method("POST"))
.and(path(format!(
"/subgraphs/id/{}",
test_vectors::NETWORK_SUBGRAPH_ID
*test_vectors::NETWORK_SUBGRAPH_DEPLOYMENT
)))
.and(body_string_contains("activeAllocations"))
.respond_with(ResponseTemplate::new(200).set_body_raw(
Expand Down
20 changes: 14 additions & 6 deletions common/src/network_subgraph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use graphql::http::Response;
use reqwest::{header, Client, Url};
use serde::de::Deserialize;
use serde_json::Value;
use toolshed::thegraph::DeploymentId;

/// Network subgraph query wrapper
///
Expand All @@ -20,7 +21,7 @@ pub struct NetworkSubgraph {
impl NetworkSubgraph {
pub fn new(
graph_node_query_endpoint: Option<&str>,
deployment: Option<&str>,
deployment: Option<&DeploymentId>,
network_subgraph_url: &str,
) -> NetworkSubgraph {
//TODO: Check indexing status of the local network subgraph deployment
Expand All @@ -46,10 +47,13 @@ impl NetworkSubgraph {
}
}

pub fn local_deployment_endpoint(graph_node_query_endpoint: &str, deployment: &str) -> Url {
pub fn local_deployment_endpoint(
graph_node_query_endpoint: &str,
deployment: &DeploymentId,
) -> Url {
Url::parse(graph_node_query_endpoint)
.and_then(|u| u.join("/subgraphs/id/"))
.and_then(|u| u.join(deployment))
.and_then(|u| u.join(&deployment.to_string()))
.expect("Could not parse graph node query endpoint for the network subgraph deployment")
}

Expand All @@ -75,17 +79,21 @@ mod test {
use wiremock::matchers::{method, path};
use wiremock::{Mock, MockServer, ResponseTemplate};

use crate::test_vectors;

use super::*;

const GRAPH_NODE_STATUS_ENDPOINT: &str = "http://localhost:8000/";
const NETWORK_SUBGRAPH_ID: &str = "QmV614UpBCpuusv5MsismmPYu4KqLtdeNMKpiNrX56kw6u";
const NETWORK_SUBGRAPH_URL: &str =
"https://api.thegraph.com/subgraphs/name/graphprotocol/graph-network-goerli";

async fn mock_graph_node_server() -> MockServer {
let mock_server = MockServer::start().await;
let mock = Mock::given(method("POST"))
.and(path("/subgraphs/id/".to_string() + NETWORK_SUBGRAPH_ID))
.and(path(format!(
"/subgraphs/id/{}",
*test_vectors::NETWORK_SUBGRAPH_DEPLOYMENT
)))
.respond_with(ResponseTemplate::new(200).set_body_raw(
r#"
{
Expand All @@ -106,7 +114,7 @@ mod test {
fn network_subgraph() -> NetworkSubgraph {
NetworkSubgraph::new(
Some(GRAPH_NODE_STATUS_ENDPOINT),
Some(NETWORK_SUBGRAPH_ID),
Some(&test_vectors::NETWORK_SUBGRAPH_DEPLOYMENT),
NETWORK_SUBGRAPH_URL,
)
}
Expand Down
4 changes: 2 additions & 2 deletions common/src/test_vectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ use toolshed::thegraph::DeploymentId;

use crate::prelude::{Allocation, AllocationStatus, SubgraphDeployment};

pub const NETWORK_SUBGRAPH_ID: &str = "QmU7zqJyHSyUP3yFii8sBtHT8FaJn2WmUnRvwjAUTjwMBP";

/// The allocation IDs below are generated using the mnemonic
/// "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
/// and the following epoch and index:
Expand Down Expand Up @@ -104,6 +102,8 @@ pub const ALLOCATIONS_QUERY_RESPONSE: &str = r#"
"#;

lazy_static! {
pub static ref NETWORK_SUBGRAPH_DEPLOYMENT: DeploymentId = DeploymentId::from_str("QmU7zqJyHSyUP3yFii8sBtHT8FaJn2WmUnRvwjAUTjwMBP").unwrap();

pub static ref INDEXER_OPERATOR_MNEMONIC: String = String::from(
"abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about",
);
Expand Down
5 changes: 4 additions & 1 deletion service/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ async fn main() -> Result<(), std::io::Error> {
config
.network_subgraph
.network_subgraph_deployment
.as_deref(),
.map(|s| DeploymentId::from_str(&s))
.transpose()
.expect("Failed to parse invalid network subgraph deployment")
.as_ref(),
&config.network_subgraph.network_subgraph_endpoint,
)));

Expand Down