Skip to content

Commit 60f469d

Browse files
Merge pull request #21 from iExecBlockchainComputing/feature/add-protocol-integration-test
Add integration test suite
2 parents ee9ec3b + d8ef02f commit 60f469d

File tree

14 files changed

+2980
-5946
lines changed

14 files changed

+2980
-5946
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ jobs:
2020
run: npm run test
2121
- name: Test build
2222
run: npm run build
23+
# See Jenkinsfile-itest for "Run integration tests" step

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ build
33
generated
44
yarn.lock
55
test/.bin
6+
subgraph.yaml
7+
subgraph.test.yaml

.mocharc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extension": ["ts"],
3+
"spec": "itest/**/*.ts",
4+
"require": ["ts-node/register"],
5+
"timeout": 600000
6+
}

CHANGELOG.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
# Changelog
22

3-
All notable changes to this project will be documented in this file.
4-
5-
## next
6-
7-
### Added
8-
9-
### Changed
10-
11-
### Removed
3+
## vNext
4+
- Add integration test suite. (#21)
5+
- Add unit test suite. (#20)
126

137
## 1.0.0 - initial release
148

Jenkinsfile-itest

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
node('docker') {
2+
stage('Clone') {
3+
cleanWs()
4+
checkoutInfo = checkout(scm)
5+
echo "git checkout: ${checkoutInfo}"
6+
}
7+
stage('Pull images') {
8+
withCredentials([
9+
usernamePassword(credentialsId: 'docker-regis',
10+
usernameVariable: 'username', passwordVariable: 'password')
11+
]) {
12+
def registry = 'docker-regis.iex.ec'
13+
try {
14+
sh "echo -n '${password}' | docker login --username '${username}' --password-stdin ${registry}"
15+
sh 'cd docker/test/ && docker compose pull chain'
16+
} finally {
17+
sh "docker logout ${registry}"
18+
}
19+
}
20+
}
21+
docker.image('node:22-alpine')
22+
.inside('-v /var/run/docker.sock:/var/run/docker.sock --network=host --user=root') {
23+
stage('Init') {
24+
sh 'apk add docker docker-compose' // TODO: Use already built image for a faster job execution
25+
sh 'npm ci'
26+
}
27+
stage('Integration tests') {
28+
sh 'npm run itest'
29+
}
30+
}
31+
}

docker/Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM node:22
2+
WORKDIR /iexec-poco-subgraph
3+
COPY package*.json .
4+
RUN npm ci
5+
COPY schema.graphql .
6+
COPY subgraph.template.yaml .
7+
COPY networks.json .
8+
COPY src src
9+
ENTRYPOINT [ "npm", "run", "deploy:all" ]

docker/test/.env

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
DATA=/home/tmp/graph-test
22
DB_USER=graphnode
33
DB_PASSWORD=somerandompasswordthatishardtoguess
4-
DB_NAME=graphnode
4+
DB_NAME=graphnode-db
5+
NETWORK_NAME=test

docker/test/docker-compose.yml

Lines changed: 42 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,63 @@
1-
version: "3"
2-
3-
networks:
4-
thegraph:
5-
blockchain:
6-
71
services:
82
chain:
9-
image: "iexechub/poco-chaintest:5.3.0-token-parity"
3+
image: docker-regis.iex.ec/poco-chain:1.0.0-poco-v5.5.0-voucher-v1.0.0-nethermind
104
restart: unless-stopped
11-
networks:
12-
- blockchain
13-
expose:
14-
- 8545
15-
- 8546
165
ports:
176
- 8545:8545
18-
- 8546:8546
7+
# - 8546:8546 # port (not required for integration tests) fails to open on CI
198

209
ipfs:
21-
image: ipfs/go-ipfs:v0.10.0
2210
restart: unless-stopped
23-
networks:
24-
- thegraph
11+
image: ipfs/go-ipfs:v0.22.0
2512
ports:
13+
- 8080:8080
2614
- 5001:5001
27-
volumes:
28-
- ${DATA}/ipfs:/data/ipfs
2915

30-
postgres:
31-
image: postgres:12
16+
graphnode-postgres:
17+
image: postgres:16.4
3218
restart: unless-stopped
33-
networks:
34-
- thegraph
3519
command:
3620
- "postgres"
3721
- "-cshared_preload_libraries=pg_stat_statements"
38-
ports:
39-
- 5432:5432
22+
expose:
23+
- 5432
4024
environment:
41-
POSTGRES_USER: "${DB_USER}"
42-
POSTGRES_PASSWORD: "${DB_PASSWORD}"
43-
POSTGRES_DB: "${DB_NAME}"
25+
POSTGRES_USER: ${DB_USER}
26+
POSTGRES_PASSWORD: ${DB_PASSWORD}
27+
POSTGRES_DB: ${DB_NAME}
28+
POSTGRES_INITDB_ARGS: "-E UTF8 --locale=C"
4429

4530
graphnode:
46-
image: graphprotocol/graph-node:v0.27.0
31+
image: graphprotocol/graph-node:v0.35.1
4732
restart: unless-stopped
48-
networks:
49-
- blockchain
50-
- thegraph
51-
depends_on:
52-
- ipfs
53-
- postgres
54-
- chain
5533
ports:
56-
- 8000:8000 # http
57-
- 8001:8001 # ws
58-
- 8020:8020 # deploy
59-
- 8030:8030 # monitoring
60-
- 8040:8040 # prometeus
34+
- 8000:8000 # GraphQL HTTP
35+
# - 8001:8001 # GraphQL WS
36+
- 8020:8020 # admin RPC
37+
# - 8040:8040 # metrics
38+
environment:
39+
postgres_host: graphnode-postgres
40+
postgres_port: 5432
41+
postgres_user: ${DB_USER}
42+
postgres_pass: ${DB_PASSWORD}
43+
postgres_db: ${DB_NAME}
44+
ipfs: ipfs:5001
45+
ethereum: ${NETWORK_NAME}:http://chain:8545
46+
healthcheck:
47+
test: netcat -w 1 0.0.0.0 8020
48+
interval: 10s
49+
timeout: 5s
50+
retries: 10
51+
start_period: 30s
52+
53+
poco-subgraph-deployer:
54+
build:
55+
context: ../..
56+
dockerfile: docker/Dockerfile
6157
environment:
62-
RUST_BACKTRACE: 1
63-
postgres_host: postgres
64-
postgres_user: "${DB_USER}"
65-
postgres_pass: "${DB_PASSWORD}"
66-
postgres_db: "${DB_NAME}"
67-
ipfs: "ipfs:5001"
68-
ethereum: "test:http://chain:8545"
69-
GRAPH_NODE_ID: "graphnode_id"
58+
GRAPHNODE_URL: http://graphnode:8020
59+
IPFS_URL: http://ipfs:5001
60+
NETWORK_NAME: ${NETWORK_NAME}
61+
depends_on:
62+
graphnode:
63+
condition: service_healthy

itest/integration.test.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { ApolloClient, gql, InMemoryCache } from '@apollo/client';
2+
import { equal } from 'assert';
3+
import { DockerComposeEnvironment, Wait } from 'testcontainers';
4+
5+
const SECONDS = 1000;
6+
const MINUTES = 60 * SECONDS;
7+
const APIURL = 'http://localhost:8000/subgraphs/name/test/poco';
8+
const client = new ApolloClient({
9+
uri: APIURL,
10+
cache: new InMemoryCache(),
11+
});
12+
13+
describe('Integration tests', () => {
14+
/**
15+
* Services are started only once before running all tests to get a decent test
16+
* suite duration with multiple tests. Please switch to `beforeEach` if necessary.
17+
* Shutdown of services is handled by `testcontainers` framework.
18+
*/
19+
before(async () => {
20+
console.log('Starting services..');
21+
const environment = new DockerComposeEnvironment('docker/test/', 'docker-compose.yml')
22+
.withStartupTimeout(3 * MINUTES)
23+
.withWaitStrategy(
24+
'poco-subgraph-deployer-1',
25+
Wait.forLogMessage(
26+
'Deployed to http://graphnode:8000/subgraphs/name/test/poco/graphql',
27+
),
28+
);
29+
await environment.up();
30+
const secondsToWait = 5;
31+
console.log(
32+
`Waiting ${secondsToWait}s for graphnode to ingest a few blocks before querying it..`,
33+
);
34+
await new Promise((resolve) => {
35+
return setTimeout(resolve, secondsToWait * SECONDS);
36+
});
37+
});
38+
39+
it('should get protocol', async () => {
40+
const result = await client.query({
41+
query: gql(`
42+
query {
43+
protocol(id: "iExec") {
44+
id
45+
tvl
46+
}
47+
}
48+
`),
49+
});
50+
const protocol = result.data.protocol;
51+
equal(protocol.id, 'iExec');
52+
equal(protocol.tvl, '0.02025');
53+
});
54+
});

networks.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"test": {
3+
"ERC1538": {
4+
"address": "0xc4b11f41746D3Ad8504da5B383E1aB9aa969AbC7",
5+
"startBlock": 0
6+
},
7+
"Core": {
8+
"address": "0xc4b11f41746D3Ad8504da5B383E1aB9aa969AbC7",
9+
"startBlock": 0
10+
},
11+
"AppRegistry": {
12+
"address": "0xd5Fe43e3cDD29812949dc9b368345537D7B73001",
13+
"startBlock": 0
14+
},
15+
"DatasetRegistry": {
16+
"address": "0xf3bd0602fA481230271c5396f146e5695D3750A6",
17+
"startBlock": 0
18+
},
19+
"WorkerpoolRegistry": {
20+
"address": "0x6Cb57fA761812c34645C945cA89AAe3602D42eD3",
21+
"startBlock": 0
22+
}
23+
},
24+
"bellecour": {
25+
"ERC1538": {
26+
"address": "0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f",
27+
"startBlock": 4543300
28+
},
29+
"Core": {
30+
"address": "0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f",
31+
"startBlock": 4543300
32+
},
33+
"AppRegistry": {
34+
"address": "0xB1C52075b276f87b1834919167312221d50c9D16",
35+
"startBlock": 4543300
36+
},
37+
"DatasetRegistry": {
38+
"address": "0x799DAa22654128d0C64d5b79eac9283008158730",
39+
"startBlock": 4543300
40+
},
41+
"WorkerpoolRegistry": {
42+
"address": "0xC76A18c78B7e530A165c5683CB1aB134E21938B4",
43+
"startBlock": 4543300
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)