diff --git a/.gitignore b/.gitignore index 37c75ed..8f9dcd9 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ yarn.lock test/.bin subgraph.yaml subgraph.test.yaml +.env 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 } 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/itest/integration.test.ts b/itest/integration.test.ts index c9fd274..faae56d 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..`, ); diff --git a/package.json b/package.json index 80369c4..dd1a47f 100644 --- a/package.json +++ b/package.json @@ -9,10 +9,14 @@ "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: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", - "itest": "DEBUG=testcontainers:* mocha" + "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" }, "lint-staged": { "*.{js,ts}": [ 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" ] 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=