From ff156b5f2a46244f77d3111316da23b889070e97 Mon Sep 17 00:00:00 2001 From: Filippo Costa Date: Sun, 15 Dec 2024 18:47:53 +0100 Subject: [PATCH] Small testing code quality improvements --- crates/graphix_lib/src/test_utils/mod.rs | 6 ++--- .../graphix_lib/tests/it_indexing_statuses.rs | 4 ++-- .../tests/it_proofs_of_indexing.rs | 23 +++++++++---------- crates/indexer_client/src/real_indexer.rs | 3 ++- crates/network_sg_client/src/lib.rs | 7 +++--- 5 files changed, 22 insertions(+), 21 deletions(-) diff --git a/crates/graphix_lib/src/test_utils/mod.rs b/crates/graphix_lib/src/test_utils/mod.rs index 279c52d..6d3a1b7 100644 --- a/crates/graphix_lib/src/test_utils/mod.rs +++ b/crates/graphix_lib/src/test_utils/mod.rs @@ -34,6 +34,7 @@ pub fn test_indexer_from_url(url: impl Into) -> Arc let mut addr = url.to_string().into_bytes(); addr.resize(20, 0); + // Create a fake address from the URL. let address = <[u8; 20]>::try_from(addr).unwrap().into(); let conf = IndexerConfig { @@ -53,9 +54,8 @@ pub fn test_indexer_from_url(url: impl Into) -> Arc )) } -/// Test utility function to create a valid `SubgraphDeployment` with an arbitrary deployment -/// id/ipfs hash. -pub fn test_deployment_id(deployment: impl Into) -> IpfsCid { +/// Parses the [`IpfsCid`] of a subgraph deployment. +pub fn ipfs_cid(deployment: impl Into) -> IpfsCid { IpfsCid::from_str(&deployment.into()).unwrap() } diff --git a/crates/graphix_lib/tests/it_indexing_statuses.rs b/crates/graphix_lib/tests/it_indexing_statuses.rs index 6f53fe3..54d3380 100644 --- a/crates/graphix_lib/tests/it_indexing_statuses.rs +++ b/crates/graphix_lib/tests/it_indexing_statuses.rs @@ -1,14 +1,14 @@ use std::time::Duration; use graphix_indexer_client::IndexerClient; -use graphix_lib::test_utils::{test_deployment_id, test_indexer_from_url}; +use graphix_lib::test_utils::{ipfs_cid, test_indexer_from_url}; #[tokio::test] async fn send_indexer_statuses_query() { //// Given let indexer = test_indexer_from_url("https://testnet-indexer-03-europe-cent.thegraph.com"); - let test_deployment = test_deployment_id("QmeYTH2fK2wv96XvnCGH2eyKFE8kmRfo53zYVy5dKysZtH"); + let test_deployment = ipfs_cid("QmeYTH2fK2wv96XvnCGH2eyKFE8kmRfo53zYVy5dKysZtH"); //// When let request_fut = IndexerClient::indexing_statuses(indexer); diff --git a/crates/graphix_lib/tests/it_proofs_of_indexing.rs b/crates/graphix_lib/tests/it_proofs_of_indexing.rs index d6b356f..f3c929d 100644 --- a/crates/graphix_lib/tests/it_proofs_of_indexing.rs +++ b/crates/graphix_lib/tests/it_proofs_of_indexing.rs @@ -1,14 +1,14 @@ use std::time::Duration; use graphix_indexer_client::{IndexerClient, PoiRequest}; -use graphix_lib::test_utils::{test_deployment_id, test_indexer_from_url}; +use graphix_lib::test_utils::{ipfs_cid, test_indexer_from_url}; #[tokio::test] async fn send_single_query_and_process_result() { //// Given let indexer = test_indexer_from_url("https://testnet-indexer-03-europe-cent.thegraph.com"); - let deployment = test_deployment_id("QmeYTH2fK2wv96XvnCGH2eyKFE8kmRfo53zYVy5dKysZtH"); + let deployment = ipfs_cid("QmeYTH2fK2wv96XvnCGH2eyKFE8kmRfo53zYVy5dKysZtH"); let poi_request = PoiRequest { deployment: deployment.clone(), @@ -34,7 +34,7 @@ async fn send_single_query_of_unknown_deployment_id_and_handle_error() { //// Given let indexer = test_indexer_from_url("https://testnet-indexer-03-europe-cent.thegraph.com"); - let deployment_unknown = test_deployment_id("Qmd3vU6y6pxxXPrvVWRZMN9soNB8AFQCEnqPa9jMSZZDEG"); + let deployment_unknown = ipfs_cid("Qmd3vU6y6pxxXPrvVWRZMN9soNB8AFQCEnqPa9jMSZZDEG"); let poi_request = PoiRequest { deployment: deployment_unknown.clone(), @@ -61,7 +61,7 @@ async fn send_single_query_of_unknown_block_number_and_handle_error() { //// Given let indexer = test_indexer_from_url("https://testnet-indexer-03-europe-cent.thegraph.com"); - let deployment = test_deployment_id("QmeYTH2fK2wv96XvnCGH2eyKFE8kmRfo53zYVy5dKysZtH"); + let deployment = ipfs_cid("QmeYTH2fK2wv96XvnCGH2eyKFE8kmRfo53zYVy5dKysZtH"); let poi_request = PoiRequest { deployment: deployment.clone(), @@ -87,16 +87,13 @@ async fn send_single_query_of_unknown_block_number_and_handle_error() { async fn send_multiple_queries_and_process_results() { // Given - // FIXME: This is temporarily set to 1 until we fix the error: 'Null value resolved for - // non-null field `proofOfIndexing`' Which is probably a Graph Node bug. Setting it to 1 - // reduces the impact of this issue. const MAX_REQUESTS_PER_QUERY: usize = 1; let indexer = test_indexer_from_url("https://testnet-indexer-03-europe-cent.thegraph.com"); - let deployment = test_deployment_id("QmeYTH2fK2wv96XvnCGH2eyKFE8kmRfo53zYVy5dKysZtH"); + let deployment = ipfs_cid("QmeYTH2fK2wv96XvnCGH2eyKFE8kmRfo53zYVy5dKysZtH"); - let poi_requests = (1..=MAX_REQUESTS_PER_QUERY + 2) + let poi_requests = (1..=MAX_REQUESTS_PER_QUERY) .map(|i| PoiRequest { deployment: deployment.clone(), block_number: i as u64, @@ -109,6 +106,8 @@ async fn send_multiple_queries_and_process_results() { .await .expect("Timeout"); + dbg!(&response); + // Then assert_eq!(response.len(), MAX_REQUESTS_PER_QUERY + 2); @@ -127,9 +126,9 @@ async fn send_multiple_queries_of_unknown_deployment_id_and_process_results() { //// Given let indexer = test_indexer_from_url("https://testnet-indexer-03-europe-cent.thegraph.com"); - let deployment0 = test_deployment_id("QmeYTH2fK2wv96XvnCGH2eyKFE8kmRfo53zYVy5dKysZtH"); - let deployment1 = test_deployment_id("QmawxQJ5U1JvgosoFVDyAwutLWxrckqVmBTQxaMaKoj3Lw"); - let deployment_unknown = test_deployment_id("Qmd3vU6y6pxxXPrvVWRZMN9soNB8AFQCEnqPa9jMSZZDEG"); + let deployment0 = ipfs_cid("QmeYTH2fK2wv96XvnCGH2eyKFE8kmRfo53zYVy5dKysZtH"); + let deployment1 = ipfs_cid("QmawxQJ5U1JvgosoFVDyAwutLWxrckqVmBTQxaMaKoj3Lw"); + let deployment_unknown = ipfs_cid("Qmd3vU6y6pxxXPrvVWRZMN9soNB8AFQCEnqPa9jMSZZDEG"); let poi_requests = vec![ PoiRequest { diff --git a/crates/indexer_client/src/real_indexer.rs b/crates/indexer_client/src/real_indexer.rs index 656bfff..ed2204e 100644 --- a/crates/indexer_client/src/real_indexer.rs +++ b/crates/indexer_client/src/real_indexer.rs @@ -322,11 +322,12 @@ impl IndexerClient for RealIndexer { } mod gql_types { + use std::str::FromStr; + use graphix_common_types::{BlockHash, IpfsCid, PoiBytes}; use super::*; use crate::BlockPointer; - use std::str::FromStr; pub type JSONObject = serde_json::Value; pub type BigInt = String; diff --git a/crates/network_sg_client/src/lib.rs b/crates/network_sg_client/src/lib.rs index 5318b62..612af30 100644 --- a/crates/network_sg_client/src/lib.rs +++ b/crates/network_sg_client/src/lib.rs @@ -344,10 +344,11 @@ mod tests { use super::*; fn network_sg_client_on_ethereum() -> NetworkSubgraphClient { + let api_key = std::env::var("GRAPHIX_GATEWAY_API_KEY").unwrap(); NetworkSubgraphClient::new( - "https://api.thegraph.com/subgraphs/name/graphprotocol/graph-network-mainnet" - .parse() - .unwrap(), + format!( + "https://gateway.thegraph.com/api/{api_key}/subgraphs/id/DZz4kDTdmzWLWsV373w2bSmoar3umKKH9y82SUKr5qmp" + ).parse().unwrap(), IntCounterVec::new(prometheus::Opts::new("foo", "bar"), &["a", "b"]).unwrap(), ) }