-
Notifications
You must be signed in to change notification settings - Fork 991
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration tests for multiple subgraph datasources
- Loading branch information
1 parent
065ca55
commit 6dfd085
Showing
5 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
tests/integration-tests/multiple-subgraph-data-sources/abis/Contract.abi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[ | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": false, | ||
"internalType": "string", | ||
"name": "testCommand", | ||
"type": "string" | ||
} | ||
], | ||
"name": "TestEvent", | ||
"type": "event" | ||
} | ||
] |
13 changes: 13 additions & 0 deletions
13
tests/integration-tests/multiple-subgraph-data-sources/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "subgraph-data-sources", | ||
"version": "0.1.0", | ||
"scripts": { | ||
"codegen": "graph codegen --skip-migrations", | ||
"create:test": "graph create test/subgraph-data-sources --node $GRAPH_NODE_ADMIN_URI", | ||
"deploy:test": "graph deploy test/subgraph-data-sources --version-label v0.0.1 --ipfs $IPFS_URI --node $GRAPH_NODE_ADMIN_URI" | ||
}, | ||
"devDependencies": { | ||
"@graphprotocol/graph-cli": "0.79.0-alpha-20240711124603-49edf22", | ||
"@graphprotocol/graph-ts": "0.31.0" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
tests/integration-tests/multiple-subgraph-data-sources/schema.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
type MirrorBlock @entity { | ||
id: String! | ||
number: BigInt! | ||
hash: Bytes! | ||
testMessage: String | ||
} |
46 changes: 46 additions & 0 deletions
46
tests/integration-tests/multiple-subgraph-data-sources/src/mapping.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Entity, log, store } from '@graphprotocol/graph-ts'; | ||
import { MirrorBlock } from '../generated/schema'; | ||
|
||
export class EntityTrigger { | ||
constructor( | ||
public entityOp: u32, | ||
public entityType: string, | ||
public entity: Entity, | ||
public vid: i64, | ||
) {} | ||
} | ||
|
||
export function handleEntity(trigger: EntityTrigger): void { | ||
let blockEntity = trigger.entity; | ||
let blockNumber = blockEntity.getBigInt('number'); | ||
let blockHash = blockEntity.getBytes('hash'); | ||
let testMessage = blockEntity.get('testMessage'); | ||
let id = blockEntity.getString('id'); | ||
|
||
log.info('Block number: {}', [blockNumber.toString()]); | ||
|
||
if (trigger.entityOp == 2) { | ||
log.info('Removing block entity with id: {}', [id]); | ||
store.remove('MirrorBlock', id); | ||
return; | ||
} | ||
|
||
let block = loadOrCreateMirrorBlock(id); | ||
block.number = blockNumber; | ||
block.hash = blockHash; | ||
if (testMessage) { | ||
block.testMessage = testMessage.toString(); | ||
} | ||
|
||
block.save(); | ||
} | ||
|
||
export function loadOrCreateMirrorBlock(id: string): MirrorBlock { | ||
let block = MirrorBlock.load(id); | ||
if (!block) { | ||
log.info('Creating new block entity with id: {}', [id]); | ||
block = new MirrorBlock(id); | ||
} | ||
|
||
return block; | ||
} |
21 changes: 21 additions & 0 deletions
21
tests/integration-tests/multiple-subgraph-data-sources/subgraph.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
specVersion: 1.3.0 | ||
schema: | ||
file: ./schema.graphql | ||
dataSources: | ||
- kind: subgraph | ||
name: Contract | ||
network: test | ||
source: | ||
address: 'Qmaqf8cRxfxbduZppSHKG9DMuX5JZPMoGuwGb2DQuo48sq' | ||
startBlock: 0 | ||
mapping: | ||
apiVersion: 0.0.7 | ||
language: wasm/assemblyscript | ||
entities: | ||
- Gravatar | ||
handlers: | ||
- handler: handleEntity | ||
entity: Block | ||
- handler: handleEntity | ||
entity: Block2 | ||
file: ./src/mapping.ts |