Skip to content

Commit

Permalink
integrate chopstick tests with CI (#68)
Browse files Browse the repository at this point in the history
* ci test

* ci test works
  • Loading branch information
shunjizhan authored Jul 17, 2024
1 parent 54b5814 commit f3abb6e
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 15 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
71 changes: 56 additions & 15 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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 🚀"
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit f3abb6e

Please sign in to comment.