Skip to content

Commit

Permalink
Merge pull request #32 from iExecBlockchainComputing/release/1.1.0
Browse files Browse the repository at this point in the history
Release v1.1.0 - Support deal sponsor
  • Loading branch information
jeremyjams authored Feb 10, 2025
2 parents cacdd58 + 157d280 commit 001b887
Show file tree
Hide file tree
Showing 32 changed files with 4,505 additions and 6,635 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
on:
pull_request:
branches:
- develop
- main

jobs:
coverage:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Init
run: npm ci
- name: Run Coverage
run: (npm run coverage 2>&1) | tee /tmp/coverage.out | cat
- name: Extract coverage
run: echo "COVERAGE=$(cat /tmp/coverage.out | grep "Global test coverage")" >> $GITHUB_ENV
- name: Display coverage in Github PR checks
# See https://docs.github.com/en/rest/checks/runs?apiVersion=2022-11-28#create-a-check-run
# and https://www.kenmuse.com/blog/creating-github-checks/
env:
GH_TOKEN: ${{ github.token }}
run: | # TODO: Set "failure" conclusion if coverage is too low
curl -L -X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GH_TOKEN"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ github.repository }}/check-runs \
-d '{"name":"Coverage ratio", "head_sha":"${{ github.event.pull_request.head.sha }}", "status":"completed", "conclusion":"success", "output":{"title":"${{env.COVERAGE}}", "summary":""}}'
23 changes: 23 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
on:
push:
branches:
- feature/*
- bugfix/*
- develop
- release/*
- hotfix/*
- main

jobs:
test:
runs-on: ubuntu-22.04 # For 24.04+, see https://github.com/graphprotocol/graph-tooling/issues/1546#issuecomment-2589680195
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Init
run: npm ci
- name: Run unit tests
run: npm run test
- name: Test build
run: npm run build
# See Jenkinsfile-itest for "Run integration tests" step
24 changes: 0 additions & 24 deletions .github/workflows/nodejs.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ node_modules
build
generated
yarn.lock
test/.bin
subgraph.yaml
subgraph.test.yaml
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lint-staged
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": 1000000
}
10 changes: 10 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"printWidth": 100,
"singleQuote": true,
"tabWidth": 4,
"trailingComma": "all",
"endOfLine": "auto",
"plugins": [
"prettier-plugin-organize-imports"
]
}
21 changes: 10 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
# Changelog

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

## next

### Added

### Changed

### Removed

## 1.0.0 - initial release
## v1.1.0 - Support deal sponsor
- Add `sponsor` to `deal`. (#31)
- Update deployment hosts:
- production (#30)
- staging (#29)
- Display coverage in Github PR checks. (#26)
- Add integration test suite. (#21)
- Add unit test suite. (#20)

## v1.0.0 - initial release

### features

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') {
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'
}
}
}
7 changes: 4 additions & 3 deletions Jenkinsfile_Subgraph_bellecour
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//Readme @ http://gitlab.iex.ec:30000/iexec/jenkins-library

@Library('global-jenkins-library@2.7.7') _
@Library('global-jenkins-library@2.8.1') _
deploySubGraph(
targetRemoteHost : 'azubgrpbp-thegraph-bellecour.public.az2.internal',
targetRemoteHostGraphNode : 'azubgrpbp-thegraph.public.az2.internal',
targetRemoteHostIPFS : 'ipfs-upload.v8-bellecour.iex.ec',
subgraphFolder: './',
subgraphFilename: 'subgraph.bellecour.yaml',
subgraphVersionLabel: 'v1.0.0-rc.1',
subgraphVersionLabel: 'v1.1.0',
subgraphLabel: 'bellecour/poco-v5'
)
11 changes: 11 additions & 0 deletions Jenkinsfile_Subgraph_bellecour_stagingv8
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//Readme @ http://gitlab.iex.ec:30000/iexec/jenkins-library

@Library('[email protected]') _
deploySubGraph(
targetRemoteHostGraphNode : 'azubgrpbx-thegraph-staging.public.az2.internal',
targetRemoteHostIPFS : 'ipfs-upload.stagingv8.iex.ec',
subgraphFolder: './',
subgraphFilename: 'subgraph.bellecour.yaml',
subgraphVersionLabel: 'v1.1.0',
subgraphLabel: 'bellecour/poco-v5'
)
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ A subgraph to explore the PoCo smarcontracts

[CHANGELOG](./CHANGELOG.md)

# Setup coverage⁠

> In order for Matchstick to check which handlers are being run, those handlers need to be exported from the test file.
Check how to export handlers with [Matchstick - Test Coverage documentation](https://thegraph.com/docs/en/subgraphs/developing/creating/unit-testing-framework/#test-coverage).

> [!NOTE]
> Since Matchstick code coverage is in very early stages, Matchstick cannot check for branch coverage, but rely on the assertion that a given handler has been called.

## local dev

run local services:
Expand Down
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(5 * MINUTES)
.withWaitStrategy(
'poco-subgraph-deployer-1',
Wait.forLogMessage(
'Deployed to http://graphnode:8000/subgraphs/name/test/poco/graphql',
),
);
await environment.up();
const secondsToWait = 10;
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');
});
});
2 changes: 2 additions & 0 deletions matchstick.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
testsFolder: test
manifestPath: subgraph.template.yaml
Loading

0 comments on commit 001b887

Please sign in to comment.