From 449aed99d1488939596a1839e5dd2c8415d4a6a5 Mon Sep 17 00:00:00 2001 From: incrypto32 Date: Mon, 15 Apr 2024 17:25:19 +0400 Subject: [PATCH] tests: move subgraph param to TestContext --- Cargo.lock | 2 +- tests/integration-tests/yarn.lock | 8 ++--- tests/tests/integration_tests.rs | 51 ++++++++++++++++++++----------- 3 files changed, 38 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 93e84cfd1e4..77a3a87ae8a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1973,7 +1973,7 @@ dependencies = [ [[package]] name = "graph_derive" -version = "0.34.0" +version = "0.35.0" dependencies = [ "heck", "proc-macro-utils", diff --git a/tests/integration-tests/yarn.lock b/tests/integration-tests/yarn.lock index 8c7b0af0167..cfded455343 100644 --- a/tests/integration-tests/yarn.lock +++ b/tests/integration-tests/yarn.lock @@ -904,10 +904,10 @@ which "2.0.2" yaml "1.10.2" -"@graphprotocol/graph-ts@0.31.0": - version "0.31.0" - resolved "https://registry.yarnpkg.com/@graphprotocol/graph-ts/-/graph-ts-0.31.0.tgz#730668c0369828b31bef81e8d9bc66b9b48e3480" - integrity sha512-xreRVM6ho2BtolyOh2flDkNoGZximybnzUnF53zJVp0+Ed0KnAlO1/KOCUYw06euVI9tk0c9nA2Z/D5SIQV2Rg== +"@graphprotocol/graph-ts@0.34.0": + version "0.34.0" + resolved "https://registry.yarnpkg.com/@graphprotocol/graph-ts/-/graph-ts-0.34.0.tgz#ca47398295b114f25b412faa364b98af31fa2bb7" + integrity sha512-gnhjai65AV4YMYe9QHGz+HP/jdzI54z/nOfEXZFfh6m987EP2iy3ycLXrTi+ahcogHH7vtoWFdXbUzZbE8bCAg== dependencies: assemblyscript "0.19.10" diff --git a/tests/tests/integration_tests.rs b/tests/tests/integration_tests.rs index 36102a0ef30..7f0969cfd14 100644 --- a/tests/tests/integration_tests.rs +++ b/tests/tests/integration_tests.rs @@ -25,12 +25,14 @@ use tokio::task::JoinError; use tokio::time::sleep; type TestFn = Box< - dyn FnOnce(Subgraph, TestContext) -> Pin> + Send>> + dyn FnOnce(TestContext) -> Pin> + Send>> + Sync + Send, >; -struct TestContext {} +struct TestContext { + subgraph: Subgraph, +} enum TestStatus { Ok, @@ -94,15 +96,15 @@ struct TestCase { } impl TestCase { - fn new(name: &str, test: fn(Subgraph, TestContext) -> T) -> Self + fn new(name: &str, test: fn(TestContext) -> T) -> Self where T: Future> + Send + 'static, { - fn force_boxed(f: fn(Subgraph, TestContext) -> T) -> TestFn + fn force_boxed(f: fn(TestContext) -> T) -> TestFn where T: Future> + Send + 'static, { - Box::new(move |sg, ctx| Box::pin(f(sg, ctx))) + Box::new(move |ctx| Box::pin(f(ctx))) } Self { @@ -142,11 +144,13 @@ impl TestCase { status!(&self.name, "Subgraph ({}) has failed", subgraph.deployment); } - let ctx = TestContext {}; + let ctx = TestContext { + subgraph: subgraph.clone(), + }; status!(&self.name, "Starting test"); let subgraph2 = subgraph.clone(); - let res = tokio::spawn(async move { (self.test)(subgraph, ctx).await }).await; + let res = tokio::spawn(async move { (self.test)(ctx).await }).await; let status = match res { Ok(Ok(())) => { status!(&self.name, "Test succeeded"); @@ -227,7 +231,8 @@ pub async fn query_succeeds( * the `cases` variable in `integration_tests`. */ -async fn test_int8(subgraph: Subgraph, _ctx: TestContext) -> anyhow::Result<()> { +async fn test_int8(ctx: TestContext) -> anyhow::Result<()> { + let subgraph = ctx.subgraph; assert!(subgraph.healthy); let resp = subgraph @@ -259,7 +264,8 @@ async fn test_int8(subgraph: Subgraph, _ctx: TestContext) -> anyhow::Result<()> * the `cases` variable in `integration_tests`. */ -async fn test_timestamp(subgraph: Subgraph, _ctx: TestContext) -> anyhow::Result<()> { +async fn test_timestamp(ctx: TestContext) -> anyhow::Result<()> { + let subgraph = ctx.subgraph; assert!(subgraph.healthy); let resp = subgraph @@ -286,7 +292,8 @@ async fn test_timestamp(subgraph: Subgraph, _ctx: TestContext) -> anyhow::Result Ok(()) } -async fn test_block_handlers(subgraph: Subgraph, _ctx: TestContext) -> anyhow::Result<()> { +async fn test_block_handlers(ctx: TestContext) -> anyhow::Result<()> { + let subgraph = ctx.subgraph; assert!(subgraph.healthy); // test non-filtered blockHandler @@ -423,7 +430,8 @@ async fn test_block_handlers(subgraph: Subgraph, _ctx: TestContext) -> anyhow::R Ok(()) } -async fn test_eth_api(subgraph: Subgraph, _ctx: TestContext) -> anyhow::Result<()> { +async fn test_eth_api(ctx: TestContext) -> anyhow::Result<()> { + let subgraph = ctx.subgraph; assert!(subgraph.healthy); let expected_response = json!({ @@ -445,7 +453,8 @@ async fn test_eth_api(subgraph: Subgraph, _ctx: TestContext) -> anyhow::Result<( Ok(()) } -async fn test_ganache_reverts(subgraph: Subgraph, _ctx: TestContext) -> anyhow::Result<()> { +async fn test_ganache_reverts(ctx: TestContext) -> anyhow::Result<()> { + let subgraph = ctx.subgraph; assert!(subgraph.healthy); let exp = json!({ @@ -473,12 +482,14 @@ async fn test_ganache_reverts(subgraph: Subgraph, _ctx: TestContext) -> anyhow:: Ok(()) } -async fn test_host_exports(subgraph: Subgraph, _ctx: TestContext) -> anyhow::Result<()> { +async fn test_host_exports(ctx: TestContext) -> anyhow::Result<()> { + let subgraph = ctx.subgraph; assert!(subgraph.healthy); Ok(()) } -async fn test_non_fatal_errors(subgraph: Subgraph, _ctx: TestContext) -> anyhow::Result<()> { +async fn test_non_fatal_errors(ctx: TestContext) -> anyhow::Result<()> { + let subgraph = ctx.subgraph; assert!(!subgraph.healthy); let query = "query GetSubgraphFeatures($deployment: String!) { @@ -522,7 +533,8 @@ async fn test_non_fatal_errors(subgraph: Subgraph, _ctx: TestContext) -> anyhow: Ok(()) } -async fn test_overloaded_functions(subgraph: Subgraph, _ctx: TestContext) -> anyhow::Result<()> { +async fn test_overloaded_functions(ctx: TestContext) -> anyhow::Result<()> { + let subgraph = ctx.subgraph; // all overloads of the contract function are called assert!(subgraph.healthy); @@ -552,7 +564,8 @@ async fn test_overloaded_functions(subgraph: Subgraph, _ctx: TestContext) -> any Ok(()) } -async fn test_value_roundtrip(subgraph: Subgraph, _ctx: TestContext) -> anyhow::Result<()> { +async fn test_value_roundtrip(ctx: TestContext) -> anyhow::Result<()> { + let subgraph = ctx.subgraph; assert!(subgraph.healthy); let exp = json!({ @@ -570,7 +583,8 @@ async fn test_value_roundtrip(subgraph: Subgraph, _ctx: TestContext) -> anyhow:: Ok(()) } -async fn test_remove_then_update(subgraph: Subgraph, _ctx: TestContext) -> anyhow::Result<()> { +async fn test_remove_then_update(ctx: TestContext) -> anyhow::Result<()> { + let subgraph = ctx.subgraph; assert!(subgraph.healthy); let exp = json!({ @@ -588,7 +602,8 @@ async fn test_remove_then_update(subgraph: Subgraph, _ctx: TestContext) -> anyho Ok(()) } -async fn test_poi_for_failed_subgraph(subgraph: Subgraph, _ctx: TestContext) -> anyhow::Result<()> { +async fn test_poi_for_failed_subgraph(ctx: TestContext) -> anyhow::Result<()> { + let subgraph = ctx.subgraph; const INDEXING_STATUS: &str = r#" query statuses($subgraphName: String!) { statuses: indexingStatusesForSubgraphName(subgraphName: $subgraphName) {