Skip to content

Commit

Permalink
tests: Add integration tests for multiple subgraph datasources
Browse files Browse the repository at this point in the history
  • Loading branch information
incrypto32 committed Jan 6, 2025
1 parent 32cf107 commit 8c2be00
Show file tree
Hide file tree
Showing 19 changed files with 1,691 additions and 62 deletions.
25 changes: 25 additions & 0 deletions tests/integration-tests/multiple-subgraph-datasources/package.json
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"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type AggregatedData @entity {
id: ID!
sourceA: String
sourceB: String
}
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()
}
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 tests/integration-tests/source-subgraph-a/abis/Contract.abi
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"
}
]
25 changes: 25 additions & 0 deletions tests/integration-tests/source-subgraph-a/package.json
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"
}
}
5 changes: 5 additions & 0 deletions tests/integration-tests/source-subgraph-a/schema.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type SourceAData @entity {
id: ID!
data: String!
timestamp: BigInt!
}
9 changes: 9 additions & 0 deletions tests/integration-tests/source-subgraph-a/src/mapping.ts
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()
}
25 changes: 25 additions & 0 deletions tests/integration-tests/source-subgraph-a/subgraph.yaml
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 tests/integration-tests/source-subgraph-b/abis/Contract.abi
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"
}
]
25 changes: 25 additions & 0 deletions tests/integration-tests/source-subgraph-b/package.json
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"
}
}
5 changes: 5 additions & 0 deletions tests/integration-tests/source-subgraph-b/schema.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type SourceBData @entity {
id: ID!
data: String!
blockNumber: BigInt!
}
9 changes: 9 additions & 0 deletions tests/integration-tests/source-subgraph-b/src/mapping.ts
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()
}
25 changes: 25 additions & 0 deletions tests/integration-tests/source-subgraph-b/subgraph.yaml
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
4 changes: 2 additions & 2 deletions tests/integration-tests/source-subgraph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"deploy:test": "graph deploy test/source-subgraph --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",
"@graphprotocol/graph-cli": "0.91.0-alpha-20241129215038-b75cda9",
"@graphprotocol/graph-ts": "0.36.0-alpha-20241129215038-b75cda9",
"solc": "^0.8.2"
},
"dependencies": {
Expand Down
4 changes: 2 additions & 2 deletions tests/integration-tests/subgraph-data-sources/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"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"
"@graphprotocol/graph-cli": "0.91.0-alpha-20241129215038-b75cda9",
"@graphprotocol/graph-ts": "0.36.0-alpha-20241129215038-b75cda9"
}
}
Loading

0 comments on commit 8c2be00

Please sign in to comment.