From 45214c9152c4d3537b340773c30f426b04eecb80 Mon Sep 17 00:00:00 2001 From: Eva Pace Date: Fri, 29 Jul 2022 12:27:16 -0300 Subject: [PATCH] refactor: Create helper 'latest_block' fn in store::subgraph tests --- store/postgres/tests/subgraph.rs | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/store/postgres/tests/subgraph.rs b/store/postgres/tests/subgraph.rs index 4d921c7eedc..846fc76df95 100644 --- a/store/postgres/tests/subgraph.rs +++ b/store/postgres/tests/subgraph.rs @@ -1,10 +1,11 @@ use graph::{ components::{ server::index_node::VersionInfo, - store::{DeploymentLocator, StatusStore}, + store::{DeploymentId, DeploymentLocator, StatusStore}, }, data::subgraph::schema::{DeploymentCreate, SubgraphError}, data::subgraph::{schema::SubgraphHealth, SubgraphFeature}, + prelude::BlockPtr, prelude::EntityChange, prelude::EntityChangeOperation, prelude::QueryStoreManager, @@ -55,6 +56,17 @@ fn get_version_info(store: &Store, subgraph_name: &str) -> VersionInfo { store.version_info(¤t).unwrap() } +async fn latest_block(store: &Store, deployment_id: DeploymentId) -> BlockPtr { + store + .subgraph_store() + .writable(LOGGER.clone(), deployment_id) + .await + .expect("can get writable") + .block_ptr() + .await + .unwrap() +} + async fn create_subgraph_with_non_fatal_feature( subgraph_id: &DeploymentHash, schema: &str, @@ -587,7 +599,7 @@ fn fatal_vs_non_fatal() { .unwrap(); assert!(!query_store - .has_non_fatal_errors(BLOCKS[0].number) + .has_non_fatal_errors(latest_block(&store, deployment.id).await.number) .await .unwrap()); @@ -596,7 +608,7 @@ fn fatal_vs_non_fatal() { .unwrap(); assert!(query_store - .has_non_fatal_errors(BLOCKS[1].number) + .has_non_fatal_errors(latest_block(&store, deployment.id).await.number) .await .unwrap()); }) @@ -647,7 +659,7 @@ fn has_non_fatal_errors_without_feature() { // Returns false because there are no errors. assert!(!query_store - .has_non_fatal_errors(BLOCKS[0].number) + .has_non_fatal_errors(latest_block(&store, deployment.id).await.number) .await .unwrap()); @@ -658,7 +670,7 @@ fn has_non_fatal_errors_without_feature() { // Still returns false because the subgraph doesn't have // the NonFatalErrors feature. assert!(!query_store - .has_non_fatal_errors(BLOCKS[1].number) + .has_non_fatal_errors(latest_block(&store, deployment.id).await.number) .await .unwrap()); }) @@ -694,7 +706,7 @@ fn fail_unfail_deterministic_error() { // We don't have any errors and the subgraph is healthy. assert!(!query_store - .has_non_fatal_errors(BLOCKS[0].number) + .has_non_fatal_errors(latest_block(&store, deployment.id).await.number) .await .unwrap()); let vi = get_version_info(&store, NAME); @@ -714,7 +726,7 @@ fn fail_unfail_deterministic_error() { // Still no fatal errors. assert!(!query_store - .has_non_fatal_errors(BLOCKS[1].number) + .has_non_fatal_errors(latest_block(&store, deployment.id).await.number) .await .unwrap()); let vi = get_version_info(&store, NAME); @@ -741,7 +753,7 @@ fn fail_unfail_deterministic_error() { // Now we have a fatal error because the subgraph failed. assert!(query_store - .has_non_fatal_errors(BLOCKS[1].number) + .has_non_fatal_errors(latest_block(&store, deployment.id).await.number) .await .unwrap()); let vi = get_version_info(&store, NAME); @@ -758,7 +770,7 @@ fn fail_unfail_deterministic_error() { // We don't have fatal errors anymore and the block got reverted. assert_eq!(outcome, UnfailOutcome::Unfailed); assert!(!query_store - .has_non_fatal_errors(BLOCKS[0].number) + .has_non_fatal_errors(latest_block(&store, deployment.id).await.number) .await .unwrap()); let vi = get_version_info(&store, NAME);