Skip to content

Commit

Permalink
Small testing code quality improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
neysofu committed Dec 15, 2024
1 parent cfffcc1 commit ff156b5
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 21 deletions.
6 changes: 3 additions & 3 deletions crates/graphix_lib/src/test_utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub fn test_indexer_from_url(url: impl Into<String>) -> Arc<impl IndexerClient>

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 {
Expand All @@ -53,9 +54,8 @@ pub fn test_indexer_from_url(url: impl Into<String>) -> Arc<impl IndexerClient>
))
}

/// Test utility function to create a valid `SubgraphDeployment` with an arbitrary deployment
/// id/ipfs hash.
pub fn test_deployment_id(deployment: impl Into<String>) -> IpfsCid {
/// Parses the [`IpfsCid`] of a subgraph deployment.
pub fn ipfs_cid(deployment: impl Into<String>) -> IpfsCid {
IpfsCid::from_str(&deployment.into()).unwrap()
}

Expand Down
4 changes: 2 additions & 2 deletions crates/graphix_lib/tests/it_indexing_statuses.rs
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
23 changes: 11 additions & 12 deletions crates/graphix_lib/tests/it_proofs_of_indexing.rs
Original file line number Diff line number Diff line change
@@ -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(),
Expand All @@ -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(),
Expand All @@ -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(),
Expand All @@ -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,
Expand All @@ -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);

Expand All @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion crates/indexer_client/src/real_indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions crates/network_sg_client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
)
}
Expand Down

0 comments on commit ff156b5

Please sign in to comment.