Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ jobs:
run: npm run test
- name: Test build
run: npm run build
# See Jenkinsfile-itest for "Run integration tests" step
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DamienMure FYI 1

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ build
generated
yarn.lock
test/.bin
subgraph.yaml
subgraph.test.yaml
6 changes: 6 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extension": ["ts"],
"spec": "itest/**/*.ts",
"require": ["ts-node/register"],
"timeout": 600000
}
12 changes: 3 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
# Changelog

All notable changes to this project will be documented in this file.

## next

### Added

### Changed

### Removed
## vNext
- Add integration test suite. (#21)
- Add unit test suite. (#20)

## 1.0.0 - initial release

Expand Down
31 changes: 31 additions & 0 deletions Jenkinsfile-itest
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
node('docker') {
stage('Clone') {
cleanWs()
checkoutInfo = checkout(scm)
echo "git checkout: ${checkoutInfo}"
}
stage('Pull images') {
withCredentials([
usernamePassword(credentialsId: 'docker-regis',
usernameVariable: 'username', passwordVariable: 'password')
]) {
def registry = 'docker-regis.iex.ec'
try {
sh "echo -n '${password}' | docker login --username '${username}' --password-stdin ${registry}"
sh 'cd docker/test/ && docker compose pull chain'
} finally {
sh "docker logout ${registry}"
}
}
}
docker.image('node:22-alpine')
.inside('-v /var/run/docker.sock:/var/run/docker.sock --network=host --user=root') {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DamienMure FYI 2

stage('Init') {
sh 'apk add docker docker-compose' // TODO: Use already built image for a faster job execution
sh 'npm ci'
}
stage('Integration tests') {
sh 'npm run itest'
}
}
}
9 changes: 9 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM node:22
WORKDIR /iexec-poco-subgraph
COPY package*.json .
RUN npm ci
COPY schema.graphql .
COPY subgraph.template.yaml .
COPY networks.json .
COPY src src
ENTRYPOINT [ "npm", "run", "deploy:all" ]
3 changes: 2 additions & 1 deletion docker/test/.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
DATA=/home/tmp/graph-test
DB_USER=graphnode
DB_PASSWORD=somerandompasswordthatishardtoguess
DB_NAME=graphnode
DB_NAME=graphnode-db
NETWORK_NAME=test
90 changes: 42 additions & 48 deletions docker/test/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,69 +1,63 @@
version: "3"

networks:
thegraph:
blockchain:

services:
chain:
image: "iexechub/poco-chaintest:5.3.0-token-parity"
image: docker-regis.iex.ec/poco-chain:1.0.0-poco-v5.5.0-voucher-v1.0.0-nethermind
restart: unless-stopped
networks:
- blockchain
expose:
- 8545
- 8546
ports:
- 8545:8545
- 8546:8546
# - 8546:8546 # port (not required for integration tests) fails to open on CI

ipfs:
image: ipfs/go-ipfs:v0.10.0
restart: unless-stopped
networks:
- thegraph
image: ipfs/go-ipfs:v0.22.0
ports:
- 8080:8080
- 5001:5001
volumes:
- ${DATA}/ipfs:/data/ipfs

postgres:
image: postgres:12
graphnode-postgres:
image: postgres:16.4
restart: unless-stopped
networks:
- thegraph
command:
- "postgres"
- "-cshared_preload_libraries=pg_stat_statements"
ports:
- 5432:5432
expose:
- 5432
environment:
POSTGRES_USER: "${DB_USER}"
POSTGRES_PASSWORD: "${DB_PASSWORD}"
POSTGRES_DB: "${DB_NAME}"
POSTGRES_USER: ${DB_USER}
POSTGRES_PASSWORD: ${DB_PASSWORD}
POSTGRES_DB: ${DB_NAME}
POSTGRES_INITDB_ARGS: "-E UTF8 --locale=C"

graphnode:
image: graphprotocol/graph-node:v0.27.0
image: graphprotocol/graph-node:v0.35.1
restart: unless-stopped
networks:
- blockchain
- thegraph
depends_on:
- ipfs
- postgres
- chain
ports:
- 8000:8000 # http
- 8001:8001 # ws
- 8020:8020 # deploy
- 8030:8030 # monitoring
- 8040:8040 # prometeus
- 8000:8000 # GraphQL HTTP
# - 8001:8001 # GraphQL WS
- 8020:8020 # admin RPC
# - 8040:8040 # metrics
environment:
postgres_host: graphnode-postgres
postgres_port: 5432
postgres_user: ${DB_USER}
postgres_pass: ${DB_PASSWORD}
postgres_db: ${DB_NAME}
ipfs: ipfs:5001
ethereum: ${NETWORK_NAME}:http://chain:8545
healthcheck:
test: netcat -w 1 0.0.0.0 8020
interval: 10s
timeout: 5s
retries: 10
start_period: 30s

poco-subgraph-deployer:
build:
context: ../..
dockerfile: docker/Dockerfile
environment:
RUST_BACKTRACE: 1
postgres_host: postgres
postgres_user: "${DB_USER}"
postgres_pass: "${DB_PASSWORD}"
postgres_db: "${DB_NAME}"
ipfs: "ipfs:5001"
ethereum: "test:http://chain:8545"
GRAPH_NODE_ID: "graphnode_id"
GRAPHNODE_URL: http://graphnode:8020
IPFS_URL: http://ipfs:5001
NETWORK_NAME: ${NETWORK_NAME}
depends_on:
graphnode:
condition: service_healthy
54 changes: 54 additions & 0 deletions itest/integration.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { ApolloClient, gql, InMemoryCache } from '@apollo/client';
import { equal } from 'assert';
import { DockerComposeEnvironment, Wait } from 'testcontainers';

const SECONDS = 1000;
const MINUTES = 60 * SECONDS;
const APIURL = 'http://localhost:8000/subgraphs/name/test/poco';
const client = new ApolloClient({
uri: APIURL,
cache: new InMemoryCache(),
});

describe('Integration tests', () => {
/**
* Services are started only once before running all tests to get a decent test
* suite duration with multiple tests. Please switch to `beforeEach` if necessary.
* Shutdown of services is handled by `testcontainers` framework.
*/
before(async () => {
console.log('Starting services..');
const environment = new DockerComposeEnvironment('docker/test/', 'docker-compose.yml')
.withStartupTimeout(3 * MINUTES)
.withWaitStrategy(
'poco-subgraph-deployer-1',
Wait.forLogMessage(
'Deployed to http://graphnode:8000/subgraphs/name/test/poco/graphql',
),
);
await environment.up();
const secondsToWait = 5;
console.log(
`Waiting ${secondsToWait}s for graphnode to ingest a few blocks before querying it..`,
);
await new Promise((resolve) => {
return setTimeout(resolve, secondsToWait * SECONDS);
});
});

it('should get protocol', async () => {
const result = await client.query({
query: gql(`
query {
protocol(id: "iExec") {
id
tvl
}
}
`),
});
const protocol = result.data.protocol;
equal(protocol.id, 'iExec');
equal(protocol.tvl, '0.02025');
});
});
46 changes: 46 additions & 0 deletions networks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"test": {
"ERC1538": {
"address": "0xc4b11f41746D3Ad8504da5B383E1aB9aa969AbC7",
"startBlock": 0
},
"Core": {
"address": "0xc4b11f41746D3Ad8504da5B383E1aB9aa969AbC7",
"startBlock": 0
},
"AppRegistry": {
"address": "0xd5Fe43e3cDD29812949dc9b368345537D7B73001",
"startBlock": 0
},
"DatasetRegistry": {
"address": "0xf3bd0602fA481230271c5396f146e5695D3750A6",
"startBlock": 0
},
"WorkerpoolRegistry": {
"address": "0x6Cb57fA761812c34645C945cA89AAe3602D42eD3",
"startBlock": 0
}
},
"bellecour": {
"ERC1538": {
"address": "0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f",
"startBlock": 4543300
},
"Core": {
"address": "0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f",
"startBlock": 4543300
},
"AppRegistry": {
"address": "0xB1C52075b276f87b1834919167312221d50c9D16",
"startBlock": 4543300
},
"DatasetRegistry": {
"address": "0x799DAa22654128d0C64d5b79eac9283008158730",
"startBlock": 4543300
},
"WorkerpoolRegistry": {
"address": "0xC76A18c78B7e530A165c5683CB1aB134E21938B4",
"startBlock": 4543300
}
}
}
Loading