From 532851f81f1d4f00802f6c37a1876922f90e8048 Mon Sep 17 00:00:00 2001 From: Shunji Zhan Date: Tue, 16 Jul 2024 15:14:21 +0800 Subject: [PATCH] ci test works --- README.md | 32 +++++++++++++++----------------- docker-compose.yml | 37 +++++++++++++++++++++++++++++++------ package.json | 4 ++-- 3 files changed, 48 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 3d2718e..65089a7 100644 --- a/README.md +++ b/README.md @@ -574,39 +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 +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.test .env -yarn dev +yarn test ``` ## Production Config diff --git a/docker-compose.yml b/docker-compose.yml index 41a53f4..cbbbb69 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,17 +12,29 @@ services: ports: - 8000:8000 healthcheck: - test: "exit 0" - # FIXME: does not seem to work - # test: "curl --fail -X POST -H \"Content-Type: application/json\" http://localhost:8000 -d \"{\"id\": 1, \"jsonrpc\": \"2.0\", \"method\": \"system_health\", \"params\": []}\" || exit 1" + # 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 - start_period: 10s eth-rpc: container_name: eth-rpc image: acala/eth-rpc-adapter:2.8.7 - restart: always + restart: on-failure depends_on: node: condition: service_healthy @@ -32,4 +44,17 @@ services: - host.docker.internal:host-gateway environment: - ENDPOINT_URL=ws://node:8000 - command: yarn start \ No newline at end of file + 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 + + 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 286c93a..fe41eb5 100644 --- a/package.json +++ b/package.json @@ -11,12 +11,12 @@ "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:coverage": "COVERAGE=1 yarn test --coverage", "test:ci": "yarn start:test-stack; yarn test:coverage", - "relay": "ts-node src/scripts/manual-relay.ts", - "start:test-stack": "docker compose up" + "relay": "ts-node src/scripts/manual-relay.ts" }, "dependencies": { "@acala-network/api": "~6.0.4",