Skip to content

Commit

Permalink
Merge branch 'fix-subgraph-local-test' into update-deps-20240822
Browse files Browse the repository at this point in the history
  • Loading branch information
hellwolf committed Aug 28, 2024
2 parents 42f9d2f + fbd7cf4 commit 0cc5f86
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 117 deletions.
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 @@ -47,7 +47,8 @@
"private": true,
"repository": "github:superfluid-finance/protocol-monorepo",
"resolutions": {
"mocha": "^10.2.0"
"mocha": "^10.2.0",
"cross-fetch": "^4.0.0"
},
"scripts": {
"prepare": "husky && npm run git-submodule:init",
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
22 changes: 1 addition & 21 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7829,22 +7829,7 @@ create-require@^1.1.0:
resolved "https://registry.yarnpkg.com/create-require/-/create-require-1.1.1.tgz#c1d7e8f1e5f6cfc9ff65f9cd352d37348756c333"
integrity sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==

cross-fetch@^2.1.0:
version "2.2.6"
resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-2.2.6.tgz#2ef0bb39a24ac034787965c457368a28730e220a"
integrity sha512-9JZz+vXCmfKUZ68zAptS7k4Nu8e2qcibe7WVZYps7sAgk5R8GYTc+T1WR0v1rlP9HxgARmOX1UTIJZFytajpNA==
dependencies:
node-fetch "^2.6.7"
whatwg-fetch "^2.0.4"

cross-fetch@^3.1.4, cross-fetch@^3.1.5:
version "3.1.5"
resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-3.1.5.tgz#e1389f44d9e7ba767907f7af8454787952ab534f"
integrity sha512-lvb1SBsI0Z7GDwmuid+mU3kWVBwTVUbe7S0H52yaaAdQOXq2YktTCZdlAcNKFzE6QtRz0snpw9bNiPeOIkkQvw==
dependencies:
node-fetch "2.6.7"

cross-fetch@^4.0.0:
cross-fetch@^2.1.0, cross-fetch@^3.1.4, cross-fetch@^3.1.5, cross-fetch@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-4.0.0.tgz#f037aef1580bb3a1a35164ea2a848ba81b445983"
integrity sha512-e4a5N8lVvuLgAWgnCrLr2PP0YyDOTHa9H/Rj54dirp61qXnNq46m82bRhNqIA5VccJtWBvPTFRV3TtvHUKPB1g==
Expand Down Expand Up @@ -20134,11 +20119,6 @@ websocket@^1.0.32:
utf-8-validate "^5.0.2"
yaeti "^0.0.6"

whatwg-fetch@^2.0.4:
version "2.0.4"
resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-2.0.4.tgz#dde6a5df315f9d39991aa17621853d720b85566f"
integrity sha512-dcQ1GWpOD/eEQ97k66aiEVpNnapVj90/+R+SXTPYGHpYBBypfKJEQjLrvMZ7YXbKm21gXd4NcuxUTjiv1YtLng==

whatwg-mimetype@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/whatwg-mimetype/-/whatwg-mimetype-3.0.0.tgz#5fa1a7623867ff1af6ca3dc72ad6b8a4208beba7"
Expand Down

0 comments on commit 0cc5f86

Please sign in to comment.