Skip to content

Commit

Permalink
refactor: Create helper 'latest_block' fn in store::subgraph tests
Browse files Browse the repository at this point in the history
  • Loading branch information
evaporei committed Jul 29, 2022
1 parent f4f59b8 commit 45214c9
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions store/postgres/tests/subgraph.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -55,6 +56,17 @@ fn get_version_info(store: &Store, subgraph_name: &str) -> VersionInfo {
store.version_info(&current).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,
Expand Down Expand Up @@ -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());

Expand All @@ -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());
})
Expand Down Expand Up @@ -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());

Expand All @@ -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());
})
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 45214c9

Please sign in to comment.