Skip to content

Commit 5a52078

Browse files
committed
tests: add integration tests
1 parent 18db52d commit 5a52078

File tree

5 files changed

+34
-4
lines changed

5 files changed

+34
-4
lines changed

tests/integration-tests/source-subgraph/schema.graphql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@ type Block2 @entity(immutable: true) {
1010
hash: Bytes!
1111
testMessage: String
1212
}
13+
14+
type Block3 @entity(immutable: true) {
15+
id: Bytes!
16+
number: BigInt!
17+
testMessage: String
18+
}

tests/integration-tests/source-subgraph/src/mapping.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ethereum, log, store } from '@graphprotocol/graph-ts';
2-
import { Block, Block2 } from '../generated/schema';
2+
import { Block, Block2, Block3 } from '../generated/schema';
33

44
export function handleBlock(block: ethereum.Block): void {
55
log.info('handleBlock {}', [block.number.toString()]);
@@ -22,4 +22,10 @@ export function handleBlock(block: ethereum.Block): void {
2222
blockEntity3.hash = block.hash;
2323
blockEntity3.testMessage = block.number.toString().concat('-message');
2424
blockEntity3.save();
25+
26+
let id4 = block.hash;
27+
let blockEntity4 = new Block3(id4);
28+
blockEntity4.number = block.number;
29+
blockEntity4.testMessage = block.number.toString().concat('-message');
30+
blockEntity4.save();
2531
}

tests/integration-tests/subgraph-data-sources/schema.graphql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@ type MirrorBlock @entity {
44
hash: Bytes!
55
testMessage: String
66
}
7+
8+
type MirrorBlockBytes @entity {
9+
id: Bytes!
10+
number: BigInt!
11+
testMessage: String
12+
}

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { log, store } from '@graphprotocol/graph-ts';
2-
import { Block, Block2 } from '../generated/subgraph-QmWi3H11QFE2PiWx6WcQkZYZdA5UasaBptUJqGn54MFux5';
3-
import { MirrorBlock } from '../generated/schema';
2+
import { Block, Block2, Block3 } from '../generated/subgraph-QmRWTEejPDDwALaquFGm6X2GBbbh5osYDXwCRRkoZ6KQhb';
3+
import { MirrorBlock, MirrorBlockBytes } from '../generated/schema';
44

55
export function handleEntity(block: Block): void {
66
let id = block.id;
@@ -23,6 +23,16 @@ export function handleEntity2(block: Block2): void {
2323
blockEntity.save();
2424
}
2525

26+
export function handleEntity3(block: Block3): void {
27+
let id = block.id;
28+
29+
let blockEntity = new MirrorBlockBytes(id);
30+
blockEntity.number = block.number;
31+
blockEntity.testMessage = block.testMessage;
32+
33+
blockEntity.save();
34+
}
35+
2636
export function loadOrCreateMirrorBlock(id: string): MirrorBlock {
2737
let block = MirrorBlock.load(id);
2838
if (!block) {

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: 'QmWi3H11QFE2PiWx6WcQkZYZdA5UasaBptUJqGn54MFux5'
9+
address: 'QmRWTEejPDDwALaquFGm6X2GBbbh5osYDXwCRRkoZ6KQhb'
1010
startBlock: 0
1111
mapping:
1212
apiVersion: 0.0.7
@@ -18,4 +18,6 @@ dataSources:
1818
entity: Block
1919
- handler: handleEntity2
2020
entity: Block2
21+
- handler: handleEntity3
22+
entity: Block3
2123
file: ./src/mapping.ts

0 commit comments

Comments
 (0)