From 306669785448b7bf2d62ae82efac72037e97b506 Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Tue, 26 Nov 2024 16:27:28 +0100 Subject: [PATCH 01/11] deploy local graphnode with setting a particular starting block --- .gitignore | 1 + docker/Dockerfile | 5 ++- generate_subgraph_file.sh | 9 +++- package.json | 8 ++-- test-stack/docker-compose.yml | 79 +++++++++++++++++++++++++++++++++++ test-stack/template.env | 3 ++ 6 files changed, 100 insertions(+), 5 deletions(-) create mode 100644 test-stack/docker-compose.yml create mode 100644 test-stack/template.env diff --git a/.gitignore b/.gitignore index 37c75ed..842f5db 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ yarn.lock test/.bin subgraph.yaml subgraph.test.yaml +.env \ No newline at end of file diff --git a/docker/Dockerfile b/docker/Dockerfile index 3621e9a..79e4f08 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,9 +1,12 @@ -FROM node:22 +FROM node:22-alpine +RUN apk --no-cache add jq bash WORKDIR /iexec-poco-subgraph COPY package*.json . RUN npm ci COPY schema.graphql . COPY subgraph.template.yaml . COPY networks.json . +COPY config.json . +COPY generate_subgraph_file.sh . COPY src src ENTRYPOINT [ "npm", "run", "deploy:all" ] diff --git a/generate_subgraph_file.sh b/generate_subgraph_file.sh index 8e1e406..babc4f6 100755 --- a/generate_subgraph_file.sh +++ b/generate_subgraph_file.sh @@ -15,7 +15,7 @@ generate_yaml() { local network=$1 local config_file="config.json" local template_file="subgraph.template.yaml" - local output_file="subgraph.${network}.yaml" + local output_file="subgraph.yaml" # Read values from config.json local start_block=$(jq -r ".${network}.START_BLOCK" ${config_file}) @@ -25,6 +25,13 @@ generate_yaml() { local dataset_registry_address=$(jq -r ".${network}.DATATSET_REGISTRY_ADDRESS" ${config_file}) local workerpool_registry_address=$(jq -r ".${network}.WORKERPOOL_REGISTRY_ADDRESS" ${config_file}) + if [ -n "$START_BLOCK" ]; then + echo "START_BLOCK is set to $START_BLOCK" + start_block=$START_BLOCK + else + echo "START_BLOCK is not set. Using start_block from config.json: $start_block" + fi + # Replace placeholders in the template and create the output file sed -e "s/#NETWORK_NAME#/network: ${network}/g" \ -e "s/#START_BLOCK#/startBlock: ${start_block}/g" \ diff --git a/package.json b/package.json index 80369c4..e384f87 100644 --- a/package.json +++ b/package.json @@ -8,11 +8,13 @@ "codegen": "graph codegen subgraph.template.yaml", "test": "npm run codegen && graph test", "test-docker": "npm run codegen && docker run -it --rm -v $(pwd):/matchstick/subgraph rainprotocol/matchstick:main", - "build": "npm run codegen && cp subgraph.template.yaml subgraph.yaml && graph build --network ${NETWORK_NAME:-bellecour}", + "build": "npm run codegen && cp subgraph.template.yaml subgraph.yaml && graph build --network ${NETWORK_NAME:-bellecour} && ./generate_subgraph_file.sh ${NETWORK_NAME:-bellecour}", "create": "graph create ${NETWORK_NAME:-bellecour}/poco --node ${GRAPHNODE_URL:-http://localhost:8020}", "deploy": "graph deploy ${NETWORK_NAME:-bellecour}/poco --node ${GRAPHNODE_URL:-http://localhost:8020} --ipfs ${IPFS_URL:-http://localhost:5001} --version-label ${VERSION_LABEL:-bellecour/poco-v5}", "deploy:all": "npm run build && npm run create && npm run deploy", - "itest": "DEBUG=testcontainers:* mocha" + "itest": "DEBUG=testcontainers:* mocha", + "stop-test-stack": "cd test-stack && docker compose down --remove-orphans --volumes", + "start-test-stack": "npm run stop-test-stack && cd test-stack && docker compose build && docker compose up -d" }, "lint-staged": { "*.{js,ts}": [ @@ -44,4 +46,4 @@ "@iexec/poco": "5.3.0", "@iexec/solidity": "0.1.0" } -} +} \ No newline at end of file diff --git a/test-stack/docker-compose.yml b/test-stack/docker-compose.yml new file mode 100644 index 0000000..e6eba28 --- /dev/null +++ b/test-stack/docker-compose.yml @@ -0,0 +1,79 @@ +services: + graphnode-postgres: + image: postgres:16.4 + restart: unless-stopped + command: + - "postgres" + - "-cshared_preload_libraries=pg_stat_statements" + expose: + - 5432 + environment: + POSTGRES_USER: graphnode + POSTGRES_PASSWORD: password + POSTGRES_DB: graphnode-db + POSTGRES_INITDB_ARGS: "-E UTF8 --locale=C" + healthcheck: + test: pg_isready -U graphnode -d graphnode-db + interval: 10s + timeout: 5s + retries: 3 + start_period: 30s + + ipfs: + restart: unless-stopped + image: ipfs/go-ipfs:v0.22.0 + expose: + - 8080 + - 5001 + ports: + - 8080:8080 + - 5001:5001 + + graphnode: + image: graphprotocol/graph-node:v0.35.1 + restart: unless-stopped + expose: + - 8000 + - 8020 + ports: + # GraphQL HTTP + - 8000:8000 + # GraphQL WS + # - 8001:8001 + # admin RPC + - 8020:8020 + # metrics + # - 8040:8040 + environment: + postgres_host: graphnode-postgres + postgres_port: 5432 + postgres_user: graphnode + postgres_pass: password + postgres_db: graphnode-db + ipfs: ipfs:5001 + ethereum: ${NETWORK_NAME}:${BELLECOUR_NODE_URL} + GRAPH_ETHEREUM_GENESIS_BLOCK_NUMBER: $START_BLOCK + depends_on: + graphnode-postgres: + condition: service_healthy + ipfs: + condition: service_started + healthcheck: + test: netcat -w 1 0.0.0.0 8020 + interval: 10s + timeout: 5s + retries: 5 + start_period: 30s + + poco-subgraph-deployer: + build: + context: .. + dockerfile: docker/Dockerfile + environment: + GRAPHNODE_URL: http://graphnode:8020 + IPFS_URL: http://ipfs:5001 + NETWORK_NAME: $NETWORK_NAME + START_BLOCK: $START_BLOCK + depends_on: + graphnode: + condition: service_healthy diff --git a/test-stack/template.env b/test-stack/template.env new file mode 100644 index 0000000..c426105 --- /dev/null +++ b/test-stack/template.env @@ -0,0 +1,3 @@ +BELLECOUR_NODE_URL= +START_BLOCK= +NETWORK_NAME= From 779569a3447e17d1527ce9d5fa7b2ec116f16d4a Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Wed, 27 Nov 2024 11:36:35 +0100 Subject: [PATCH 02/11] update timeout --- .mocharc.json | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.mocharc.json b/.mocharc.json index 1dff619..0e5c939 100644 --- a/.mocharc.json +++ b/.mocharc.json @@ -1,6 +1,10 @@ { - "extension": ["ts"], + "extension": [ + "ts" + ], "spec": "itest/**/*.ts", - "require": ["ts-node/register"], - "timeout": 600000 -} + "require": [ + "ts-node/register" + ], + "timeout": 1000000 +} \ No newline at end of file From 86f747d151b6712f955c01587647110d5c511bec Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Wed, 27 Nov 2024 12:40:32 +0100 Subject: [PATCH 03/11] test its --- itest/integration.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/itest/integration.test.ts b/itest/integration.test.ts index c9fd274..88347bb 100644 --- a/itest/integration.test.ts +++ b/itest/integration.test.ts @@ -47,6 +47,7 @@ describe('Integration tests', () => { } `), }); + console.log('result =>', result); const protocol = result.data.protocol; equal(protocol.id, 'iExec'); equal(protocol.tvl, '0.02025'); From e4a0c39c7b33972db164c7fd3498edd3d7cbc9dd Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Wed, 27 Nov 2024 14:53:26 +0100 Subject: [PATCH 04/11] separate docker local test and it test --- docker/Dockerfile | 7 ++----- package.json | 4 +++- test-stack/Dockerfile | 12 ++++++++++++ 3 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 test-stack/Dockerfile diff --git a/docker/Dockerfile b/docker/Dockerfile index 79e4f08..39204f6 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,12 +1,9 @@ -FROM node:22-alpine -RUN apk --no-cache add jq bash +FROM node:22 WORKDIR /iexec-poco-subgraph COPY package*.json . RUN npm ci COPY schema.graphql . COPY subgraph.template.yaml . COPY networks.json . -COPY config.json . -COPY generate_subgraph_file.sh . COPY src src -ENTRYPOINT [ "npm", "run", "deploy:all" ] +ENTRYPOINT [ "npm", "run", "deploy:all" ] \ No newline at end of file diff --git a/package.json b/package.json index e384f87..ed22888 100644 --- a/package.json +++ b/package.json @@ -8,10 +8,12 @@ "codegen": "graph codegen subgraph.template.yaml", "test": "npm run codegen && graph test", "test-docker": "npm run codegen && docker run -it --rm -v $(pwd):/matchstick/subgraph rainprotocol/matchstick:main", - "build": "npm run codegen && cp subgraph.template.yaml subgraph.yaml && graph build --network ${NETWORK_NAME:-bellecour} && ./generate_subgraph_file.sh ${NETWORK_NAME:-bellecour}", + "build": "npm run codegen && cp subgraph.template.yaml subgraph.yaml && graph build --network ${NETWORK_NAME:-bellecour}", + "build:local-test": "npm run codegen && cp subgraph.template.yaml subgraph.yaml && graph build --network ${NETWORK_NAME:-bellecour} && ./generate_subgraph_file.sh ${NETWORK_NAME:-bellecour}", "create": "graph create ${NETWORK_NAME:-bellecour}/poco --node ${GRAPHNODE_URL:-http://localhost:8020}", "deploy": "graph deploy ${NETWORK_NAME:-bellecour}/poco --node ${GRAPHNODE_URL:-http://localhost:8020} --ipfs ${IPFS_URL:-http://localhost:5001} --version-label ${VERSION_LABEL:-bellecour/poco-v5}", "deploy:all": "npm run build && npm run create && npm run deploy", + "all-local-test": "npm run build:local-test && npm run create && npm run deploy", "itest": "DEBUG=testcontainers:* mocha", "stop-test-stack": "cd test-stack && docker compose down --remove-orphans --volumes", "start-test-stack": "npm run stop-test-stack && cd test-stack && docker compose build && docker compose up -d" diff --git a/test-stack/Dockerfile b/test-stack/Dockerfile new file mode 100644 index 0000000..7a9009a --- /dev/null +++ b/test-stack/Dockerfile @@ -0,0 +1,12 @@ +FROM node:22-alpine +RUN apk --no-cache add jq bash +WORKDIR /iexec-poco-subgraph +COPY package*.json . +RUN npm ci +COPY schema.graphql . +COPY subgraph.template.yaml . +COPY networks.json . +COPY config.json . +COPY generate_subgraph_file.sh . +COPY src src +ENTRYPOINT [ "npm", "run", "deploy:all-local-test" ] From e83569af4df46592ca0c6918fdb16cc676cb6dcb Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Wed, 27 Nov 2024 15:09:37 +0100 Subject: [PATCH 05/11] get back all vesion --- .mocharc.json | 12 ++++-------- docker/Dockerfile | 2 +- package.json | 2 +- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/.mocharc.json b/.mocharc.json index 0e5c939..1dff619 100644 --- a/.mocharc.json +++ b/.mocharc.json @@ -1,10 +1,6 @@ { - "extension": [ - "ts" - ], + "extension": ["ts"], "spec": "itest/**/*.ts", - "require": [ - "ts-node/register" - ], - "timeout": 1000000 -} \ No newline at end of file + "require": ["ts-node/register"], + "timeout": 600000 +} diff --git a/docker/Dockerfile b/docker/Dockerfile index 39204f6..3621e9a 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -6,4 +6,4 @@ COPY schema.graphql . COPY subgraph.template.yaml . COPY networks.json . COPY src src -ENTRYPOINT [ "npm", "run", "deploy:all" ] \ No newline at end of file +ENTRYPOINT [ "npm", "run", "deploy:all" ] diff --git a/package.json b/package.json index ed22888..bcebb0a 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "create": "graph create ${NETWORK_NAME:-bellecour}/poco --node ${GRAPHNODE_URL:-http://localhost:8020}", "deploy": "graph deploy ${NETWORK_NAME:-bellecour}/poco --node ${GRAPHNODE_URL:-http://localhost:8020} --ipfs ${IPFS_URL:-http://localhost:5001} --version-label ${VERSION_LABEL:-bellecour/poco-v5}", "deploy:all": "npm run build && npm run create && npm run deploy", - "all-local-test": "npm run build:local-test && npm run create && npm run deploy", + "deploy:all-local-test": "npm run build:local-test && npm run create && npm run deploy", "itest": "DEBUG=testcontainers:* mocha", "stop-test-stack": "cd test-stack && docker compose down --remove-orphans --volumes", "start-test-stack": "npm run stop-test-stack && cd test-stack && docker compose build && docker compose up -d" From bf31ccccee20d8b1f9f7bf0db5e8f806aaa4c5a8 Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Wed, 27 Nov 2024 15:14:41 +0100 Subject: [PATCH 06/11] add end of file line --- .gitignore | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 842f5db..8f9dcd9 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,4 @@ yarn.lock test/.bin subgraph.yaml subgraph.test.yaml -.env \ No newline at end of file +.env diff --git a/package.json b/package.json index bcebb0a..dd1a47f 100644 --- a/package.json +++ b/package.json @@ -48,4 +48,4 @@ "@iexec/poco": "5.3.0", "@iexec/solidity": "0.1.0" } -} \ No newline at end of file +} From 909e8697085c2550b333a5a5347c7831f15b5574 Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Wed, 27 Nov 2024 15:24:51 +0100 Subject: [PATCH 07/11] update timeout --- .mocharc.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.mocharc.json b/.mocharc.json index 1dff619..1b92e08 100644 --- a/.mocharc.json +++ b/.mocharc.json @@ -2,5 +2,5 @@ "extension": ["ts"], "spec": "itest/**/*.ts", "require": ["ts-node/register"], - "timeout": 600000 + "timeout": 1000000 } From f38a77bceaea30e1e73814bf38ff03f83e7f2f98 Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Wed, 27 Nov 2024 15:41:55 +0100 Subject: [PATCH 08/11] update waiting seconds --- itest/integration.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/itest/integration.test.ts b/itest/integration.test.ts index 88347bb..6123710 100644 --- a/itest/integration.test.ts +++ b/itest/integration.test.ts @@ -27,7 +27,7 @@ describe('Integration tests', () => { ), ); await environment.up(); - const secondsToWait = 5; + const secondsToWait = 10; console.log( `Waiting ${secondsToWait}s for graphnode to ingest a few blocks before querying it..`, ); From ff7c1a7fac5bf6f24adec3e4658566f192269b8c Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Wed, 27 Nov 2024 15:53:44 +0100 Subject: [PATCH 09/11] remve console log --- itest/integration.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/itest/integration.test.ts b/itest/integration.test.ts index 6123710..bb923a4 100644 --- a/itest/integration.test.ts +++ b/itest/integration.test.ts @@ -27,7 +27,6 @@ describe('Integration tests', () => { ), ); await environment.up(); - const secondsToWait = 10; console.log( `Waiting ${secondsToWait}s for graphnode to ingest a few blocks before querying it..`, ); From b4582d42a2a8d5d3560bb3d0301231e13d78c4b8 Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Wed, 27 Nov 2024 16:00:53 +0100 Subject: [PATCH 10/11] re-add seconds --- itest/integration.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/itest/integration.test.ts b/itest/integration.test.ts index bb923a4..6123710 100644 --- a/itest/integration.test.ts +++ b/itest/integration.test.ts @@ -27,6 +27,7 @@ describe('Integration tests', () => { ), ); await environment.up(); + const secondsToWait = 10; console.log( `Waiting ${secondsToWait}s for graphnode to ingest a few blocks before querying it..`, ); From 7cf21ad48ea713c7d86f4b5d99fd8dadef6654cc Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Wed, 27 Nov 2024 16:17:06 +0100 Subject: [PATCH 11/11] remove console log --- itest/integration.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/itest/integration.test.ts b/itest/integration.test.ts index 6123710..faae56d 100644 --- a/itest/integration.test.ts +++ b/itest/integration.test.ts @@ -47,7 +47,6 @@ describe('Integration tests', () => { } `), }); - console.log('result =>', result); const protocol = result.data.protocol; equal(protocol.id, 'iExec'); equal(protocol.tvl, '0.02025');