From f3abb6e7da6bd43295169798e2f1a576a3837917 Mon Sep 17 00:00:00 2001 From: Shunji Zhan Date: Wed, 17 Jul 2024 10:30:40 +0800 Subject: [PATCH] integrate chopstick tests with CI (#68) * ci test * ci test works --- .github/workflows/test.yml | 2 +- README.md | 36 ++++++++----------- docker-compose.yml | 71 ++++++++++++++++++++++++++++++-------- package.json | 6 ++-- 4 files changed, 74 insertions(+), 41 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cefc84b..ab7d191 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,7 +27,7 @@ jobs: run: cp .env.test .env - name: run tests - run: yarn test:coverage + run: yarn test:ci - name: upload coverage reports uses: codecov/codecov-action@v3 diff --git a/README.md b/README.md index d1dea2e..65089a7 100644 --- a/README.md +++ b/README.md @@ -574,43 +574,37 @@ A complete working flow can be found in [routing e2e tests](./src/__tests__/rout 4) fetch VAA and redeem on the target evm chain ## Tests -### with coverage report -- run tests and generate coverage data +### test setup +use the test env file ``` -yarn test:coverage +mv .env.test .env ``` -show coverage report in GUI +start a local test stack ``` -yarn vite preview --outDir ./coverage/ +yarn start:test-stack ``` -### with separate relayer (no coverage report) -first start a relayer: `yarn dev` - +### run tests with coverage report +- run tests and generate coverage data ``` -yarn test:shouldRelay -yarn test:relay - -yarn test:shouldRoute -yarn test:route +yarn test:coverage ``` -### test setup -first start a local acala fork +show coverage report in GUI ``` -npx @acala-network/chopsticks@latest -c src/__tests__/configs/acala.yml -p 8000 +yarn vite preview --outDir ./coverage/ ``` -start an rpc adapter +### run tests with separate relayer (no coverage report) +first start a local relayer ``` -npx @acala-network/eth-rpc-adapter -e ws://localhost:8000 +yarn dev ``` -start the relayer +run tests ``` -mv .env.homa .env -yarn dev +yarn test ``` ## Production Config diff --git a/docker-compose.yml b/docker-compose.yml index b25a908..cbbbb69 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,19 +1,60 @@ +version: '3.8' + services: - relayer: - build: - context: . - dockerfile: Dockerfile - target: relayer + node: + container_name: node + image: oven/bun:1 + working_dir: /app + volumes: + - ./src/__tests__/configs/acala.yml:/app/acala.yml + command: + bunx @acala-network/chopsticks@latest -c /app/acala.yml ports: - - 3111:3111 - # - 3112:3112 - environment: - - KARURA_ETH_RPC=https://eth-rpc-karura-testnet.aca-staging.network - - KARURA_PRIVATE_KEY=efb03e3f4fd8b3d7f9b14de6c6fb95044e2321d6bcb9dfe287ba987920254044 + - 8000:8000 + healthcheck: + # bun image doesn't have wget or curl ... + test: | + bun --eval ' + fetch("http://localhost:8000", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ id: 1, jsonrpc: "2.0", method: "system_health", params: [] }) + }) + .then(res => res.json()) + .then(data => { + const exitCode = data.result ? 0 : 1; + process.exit(exitCode) + }) + .catch(() => process.exit(1)); + ' + interval: 2s + timeout: 5s + retries: 100 - - KARURA_ETH_RPC=https://eth-rpc-acala-testnet.aca-staging.network - - ACALA_PRIVATE_KEY=efb03e3f4fd8b3d7f9b14de6c6fb95044e2321d6bcb9dfe287ba987920254044 + eth-rpc: + container_name: eth-rpc + image: acala/eth-rpc-adapter:2.8.7 + restart: on-failure + depends_on: + node: + condition: service_healthy + ports: + - 8545:8545 + extra_hosts: + - host.docker.internal:host-gateway + environment: + - ENDPOINT_URL=ws://node:8000 + healthcheck: + test: | + wget -q -O- --post-data='{"id": 1, "jsonrpc": "2.0", "method": "eth_chainId", "params": []}' --header='Content-Type: application/json' http://localhost:8545 || exit 1 + interval: 2s + timeout: 5s + retries: 100 - - PORT=3111 - - TESTNET_MODE=1 - restart: always + test-stack-ready: + image: alpine:latest + restart: on-failure + depends_on: + eth-rpc: + condition: service_healthy + command: echo "test stack ready 🚀" \ No newline at end of file diff --git a/package.json b/package.json index c63a6cb..fe41eb5 100644 --- a/package.json +++ b/package.json @@ -11,13 +11,11 @@ "scripts": { "build": "tsc", "start": "node dist/index.js", + "start:test-stack": "docker compose up -d", "dev": "ts-node-dev --respawn src/index.ts | pino-pretty --singleLine --colorize --ignore time,hostname", "test": "vitest src/__tests__/*.test.ts --singleThread", - "test:relay": "vitest src/__tests__/relay.test.ts", - "test:shouldRelay": "vitest src/__tests__/shouldRelay.test.ts", - "test:shouldRoute": "vitest src/__tests__/shouldRoute.test.ts", - "test:route": "vitest src/__tests__/route.test.ts", "test:coverage": "COVERAGE=1 yarn test --coverage", + "test:ci": "yarn start:test-stack; yarn test:coverage", "relay": "ts-node src/scripts/manual-relay.ts" }, "dependencies": {