-
Notifications
You must be signed in to change notification settings - Fork 999
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: Add integration tests for multiple subgraph datasources
- Loading branch information
1 parent
32cf107
commit 8c2be00
Showing
19 changed files
with
1,691 additions
and
62 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
tests/integration-tests/multiple-subgraph-datasources/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,25 @@ | ||
{ | ||
"name": "multiple-subgraph-datasources", | ||
"version": "0.1.0", | ||
"scripts": { | ||
"build-contracts": "../../common/build-contracts.sh", | ||
"codegen": "graph codegen subgraph.yaml --skip-migrations", | ||
"test": "yarn build-contracts && truffle test --compile-none --network test", | ||
"create:test": "graph create test/multiple-subgraph-datasources --node $GRAPH_NODE_ADMIN_URI", | ||
"deploy:test": "graph deploy test/multiple-subgraph-datasources --version-label v0.0.1 --ipfs $IPFS_URI --node $GRAPH_NODE_ADMIN_URI" | ||
}, | ||
"devDependencies": { | ||
"@graphprotocol/graph-cli": "0.93.4-alpha-20250105163501-f401d0c57c4ba1f1af95a928d447efd63a56ecdc", | ||
"@graphprotocol/graph-ts": "0.36.0-alpha-20241129215038-b75cda9", | ||
"solc": "^0.8.2" | ||
}, | ||
"dependencies": { | ||
"@truffle/contract": "^4.3", | ||
"@truffle/hdwallet-provider": "^1.2", | ||
"apollo-fetch": "^0.7.0", | ||
"babel-polyfill": "^6.26.0", | ||
"babel-register": "^6.26.0", | ||
"gluegun": "^4.6.1", | ||
"truffle": "^5.2" | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
tests/integration-tests/multiple-subgraph-datasources/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,5 @@ | ||
type AggregatedData @entity { | ||
id: ID! | ||
sourceA: String | ||
sourceB: String | ||
} |
26 changes: 26 additions & 0 deletions
26
tests/integration-tests/multiple-subgraph-datasources/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,26 @@ | ||
import { dataSource, EntityTrigger } from '@graphprotocol/graph-ts' | ||
import { AggregatedData } from '../generated/schema' | ||
import { SourceAData } from '../generated/subgraph-QmU35YwAsv59gJxhejp3qqUrSFMaoBXuskNLX7wJHNUzyA' | ||
import { SourceBData } from '../generated/subgraph-QmXjHeC7j5iWF49oEngV3tqFrHvb4NhkFpAdJYVJ1SFPNk' | ||
|
||
export function handleSourceAData(data: EntityTrigger<SourceAData>): void { | ||
let aggregated = AggregatedData.load('1') | ||
if (!aggregated) { | ||
aggregated = new AggregatedData('1') | ||
aggregated.sourceA = data.data.data | ||
} else { | ||
aggregated.sourceA = data.data.data | ||
} | ||
aggregated.save() | ||
} | ||
|
||
export function handleSourceBData(data: EntityTrigger<SourceBData>): void { | ||
let aggregated = AggregatedData.load('1') | ||
if (!aggregated) { | ||
aggregated = new AggregatedData('1') | ||
aggregated.sourceB = data.data.data | ||
} else { | ||
aggregated.sourceB = data.data.data | ||
} | ||
aggregated.save() | ||
} |
35 changes: 35 additions & 0 deletions
35
tests/integration-tests/multiple-subgraph-datasources/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,35 @@ | ||
specVersion: 1.3.0 | ||
schema: | ||
file: ./schema.graphql | ||
dataSources: | ||
- kind: subgraph | ||
name: SourceA | ||
network: test | ||
source: | ||
address: 'QmU35YwAsv59gJxhejp3qqUrSFMaoBXuskNLX7wJHNUzyA' | ||
startBlock: 0 | ||
mapping: | ||
apiVersion: 0.0.7 | ||
language: wasm/assemblyscript | ||
entities: | ||
- AggregatedData | ||
handlers: | ||
- handler: handleSourceAData | ||
entity: SourceAData | ||
file: ./src/mapping.ts | ||
|
||
- kind: subgraph | ||
name: SourceB | ||
network: test | ||
source: | ||
address: 'QmXjHeC7j5iWF49oEngV3tqFrHvb4NhkFpAdJYVJ1SFPNk' | ||
startBlock: 0 | ||
mapping: | ||
apiVersion: 0.0.7 | ||
language: wasm/assemblyscript | ||
entities: | ||
- AggregatedData | ||
handlers: | ||
- handler: handleSourceBData | ||
entity: SourceBData | ||
file: ./src/mapping.ts |
33 changes: 33 additions & 0 deletions
33
tests/integration-tests/source-subgraph-a/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,33 @@ | ||
[ | ||
{ | ||
"inputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "constructor" | ||
}, | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": false, | ||
"internalType": "uint16", | ||
"name": "x", | ||
"type": "uint16" | ||
} | ||
], | ||
"name": "Trigger", | ||
"type": "event" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "uint16", | ||
"name": "x", | ||
"type": "uint16" | ||
} | ||
], | ||
"name": "emitTrigger", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
} | ||
] |
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,25 @@ | ||
{ | ||
"name": "source-subgraph-a", | ||
"version": "0.1.0", | ||
"scripts": { | ||
"build-contracts": "../../common/build-contracts.sh", | ||
"codegen": "graph codegen --skip-migrations", | ||
"test": "yarn build-contracts && truffle test --compile-none --network test", | ||
"create:test": "graph create test/source-subgraph-a --node $GRAPH_NODE_ADMIN_URI", | ||
"deploy:test": "graph deploy test/source-subgraph-a --version-label v0.0.1 --ipfs $IPFS_URI --node $GRAPH_NODE_ADMIN_URI" | ||
}, | ||
"devDependencies": { | ||
"@graphprotocol/graph-cli": "0.69.0", | ||
"@graphprotocol/graph-ts": "0.34.0", | ||
"solc": "^0.8.2" | ||
}, | ||
"dependencies": { | ||
"@truffle/contract": "^4.3", | ||
"@truffle/hdwallet-provider": "^1.2", | ||
"apollo-fetch": "^0.7.0", | ||
"babel-polyfill": "^6.26.0", | ||
"babel-register": "^6.26.0", | ||
"gluegun": "^4.6.1", | ||
"truffle": "^5.2" | ||
} | ||
} |
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,5 @@ | ||
type SourceAData @entity { | ||
id: ID! | ||
data: String! | ||
timestamp: BigInt! | ||
} |
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,9 @@ | ||
import { ethereum } from '@graphprotocol/graph-ts' | ||
import { SourceAData } from '../generated/schema' | ||
|
||
export function handleBlock(block: ethereum.Block): void { | ||
let entity = new SourceAData('1') | ||
entity.data = 'from source A' | ||
entity.timestamp = block.timestamp | ||
entity.save() | ||
} |
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,25 @@ | ||
specVersion: 0.0.4 | ||
description: Source Subgraph A | ||
repository: https://github.com/graphprotocol/graph-node | ||
schema: | ||
file: ./schema.graphql | ||
dataSources: | ||
- kind: ethereum/contract | ||
name: SimpleContract | ||
network: test | ||
source: | ||
address: "0x5FbDB2315678afecb367f032d93F642f64180aa3" | ||
abi: SimpleContract | ||
startBlock: 0 | ||
mapping: | ||
kind: ethereum/events | ||
apiVersion: 0.0.6 | ||
language: wasm/assemblyscript | ||
entities: | ||
- SourceAData | ||
abis: | ||
- name: SimpleContract | ||
file: ./abis/Contract.abi | ||
blockHandlers: | ||
- handler: handleBlock | ||
file: ./src/mapping.ts |
33 changes: 33 additions & 0 deletions
33
tests/integration-tests/source-subgraph-b/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,33 @@ | ||
[ | ||
{ | ||
"inputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "constructor" | ||
}, | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": false, | ||
"internalType": "uint16", | ||
"name": "x", | ||
"type": "uint16" | ||
} | ||
], | ||
"name": "Trigger", | ||
"type": "event" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "uint16", | ||
"name": "x", | ||
"type": "uint16" | ||
} | ||
], | ||
"name": "emitTrigger", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
} | ||
] |
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,25 @@ | ||
{ | ||
"name": "source-subgraph-b", | ||
"version": "0.1.0", | ||
"scripts": { | ||
"build-contracts": "../../common/build-contracts.sh", | ||
"codegen": "graph codegen --skip-migrations", | ||
"test": "yarn build-contracts && truffle test --compile-none --network test", | ||
"create:test": "graph create test/source-subgraph-b --node $GRAPH_NODE_ADMIN_URI", | ||
"deploy:test": "graph deploy test/source-subgraph-b --version-label v0.0.1 --ipfs $IPFS_URI --node $GRAPH_NODE_ADMIN_URI" | ||
}, | ||
"devDependencies": { | ||
"@graphprotocol/graph-cli": "0.69.0", | ||
"@graphprotocol/graph-ts": "0.34.0", | ||
"solc": "^0.8.2" | ||
}, | ||
"dependencies": { | ||
"@truffle/contract": "^4.3", | ||
"@truffle/hdwallet-provider": "^1.2", | ||
"apollo-fetch": "^0.7.0", | ||
"babel-polyfill": "^6.26.0", | ||
"babel-register": "^6.26.0", | ||
"gluegun": "^4.6.1", | ||
"truffle": "^5.2" | ||
} | ||
} |
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,5 @@ | ||
type SourceBData @entity { | ||
id: ID! | ||
data: String! | ||
blockNumber: BigInt! | ||
} |
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,9 @@ | ||
import { ethereum } from '@graphprotocol/graph-ts' | ||
import { SourceBData } from '../generated/schema' | ||
|
||
export function handleBlock(block: ethereum.Block): void { | ||
let entity = new SourceBData('1') | ||
entity.data = 'from source B' | ||
entity.blockNumber = block.number | ||
entity.save() | ||
} |
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,25 @@ | ||
specVersion: 0.0.4 | ||
description: Source Subgraph B | ||
repository: https://github.com/graphprotocol/graph-node | ||
schema: | ||
file: ./schema.graphql | ||
dataSources: | ||
- kind: ethereum/contract | ||
name: SimpleContract | ||
network: test | ||
source: | ||
address: "0x5FbDB2315678afecb367f032d93F642f64180aa3" | ||
abi: SimpleContract | ||
startBlock: 0 | ||
mapping: | ||
kind: ethereum/events | ||
apiVersion: 0.0.6 | ||
language: wasm/assemblyscript | ||
entities: | ||
- SourceBData | ||
abis: | ||
- name: SimpleContract | ||
file: ./abis/Contract.abi | ||
blockHandlers: | ||
- handler: handleBlock | ||
file: ./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
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
Oops, something went wrong.