Skip to content

Commit 87d54ae

Browse files
incrypto32Zoran Cvetkov
authored andcommitted
tests for multiple entities
1 parent d4d4909 commit 87d54ae

File tree

7 files changed

+62
-18
lines changed

7 files changed

+62
-18
lines changed

store/test-store/tests/chain/ethereum/manifest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ dataSources:
184184
- Gravatar
185185
network: mainnet
186186
source:
187-
address: 'QmUVaWpdKgcxBov1jHEa8dr46d2rkVzfHuZFu4fXJ4sFse'
187+
address: 'QmSWWT2yrTFDZSL8tRyoHEVrcEKAUsY2hj2TMQDfdDZU8h'
188188
startBlock: 9562480
189189
mapping:
190190
apiVersion: 0.0.6
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11

2-
32
type Block @entity {
43
id: ID!
54
number: BigInt!
65
hash: Bytes!
7-
}
6+
}
7+
8+
type Block2 @entity {
9+
id: ID!
10+
number: BigInt!
11+
hash: Bytes!
12+
}
Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
import { ethereum, log } from '@graphprotocol/graph-ts';
2-
import { Block } from '../generated/schema';
2+
import { Block, Block2 } from '../generated/schema';
3+
import { BigInt } from '@graphprotocol/graph-ts';
34

45
export function handleBlock(block: ethereum.Block): void {
56
log.info('handleBlock {}', [block.number.toString()]);
6-
let blockEntity = new Block(block.number.toString());
7+
8+
let id = block.number.toString().concat('-v1');
9+
let blockEntity = new Block(id);
710
blockEntity.number = block.number;
811
blockEntity.hash = block.hash;
912
blockEntity.save();
13+
14+
let id2 = block.number.toString().concat('-v2');
15+
let blockEntity2 = new Block(id2);
16+
blockEntity2.number = block.number;
17+
blockEntity2.hash = block.hash;
18+
blockEntity2.save();
19+
20+
let id3 = block.number.toString().concat('-v3');
21+
let blockEntity3 = new Block2(id3);
22+
blockEntity3.number = block.number;
23+
blockEntity3.hash = block.hash;
24+
blockEntity3.save();
1025
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
type MirrorBlock @entity {
2-
id: Bytes!
2+
id: String!
33
number: BigInt!
44
hash: Bytes!
55
}

tests/integration-tests/subgraph-data-sources/src/mapping.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import { MirrorBlock } from '../generated/schema';
44
export function handleEntity(blockEntity: Entity): void {
55
let blockNumber = blockEntity.getBigInt('number');
66
let blockHash = blockEntity.getBytes('hash');
7+
let id = blockEntity.getString('id');
78

89
log.info('Block number: {}', [blockNumber.toString()]);
910

10-
let block = new MirrorBlock(blockHash);
11+
let block = new MirrorBlock(id);
1112
block.number = blockNumber;
1213
block.hash = blockHash;
1314
block.save();

tests/integration-tests/subgraph-data-sources/subgraph.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ dataSources:
66
name: Contract
77
network: test
88
source:
9-
address: 'QmUVaWpdKgcxBov1jHEa8dr46d2rkVzfHuZFu4fXJ4sFse'
9+
address: 'QmeZhEiJuBusu7GxCe6AytvqSsgwV8QxkbSYx5ojSFB28a'
1010
startBlock: 0
1111
mapping:
1212
apiVersion: 0.0.7
@@ -16,4 +16,6 @@ dataSources:
1616
handlers:
1717
- handler: handleEntity
1818
entity: Block
19+
- handler: handleEntity
20+
entity: Block2
1921
file: ./src/mapping.ts

tests/tests/integration_tests.rs

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -522,22 +522,43 @@ async fn subgraph_data_sources(ctx: TestContext) -> anyhow::Result<()> {
522522
assert!(subgraph.healthy);
523523
let expected_response = json!({
524524
"mirrorBlocks": [
525-
{ "number": "1" },
526-
{ "number": "2" },
527-
{ "number": "3" },
528-
{ "number": "4" },
529-
{ "number": "5" },
530-
{ "number": "6" },
531-
{ "number": "7" },
532-
{ "number": "8" },
533-
{ "number": "9" },
525+
{ "id": "1-v1", "number": "1" },
526+
{ "id": "1-v2", "number": "1" },
527+
{ "id": "1-v3", "number": "1" },
528+
{ "id": "2-v1", "number": "2" },
529+
{ "id": "2-v2", "number": "2" },
530+
{ "id": "2-v3", "number": "2" },
531+
{ "id": "3-v1", "number": "3" },
532+
{ "id": "3-v2", "number": "3" },
533+
{ "id": "3-v3", "number": "3" },
534+
{ "id": "4-v1", "number": "4" },
535+
{ "id": "4-v2", "number": "4" },
536+
{ "id": "4-v3", "number": "4" },
537+
{ "id": "5-v1", "number": "5" },
538+
{ "id": "5-v2", "number": "5" },
539+
{ "id": "5-v3", "number": "5" },
540+
{ "id": "6-v1", "number": "6" },
541+
{ "id": "6-v2", "number": "6" },
542+
{ "id": "6-v3", "number": "6" },
543+
{ "id": "7-v1", "number": "7" },
544+
{ "id": "7-v2", "number": "7" },
545+
{ "id": "7-v3", "number": "7" },
546+
{ "id": "8-v1", "number": "8" },
547+
{ "id": "8-v2", "number": "8" },
548+
{ "id": "8-v3", "number": "8" },
549+
{ "id": "9-v1", "number": "9" },
550+
{ "id": "9-v2", "number": "9" },
551+
{ "id": "9-v3", "number": "9" },
552+
{ "id": "10-v1", "number": "10" },
553+
{ "id": "10-v2", "number": "10" },
554+
{ "id": "10-v3", "number": "10" },
534555
]
535556
});
536557

537558
query_succeeds(
538559
"Blocks should be right",
539560
&subgraph,
540-
"{ mirrorBlocks(where: {number_lt: 10}, orderBy: number) { number } }",
561+
"{ mirrorBlocks(where: {number_lte: 10}, orderBy: number) { id, number } }",
541562
expected_response,
542563
)
543564
.await?;

0 commit comments

Comments
 (0)