Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
shunjizhan committed Sep 19, 2024
2 parents 7fde062 + 0a51269 commit fcee23c
Show file tree
Hide file tree
Showing 15 changed files with 1,473 additions and 311 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ jobs:
run: yarn test:ci

- name: upload coverage reports
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
# files: ./coverage/lcov.info
fail_ci_if_error: true


9 changes: 9 additions & 0 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extension": [".ts"],
"include": ["src/**/*.ts"],
"exclude": ["**/*.test.ts"],
"reporter": ["html", "text", "lcov"],
"sourceMap": true,
"instrument": true,
"require": ["ts-node/register"]
}
19 changes: 19 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
coverage:
status:
project:
default:
target: auto
threshold: 0%
base: auto
patch:
default:
target: auto
threshold: 0%
base: auto

comment:
layout: "reach, diff, flags, files"
behavior: default
require_changes: false
require_base: false
require_head: false
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: '3.8'
services:
node:
container_name: node
image: oven/bun:1
image: oven/bun:1.1.26
working_dir: /app
volumes:
- ./src/__tests__/configs/acala.yml:/app/acala.yml
Expand Down
18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
"repository": "https://github.com/AcalaNetwork/wormhole-relayer/",
"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,ip",
"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": "node dist/index.js",
"start:coverage": "pm2 start --name relayer 'nyc node -r ts-node/register src/index.ts' && ./scripts/health-check.sh",
"stop:coverage": "pm2 stop relayer && pm2 delete relayer",
"start:test-infra": "docker compose up",
"test": "vitest src/__tests__/*.test.ts --singleThread --run",
"test:coverage": "yarn start:coverage && yarn test && yarn stop:coverage",
"test:ci": "yarn start:test-infra -d; yarn test:coverage",
"clean": "rm -rf coverage .nyc_output dist/"
},
"dependencies": {
"@acala-network/api": "~6.0.4",
Expand Down Expand Up @@ -48,7 +50,6 @@
"@types/long": "^4.0.1",
"@types/node": "^16.6.1",
"@types/react": "^17.0.19",
"@types/supertest": "^2.0.12",
"@typescript-eslint/eslint-plugin": "^5.11.0",
"@typescript-eslint/parser": "^5.11.0",
"@vitest/coverage-v8": "^0.33.0",
Expand All @@ -57,9 +58,10 @@
"eslint": "^8.9.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-sort-imports-es6-autofix": "^0.6.0",
"nyc": "^17.0.0",
"pino-pretty": "^10.0.0",
"pm2": "^5.4.2",
"prettier": "^2.3.2",
"supertest": "^6.3.3",
"ts-node": "^10.5.0",
"ts-node-dev": "^2.0.0",
"typescript": "^4.3.5",
Expand Down
22 changes: 22 additions & 0 deletions scripts/health-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

HEALTH_CHECK_URL="http://localhost:3111/health"
MAX_ATTEMPTS=60
INTERVAL=1

attempt=0
while [ $attempt -lt $MAX_ATTEMPTS ]; do
response=$(curl -s -o /dev/null -w "%{http_code}" $HEALTH_CHECK_URL)
if [ $response -eq 200 ]; then
echo "🚀 relayer ready in $attempt seconds"
exit 0
fi

echo "waiting for relayer starting up... ($attempt\s)"

sleep $INTERVAL
attempt=$((attempt+1))
done

echo "❌ relayer failed to start in $MAX_ATTEMPTS seconds"
exit 1
17 changes: 8 additions & 9 deletions src/__tests__/euphrates.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ import {
TEST_KEY,
} from './testConsts';
import {
api,
expectError,
routeEuphrates,
shouldRouteEuphrates,
transferToken,
} from './testUtils';

Expand All @@ -41,11 +40,11 @@ describe.concurrent('/shouldRouteEuphrates', () => {
const recipient = '0x0085560b24769dAC4ed057F1B2ae40746AA9aAb6';

const testShouldRouteEuphrates = async (params: RouteParamsEuphrates) => {
let res = await shouldRouteEuphrates(params);
let res = await api.shouldRouteEuphrates(params);
expect(res).toMatchSnapshot();

// should be case insensitive
res = await shouldRouteEuphrates({
res = await api.shouldRouteEuphrates({
...params,
recipient: params.recipient.toLocaleLowerCase(),
});
Expand All @@ -64,7 +63,7 @@ describe.concurrent('/shouldRouteEuphrates', () => {
describe('when should not route', () => {
it('when missing params', async () => {
try {
await shouldRouteEuphrates({
await api.shouldRouteEuphrates({
recipient,
});
expect.fail('did not throw an err');
Expand All @@ -73,7 +72,7 @@ describe.concurrent('/shouldRouteEuphrates', () => {
}

try {
await shouldRouteEuphrates({
await api.shouldRouteEuphrates({
poolId: 0,
});
expect.fail('did not throw an err');
Expand All @@ -83,7 +82,7 @@ describe.concurrent('/shouldRouteEuphrates', () => {
});

it('when bad params', async () => {
const res = await shouldRouteEuphrates({
const res = await api.shouldRouteEuphrates({
recipient,
poolId: 520,
});
Expand Down Expand Up @@ -159,7 +158,7 @@ describe('/routeEuphrates', () => {
recipient: user.address,
poolId,
};
const res = await shouldRouteEuphrates(routeArgs);
const res = await api.shouldRouteEuphrates(routeArgs);
({ routerAddr } = res.data);

// make sure user has enough DOT/LCDOT to transfer to router
Expand All @@ -180,7 +179,7 @@ describe('/routeEuphrates', () => {
await transferToken(routerAddr, user, inTokenAddr, stakeAmount);

console.log('routing ...');
const routeRes = await routeEuphrates({
const routeRes = await api.routeEuphrates({
...routeArgs,
token: inTokenAddr,
});
Expand Down
31 changes: 14 additions & 17 deletions src/__tests__/homa.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ import {
TEST_KEY,
} from './testConsts';
import {
api,
expectError,
routeHoma,
routeHomaAuto,
routeStatus,
shouldRouteHoma,
transferToken,
} from './testUtils';

Expand All @@ -41,7 +38,7 @@ describe.concurrent('/shouldRouteHoma', () => {
it('to evm address', async () => {
// for (const network of [Object.values(Mainnet)]) { // TODO: enable this after deploying contract to karura
for (const chain of ['acala']) {
let res = await shouldRouteHoma({
let res = await api.shouldRouteHoma({
destAddr,
chain,
});
Expand All @@ -56,7 +53,7 @@ describe.concurrent('/shouldRouteHoma', () => {
`);

// should be case insensitive
res = await shouldRouteHoma({
res = await api.shouldRouteHoma({
destAddr: destAddr.toLocaleLowerCase(),
chain,
});
Expand All @@ -75,7 +72,7 @@ describe.concurrent('/shouldRouteHoma', () => {
it('to substrate address', async () => {
// for (const network of [Object.values(Mainnet)]) { // TODO: enable this after deploying contract to karura
for (const chain of ['acala']) {
const res = await shouldRouteHoma({
const res = await api.shouldRouteHoma({
destAddr: destAddrSubstrate,
chain,
});
Expand All @@ -95,7 +92,7 @@ describe.concurrent('/shouldRouteHoma', () => {
describe('when should not route', () => {
it('when missing params', async () => {
try {
await shouldRouteHoma({
await api.shouldRouteHoma({
destAddr,
});
expect.fail('did not throw an err');
Expand All @@ -104,7 +101,7 @@ describe.concurrent('/shouldRouteHoma', () => {
}

try {
await shouldRouteHoma({
await api.shouldRouteHoma({
chain: Mainnet.Acala,
});
expect.fail('did not throw an err');
Expand All @@ -113,7 +110,7 @@ describe.concurrent('/shouldRouteHoma', () => {
}

try {
await shouldRouteHoma({
await api.shouldRouteHoma({
chain: 'mandala',
destAddr,
});
Expand All @@ -124,7 +121,7 @@ describe.concurrent('/shouldRouteHoma', () => {
});

it('when bad params', async () => {
const res = await shouldRouteHoma({
const res = await api.shouldRouteHoma({
chain: Mainnet.Acala,
destAddr: '0xaaaaaaaaaa',
});
Expand Down Expand Up @@ -197,7 +194,7 @@ describe('/routeHoma', () => {
destAddr,
chain: 'acala',
};
const res = await shouldRouteHoma(routeArgs);
const res = await api.shouldRouteHoma(routeArgs);
({ routerAddr } = res.data);

// make sure user has enough DOT to transfer to router
Expand All @@ -217,7 +214,7 @@ describe('/routeHoma', () => {
await transferToken(routerAddr, user, DOT, stakeAmount);

console.log('routing ...');
const routeRes = await routeHoma({
const routeRes = await api.routeHoma({
...routeArgs,
token: DOT,
});
Expand Down Expand Up @@ -253,7 +250,7 @@ describe('/routeHoma', () => {
destAddr,
chain: 'acala',
};
const res = await shouldRouteHoma(routeArgs);
const res = await api.shouldRouteHoma(routeArgs);
({ routerAddr } = res.data);

// make sure user has enough DOT to transfer to router
Expand All @@ -270,7 +267,7 @@ describe('/routeHoma', () => {
const bal0 = await fetchTokenBalances();

console.log('sending auto routing request ...');
const routeRes = await routeHomaAuto({
const routeRes = await api.routeHomaAuto({
...routeArgs,
token: DOT,
});
Expand All @@ -279,7 +276,7 @@ describe('/routeHoma', () => {

const waitForRoute = new Promise<void>((resolve, reject) => {
const pollRouteStatus = setInterval(async () => {
const res = await routeStatus({ id: reqId });
const res = await api.routeStatus({ id: reqId });
const { status } = res.data[0];
console.log(`current status: ${status}`);

Expand All @@ -299,7 +296,7 @@ describe('/routeHoma', () => {
await waitForRoute;

// query status by destAddr should also returns same result
const { data } = await routeStatus({ destAddr });
const { data } = await api.routeStatus({ destAddr });
const reqInfo = data.find(info => info.reqId === reqId);
expect(reqInfo).not.to.be.undefined;
expect(reqInfo.status).to.eq(RouteStatus.Complete);
Expand Down
10 changes: 5 additions & 5 deletions src/__tests__/misc.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { api, expectError } from './testUtils';
import { describe, expect, it } from 'vitest';
import { expectError, health, noRoute, testTimeout, version } from './testUtils';

describe.concurrent('/miscellaneous', () => {
describe('when no route for the request', () => {
it('throws correct error', async () => {
try {
await noRoute({});
await api.noRoute({});

expect.fail('/noRoute did not throw when it should!');
} catch (err) {
Expand All @@ -16,15 +16,15 @@ describe.concurrent('/miscellaneous', () => {

describe('/version', () => {
it('works', async () => {
const res = await version({});
const res = await api.version({});
expect(res).to.not.be.undefined;
});
});

describe('/testTimeout', () => {
it('works', async () => {
const startTime = Date.now();
await testTimeout({
await api.testTimeout({
timeout: 1000,
});
const endTime = Date.now();
Expand All @@ -35,7 +35,7 @@ describe.concurrent('/miscellaneous', () => {

describe('/health', () => {
it('works', async () => {
const res = await health({});
const res = await api.health({});

expect(Number(res.data.relayerBalAcala)).to.be.gt(0);
// expect(Number(res.data.relayerBalKarura)).to.be.gt(0);
Expand Down
Loading

0 comments on commit fcee23c

Please sign in to comment.