Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workflow: tweak test-local-subgraph #2013

Merged
merged 20 commits into from
Aug 29, 2024
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
5 changes: 2 additions & 3 deletions .github/workflows/call.test-ethereum-contracts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,10 @@ jobs:
- name: Set cache key prefix
id: set-cache-key-prefix
run: |
node_version=${{ matrix.node-version }}
if [ "${{ inputs.run-coverage-tests }}" == false ]; then
v=ethereum-contracts-test-${node_version}-
v=ethereum-contracts-${{ env.DEV_SHELL_NAME }}-test-
else
v=ethereum-contracts-coverage-${node_version}-
v=ethereum-contracts-${{ env.DEV_SHELL_NAME }}-coverage-
fi
echo "cache_key_prefix=$v" >> "$GITHUB_OUTPUT"
shell: bash
Expand Down
47 changes: 18 additions & 29 deletions .github/workflows/call.test-local-subgraph.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ on:
workflow_call:

env:
# FIXME: subgraph test fails with node20
DEV_SHELL_NAME: ci-node18
DEV_SHELL_NAME: ci-node20
ethereum-contracts-working-directory: ./packages/ethereum-contracts
sdk-core-working-directory: ./packages/sdk-core
subgraph-working-directory: ./packages/subgraph

jobs:
subgraph-unit-tests:
name: Run subgraph unit tests
runs-on: ubuntu-latest

env:
subgraph-working-directory: ./packages/subgraph

defaults:
run:
shell: nix develop .#${{ env.DEV_SHELL_NAME }} -c bash -xe {0}
Expand All @@ -27,7 +26,7 @@ jobs:
uses: ./.github/actions/setup-workflow-base
with:
package-name: subgraph
cache-key-prefix: subgraph-unit-tests-
cache-key-prefix: subgraph-${{ env.DEV_SHELL_NAME }}-unit-tests-
dev-shell-name: ${{ env.DEV_SHELL_NAME }}

- name: Install dependencies
Expand All @@ -42,7 +41,7 @@ jobs:
run: |
yarn lint
yarn build
working-directory: ./packages/ethereum-contracts
working-directory: ${{ env.ethereum-contracts-working-directory }}

- name: Run unit tests
if: steps.base.outputs.cache-hit != 'true'
Expand All @@ -54,10 +53,6 @@ jobs:

runs-on: ubuntu-latest

env:
subgraph-working-directory: ./packages/subgraph
sdk-core-working-directory: ./packages/sdk-core

defaults:
run:
shell: nix develop .#${{ env.DEV_SHELL_NAME }} -c bash -xe {0}
Expand All @@ -70,7 +65,7 @@ jobs:
uses: ./.github/actions/setup-workflow-base
with:
package-name: subgraph
cache-key-prefix: subgraph-integration-tests-
cache-key-prefix: subgraph-${{ env.DEV_SHELL_NAME }}-integration-tests-
dev-shell-name: ${{ env.DEV_SHELL_NAME }}

- name: Install dependencies
Expand All @@ -80,41 +75,35 @@ jobs:
- name: Build contracts
if: steps.base.outputs.cache-hit != 'true'
run: yarn build
working-directory: ./packages/ethereum-contracts

- name: Start hardhat node
if: steps.base.outputs.cache-hit != 'true'
run: ./tasks/startHardhatNode.sh start
working-directory: ${{ env.sdk-core-working-directory }}
working-directory: ${{ env.ethereum-contracts-working-directory }}

- name: Build SDK core
if: steps.base.outputs.cache-hit != 'true'
# build sdk-core because subgraph tests use sdk-core
run: yarn build
working-directory: ${{ env.sdk-core-working-directory }}

- name: Start hardhat node
if: steps.base.outputs.cache-hit != 'true'
run: ./tasks/startHardhatNode.sh start
working-directory: ${{ env.sdk-core-working-directory }}

- name: Deploy framework and tokens
if: steps.base.outputs.cache-hit != 'true'
run: npx hardhat run dev-scripts/run-deploy-contracts-and-token.js --network localhost
working-directory: ./packages/ethereum-contracts
working-directory: ${{ env.ethereum-contracts-working-directory }}

- name: Prepare files for local testing
if: steps.base.outputs.cache-hit != 'true'
run: yarn prepare-local
working-directory: ${{ env.subgraph-working-directory }}

- name: Run setup-graph-node
if: steps.base.outputs.cache-hit != 'true'
run: |
chmod +x ./tasks/setup-graph-node.sh
./tasks/setup-graph-node.sh
working-directory: ${{ env.subgraph-working-directory }}

- name: Docker compose
- name: Setup graph node
if: steps.base.outputs.cache-hit != 'true'
run: |
docker rm subgraph_graph-node_1 || true
docker compose up &
./tasks/setup-graph-node.sh &
# wait for it to warm up
sleep 30
working-directory: ${{ env.subgraph-working-directory }}

- name: Run subgraph integration test suite
Expand Down
42 changes: 15 additions & 27 deletions .github/workflows/call.test-sdk-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ jobs:
id: set-matrix
run: |
if [ "${{ inputs.run-coverage-tests }}" == "true" ];then
echo "matrix={\"node-version\": [18]}" >> "$GITHUB_OUTPUT"
echo "matrix={\"node-version\": [20]}" >> "$GITHUB_OUTPUT"
else
# FIXME: subgraph test fails with node20
echo "matrix={\"node-version\": [18]}" >> "$GITHUB_OUTPUT"
echo "matrix={\"node-version\": [18, 20]}" >> "$GITHUB_OUTPUT"
fi

test-sdk-core:
Expand Down Expand Up @@ -63,11 +62,10 @@ jobs:
- name: Set cache key prefix
id: set-cache-key-prefix
run: |
node_version=${{ matrix.node-version }}
if [ "${{ inputs.run-coverage-tests }}" == false ]; then
v=sdk-core-test-${node_version}-
v=sdk-core-${{ env.DEV_SHELL_NAME }}-test-
else
v=sdk-core-coverage-${node_version}-
v=sdk-core-${{ env.DEV_SHELL_NAME }}-coverage-
fi
echo "cache_key_prefix=$v" >> "$GITHUB_OUTPUT"
shell: bash
Expand All @@ -87,19 +85,12 @@ jobs:
npx tsc --version
npx hardhat --version

- name: Lint and build essentials
- name: Build contracts
if: steps.base.outputs.cache-hit != 'true'
run: |
yarn lint
yarn build
working-directory: ${{ env.ethereum-contracts-working-directory }}

- name: Start hardhat node
if: steps.base.outputs.cache-hit != 'true'
run: |
./tasks/startHardhatNode.sh start
working-directory: ${{ env.sdk-core-working-directory }}

- name: Build SDK Core
if: steps.base.outputs.cache-hit != 'true'
# build sdk-core because of auto linking to dependency
Expand All @@ -108,7 +99,12 @@ jobs:
yarn build
working-directory: ${{ env.sdk-core-working-directory }}

- name: Deploy Framework and Tokens
- name: Start hardhat node
if: steps.base.outputs.cache-hit != 'true'
run: ./tasks/startHardhatNode.sh start
working-directory: ${{ env.sdk-core-working-directory }}

- name: Deploy framework and tokens
if: steps.base.outputs.cache-hit != 'true'
run: npx hardhat run dev-scripts/run-deploy-contracts-and-token.js --network localhost
working-directory: ${{ env.ethereum-contracts-working-directory }}
Expand All @@ -118,26 +114,18 @@ jobs:
run: yarn prepare-local
working-directory: ${{ env.subgraph-working-directory }}

- name: Run setup-graph-node
if: steps.base.outputs.cache-hit != 'true'
run: |
chmod +x ./tasks/setup-graph-node.sh
./tasks/setup-graph-node.sh
working-directory: ${{ env.subgraph-working-directory }}

- name: Docker compose
- name: Setup graph node
if: steps.base.outputs.cache-hit != 'true'
run: |
docker rm subgraph_graph-node_1 || true
docker compose up &
./tasks/setup-graph-node.sh &
# wait for it to warm up
sleep 30
working-directory: ${{ env.subgraph-working-directory }}

- name: Build and deploy local subgraph
if: steps.base.outputs.cache-hit != 'true'
run: |
yarn build-and-deploy-local
# artificial slow down to give the subgraph time to sync
sleep 30
working-directory: ${{ env.subgraph-working-directory }}

- name: Run test suite
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,11 @@ jobs:
run: yarn prepare-local
working-directory: ./packages/subgraph

- name: "Run setup-graph-node"
run: |
chmod +x ./tasks/setup-graph-node.sh
./tasks/setup-graph-node.sh
working-directory: ./packages/subgraph

- name: "Docker compose"
run: |
docker rm subgraph_graph-node_1 || true
docker compose up &
./tasks/setup-graph-node.sh &
# wait 5 seconds for it to warm up
sleep 5
working-directory: ./packages/subgraph

- name: "Prepare and Deploy Local Subgraph"
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
"web3": "^1.10.4"
},
"resolutions": {
"mocha": "^10.2.0"
"mocha": "^10.2.0",
"cross-fetch": "^4.0.0"
},
"workspaces": {
"packages": [
Expand Down
5 changes: 4 additions & 1 deletion packages/subgraph/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@
includedFiles = [
./package.json
./config
./matchstick.yaml
./schema.graphql
./tsconfig.json
./types
./src
./scripts
# for testing
./docker-compose.yml
./matchstick.yaml
./tests
./tasks
];
};
}
5 changes: 1 addition & 4 deletions packages/subgraph/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: "3"
services:
graph-node:
image: graphprotocol/graph-node:v0.35.0
Expand All @@ -11,15 +10,13 @@ services:
depends_on:
- ipfs
- postgres
extra_hosts:
- host.docker.internal:host-gateway
environment:
postgres_host: postgres
postgres_user: graph-node
postgres_pass: let-me-in
postgres_db: graph-node
ipfs: "ipfs:5001"
ethereum: "mainnet:http://host.docker.internal:8545"
ethereum: "mainnet:http://${DOCKER_HOST_IP}:8545"
GRAPH_LOG: info
ipfs:
image: ipfs/go-ipfs:v0.4.23
Expand Down
30 changes: 7 additions & 23 deletions packages/subgraph/tasks/setup-graph-node.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

set -e
set -ex

if ! which docker >/dev/null 2>&1 ; then
echo "Please install 'docker' first"
Expand All @@ -17,26 +17,10 @@ if ! which jq >/dev/null 2>&1; then
exit 1
fi

# Create the graph-node container
docker compose up --no-start graph-node
# this creates the bridged network for the composed ervices (network id: subgraph_default)
docker compose up --no-start
# we then extract the gateway ip address and export it
DOCKER_HOST_IP=$(docker network inspect subgraph_default | jq -r '.[0].IPAM.Config[].Gateway')

# Start graph-node so we can inspect it
docker compose start graph-node

# Identify the container ID
CONTAINER_ID=$(docker container ls | grep graph-node | cut -d' ' -f1)

# Inspect the container to identify the host IP address
HOST_IP=$(docker inspect "$CONTAINER_ID" | jq -r .[0].NetworkSettings.Networks[].Gateway)

echo "Host IP: $HOST_IP"

# Inject the host IP into docker-compose.yml
sed -i -e "s/host.docker.internal/$HOST_IP/g" docker-compose.yml

function stop_graph_node {
# Ensure graph-node is stopped
docker compose stop graph-node
}

trap stop_graph_node EXIT
# docker compose with required variables
DOCKER_HOST_IP=$DOCKER_HOST_IP docker compose up
Loading
Loading