From c2e1ae2954a885c7c44e08d2687178d71c7ad922 Mon Sep 17 00:00:00 2001 From: incrypto32 Date: Wed, 24 Jul 2024 17:38:50 +0530 Subject: [PATCH] tests: change entity name for integration test --- .../subgraph-data-sources/schema.graphql | 9 +++---- .../subgraph-data-sources/src/mapping.ts | 12 +++++++-- tests/tests/integration_tests.rs | 27 ++++++++++++++++++- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/tests/integration-tests/subgraph-data-sources/schema.graphql b/tests/integration-tests/subgraph-data-sources/schema.graphql index 6f97fa65c43..97f651ec409 100644 --- a/tests/integration-tests/subgraph-data-sources/schema.graphql +++ b/tests/integration-tests/subgraph-data-sources/schema.graphql @@ -1,6 +1,5 @@ -type Data @entity { - id: ID! - foo: String - bar: Int - isTest: Boolean +type MirrorBlock @entity { + id: Bytes! + number: BigInt! + hash: Bytes! } diff --git a/tests/integration-tests/subgraph-data-sources/src/mapping.ts b/tests/integration-tests/subgraph-data-sources/src/mapping.ts index f7ec4ca3f65..5842b51b21d 100644 --- a/tests/integration-tests/subgraph-data-sources/src/mapping.ts +++ b/tests/integration-tests/subgraph-data-sources/src/mapping.ts @@ -1,6 +1,14 @@ import { Entity, log } from '@graphprotocol/graph-ts'; +import { MirrorBlock } from '../generated/schema'; export function handleEntity(blockEntity: Entity): void { - let blockNumberString = blockEntity.getBigInt('number').toString(); - log.info('===> Block: {}', [blockNumberString]); + let blockNumber = blockEntity.getBigInt('number'); + let blockHash = blockEntity.getBytes('hash'); + + log.info('Block number: {}', [blockNumber.toString()]); + + let block = new MirrorBlock(blockHash); + block.number = blockNumber; + block.hash = blockHash; + block.save(); } diff --git a/tests/tests/integration_tests.rs b/tests/tests/integration_tests.rs index 371ccadeea9..647d1cc6f76 100644 --- a/tests/tests/integration_tests.rs +++ b/tests/tests/integration_tests.rs @@ -517,7 +517,32 @@ async fn test_eth_api(ctx: TestContext) -> anyhow::Result<()> { Ok(()) } -async fn subgraph_data_sources(_ctx: TestContext) -> anyhow::Result<()> { +async fn subgraph_data_sources(ctx: TestContext) -> anyhow::Result<()> { + let subgraph = ctx.subgraph; + assert!(subgraph.healthy); + let expected_response = json!({ + "mirrorBlocks": [ + { "number": "0" }, + { "number": "1" }, + { "number": "2" }, + { "number": "3" }, + { "number": "4" }, + { "number": "5" }, + { "number": "6" }, + { "number": "7" }, + { "number": "8" }, + { "number": "9" }, + ] + }); + + query_succeeds( + "Blocks should be right", + &subgraph, + "{ mirrorBlocks(where: {number_lt: 10}, orderBy: number) { number } }", + expected_response, + ) + .await?; + Ok(()) }