From 87d54ae9b3f8e5beca82e63759e1726244f94208 Mon Sep 17 00:00:00 2001 From: incrypto32 Date: Fri, 16 Aug 2024 16:57:36 +0530 Subject: [PATCH] tests for multiple entities --- .../tests/chain/ethereum/manifest.rs | 2 +- .../source-subgraph/schema.graphql | 9 +++- .../source-subgraph/src/mapping.ts | 19 ++++++++- .../subgraph-data-sources/schema.graphql | 2 +- .../subgraph-data-sources/src/mapping.ts | 3 +- .../subgraph-data-sources/subgraph.yaml | 4 +- tests/tests/integration_tests.rs | 41 ++++++++++++++----- 7 files changed, 62 insertions(+), 18 deletions(-) diff --git a/store/test-store/tests/chain/ethereum/manifest.rs b/store/test-store/tests/chain/ethereum/manifest.rs index 058b31b66e9..0bd682ebb20 100644 --- a/store/test-store/tests/chain/ethereum/manifest.rs +++ b/store/test-store/tests/chain/ethereum/manifest.rs @@ -184,7 +184,7 @@ dataSources: - Gravatar network: mainnet source: - address: 'QmUVaWpdKgcxBov1jHEa8dr46d2rkVzfHuZFu4fXJ4sFse' + address: 'QmSWWT2yrTFDZSL8tRyoHEVrcEKAUsY2hj2TMQDfdDZU8h' startBlock: 9562480 mapping: apiVersion: 0.0.6 diff --git a/tests/integration-tests/source-subgraph/schema.graphql b/tests/integration-tests/source-subgraph/schema.graphql index 4855d8c2976..39af3e96105 100644 --- a/tests/integration-tests/source-subgraph/schema.graphql +++ b/tests/integration-tests/source-subgraph/schema.graphql @@ -1,7 +1,12 @@ - type Block @entity { id: ID! number: BigInt! hash: Bytes! -} \ No newline at end of file +} + +type Block2 @entity { + id: ID! + number: BigInt! + hash: Bytes! +} diff --git a/tests/integration-tests/source-subgraph/src/mapping.ts b/tests/integration-tests/source-subgraph/src/mapping.ts index 5ca859affdc..d978f870cda 100644 --- a/tests/integration-tests/source-subgraph/src/mapping.ts +++ b/tests/integration-tests/source-subgraph/src/mapping.ts @@ -1,10 +1,25 @@ import { ethereum, log } from '@graphprotocol/graph-ts'; -import { Block } from '../generated/schema'; +import { Block, Block2 } from '../generated/schema'; +import { BigInt } from '@graphprotocol/graph-ts'; export function handleBlock(block: ethereum.Block): void { log.info('handleBlock {}', [block.number.toString()]); - let blockEntity = new Block(block.number.toString()); + + let id = block.number.toString().concat('-v1'); + let blockEntity = new Block(id); blockEntity.number = block.number; blockEntity.hash = block.hash; blockEntity.save(); + + let id2 = block.number.toString().concat('-v2'); + let blockEntity2 = new Block(id2); + blockEntity2.number = block.number; + blockEntity2.hash = block.hash; + blockEntity2.save(); + + let id3 = block.number.toString().concat('-v3'); + let blockEntity3 = new Block2(id3); + blockEntity3.number = block.number; + blockEntity3.hash = block.hash; + blockEntity3.save(); } diff --git a/tests/integration-tests/subgraph-data-sources/schema.graphql b/tests/integration-tests/subgraph-data-sources/schema.graphql index 97f651ec409..4fd00d5a59b 100644 --- a/tests/integration-tests/subgraph-data-sources/schema.graphql +++ b/tests/integration-tests/subgraph-data-sources/schema.graphql @@ -1,5 +1,5 @@ type MirrorBlock @entity { - id: Bytes! + id: String! 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 5842b51b21d..0f2df0e4783 100644 --- a/tests/integration-tests/subgraph-data-sources/src/mapping.ts +++ b/tests/integration-tests/subgraph-data-sources/src/mapping.ts @@ -4,10 +4,11 @@ import { MirrorBlock } from '../generated/schema'; export function handleEntity(blockEntity: Entity): void { let blockNumber = blockEntity.getBigInt('number'); let blockHash = blockEntity.getBytes('hash'); + let id = blockEntity.getString('id'); log.info('Block number: {}', [blockNumber.toString()]); - let block = new MirrorBlock(blockHash); + let block = new MirrorBlock(id); block.number = blockNumber; block.hash = blockHash; block.save(); diff --git a/tests/integration-tests/subgraph-data-sources/subgraph.yaml b/tests/integration-tests/subgraph-data-sources/subgraph.yaml index eca534d501c..46af96b1d34 100644 --- a/tests/integration-tests/subgraph-data-sources/subgraph.yaml +++ b/tests/integration-tests/subgraph-data-sources/subgraph.yaml @@ -6,7 +6,7 @@ dataSources: name: Contract network: test source: - address: 'QmUVaWpdKgcxBov1jHEa8dr46d2rkVzfHuZFu4fXJ4sFse' + address: 'QmeZhEiJuBusu7GxCe6AytvqSsgwV8QxkbSYx5ojSFB28a' startBlock: 0 mapping: apiVersion: 0.0.7 @@ -16,4 +16,6 @@ dataSources: handlers: - handler: handleEntity entity: Block + - handler: handleEntity + entity: Block2 file: ./src/mapping.ts diff --git a/tests/tests/integration_tests.rs b/tests/tests/integration_tests.rs index fdc82b03510..2841dcda5d6 100644 --- a/tests/tests/integration_tests.rs +++ b/tests/tests/integration_tests.rs @@ -522,22 +522,43 @@ async fn subgraph_data_sources(ctx: TestContext) -> anyhow::Result<()> { assert!(subgraph.healthy); let expected_response = json!({ "mirrorBlocks": [ - { "number": "1" }, - { "number": "2" }, - { "number": "3" }, - { "number": "4" }, - { "number": "5" }, - { "number": "6" }, - { "number": "7" }, - { "number": "8" }, - { "number": "9" }, + { "id": "1-v1", "number": "1" }, + { "id": "1-v2", "number": "1" }, + { "id": "1-v3", "number": "1" }, + { "id": "2-v1", "number": "2" }, + { "id": "2-v2", "number": "2" }, + { "id": "2-v3", "number": "2" }, + { "id": "3-v1", "number": "3" }, + { "id": "3-v2", "number": "3" }, + { "id": "3-v3", "number": "3" }, + { "id": "4-v1", "number": "4" }, + { "id": "4-v2", "number": "4" }, + { "id": "4-v3", "number": "4" }, + { "id": "5-v1", "number": "5" }, + { "id": "5-v2", "number": "5" }, + { "id": "5-v3", "number": "5" }, + { "id": "6-v1", "number": "6" }, + { "id": "6-v2", "number": "6" }, + { "id": "6-v3", "number": "6" }, + { "id": "7-v1", "number": "7" }, + { "id": "7-v2", "number": "7" }, + { "id": "7-v3", "number": "7" }, + { "id": "8-v1", "number": "8" }, + { "id": "8-v2", "number": "8" }, + { "id": "8-v3", "number": "8" }, + { "id": "9-v1", "number": "9" }, + { "id": "9-v2", "number": "9" }, + { "id": "9-v3", "number": "9" }, + { "id": "10-v1", "number": "10" }, + { "id": "10-v2", "number": "10" }, + { "id": "10-v3", "number": "10" }, ] }); query_succeeds( "Blocks should be right", &subgraph, - "{ mirrorBlocks(where: {number_lt: 10}, orderBy: number) { number } }", + "{ mirrorBlocks(where: {number_lte: 10}, orderBy: number) { id, number } }", expected_response, ) .await?;