Skip to content

Commit

Permalink
tests for multiple entities
Browse files Browse the repository at this point in the history
  • Loading branch information
incrypto32 authored and zorancv committed Aug 16, 2024
1 parent d4d4909 commit 87d54ae
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 18 deletions.
2 changes: 1 addition & 1 deletion store/test-store/tests/chain/ethereum/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ dataSources:
- Gravatar
network: mainnet
source:
address: 'QmUVaWpdKgcxBov1jHEa8dr46d2rkVzfHuZFu4fXJ4sFse'
address: 'QmSWWT2yrTFDZSL8tRyoHEVrcEKAUsY2hj2TMQDfdDZU8h'
startBlock: 9562480
mapping:
apiVersion: 0.0.6
Expand Down
9 changes: 7 additions & 2 deletions tests/integration-tests/source-subgraph/schema.graphql
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@


type Block @entity {
id: ID!
number: BigInt!
hash: Bytes!
}
}

type Block2 @entity {
id: ID!
number: BigInt!
hash: Bytes!
}
19 changes: 17 additions & 2 deletions tests/integration-tests/source-subgraph/src/mapping.ts
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
type MirrorBlock @entity {
id: Bytes!
id: String!
number: BigInt!
hash: Bytes!
}
3 changes: 2 additions & 1 deletion tests/integration-tests/subgraph-data-sources/src/mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion tests/integration-tests/subgraph-data-sources/subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ dataSources:
name: Contract
network: test
source:
address: 'QmUVaWpdKgcxBov1jHEa8dr46d2rkVzfHuZFu4fXJ4sFse'
address: 'QmeZhEiJuBusu7GxCe6AytvqSsgwV8QxkbSYx5ojSFB28a'
startBlock: 0
mapping:
apiVersion: 0.0.7
Expand All @@ -16,4 +16,6 @@ dataSources:
handlers:
- handler: handleEntity
entity: Block
- handler: handleEntity
entity: Block2
file: ./src/mapping.ts
41 changes: 31 additions & 10 deletions tests/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down

0 comments on commit 87d54ae

Please sign in to comment.