-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement e2e test flow, fix small bugs (#65)
* Create simple e2e package * Fix production issues and inconsistencies * Implement e2e test flow and CI test * Fix tests
- Loading branch information
Showing
31 changed files
with
540 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# NOTE: Keep in sync with .dockerignore | ||
.build | ||
.env | ||
.idea | ||
.log | ||
.tsbuildinfo | ||
.vscode | ||
build | ||
dist | ||
node_modules | ||
coverage | ||
pusher.json | ||
secrets.env | ||
signed-api.json | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# NOTE: Keep in sync with .dockerignore | ||
.build | ||
.env | ||
.idea | ||
.log | ||
.tsbuildinfo | ||
.vscode | ||
build | ||
dist | ||
node_modules | ||
coverage | ||
pusher.json | ||
secrets.env | ||
signed-api.json | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# e2e | ||
|
||
> End to end test utilizing Mock API, pusher and signed API. | ||
## Getting started | ||
|
||
1. If you are using Docker Desktop, you need to change the URL in `pusher/secrets.env` from `localhost` to | ||
`host.docker.internal`, because pusher is running inside a Docker container. | ||
2. Build the latest Docker images. Run `pnpm run docker:build` from the monorepo root. The e2e flow uses the docker | ||
images. | ||
3. This module contains services (or configurations) that are integrated together. Specifically: | ||
|
||
- `pusher` - Contains the configuration for the pusher service. | ||
- `signed-api` - Contains the configuration for the signed API service. | ||
- `data-provider-api.ts` - Contains the configuration for the data provider API service (mocked express server). | ||
- `user.ts` - Contains the configuration for the user service (infinite fetch from signed API). | ||
|
||
You are free to modify the configurations to test different scenarios. | ||
|
||
4. There are `start:<some-service>` scripts to start the services. It is recommended to start each service in a separate | ||
terminal and in this order: | ||
|
||
1. `pnpm run start:data-provider-api` | ||
2. `pnpm run start:signed-api` | ||
3. `pnpm run start:pusher` | ||
4. `pnpm run start:user` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const config = require('../../jest.config'); | ||
|
||
module.exports = { | ||
...config, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"name": "e2e", | ||
"version": "1.0.0", | ||
"engines": { | ||
"node": "^18.14.0", | ||
"pnpm": "^8.8.0" | ||
}, | ||
"scripts": { | ||
"build": "tsc --project tsconfig.build.json", | ||
"clean": "rm -rf coverage dist", | ||
"eslint:check": "eslint . --ext .js,.ts --max-warnings 0", | ||
"eslint:fix": "eslint . --ext .js,.ts --fix", | ||
"prettier:check": "prettier --check \"./**/*.{js,ts,md,yml,json}\"", | ||
"prettier:fix": "prettier --write \"./**/*.{js,ts,md,yml,json}\"", | ||
"start:data-provider-api": "ts-node src/data-provider-api.ts", | ||
"start:pusher": "docker run -it --init --volume $(pwd)/src/pusher:/app/config --network host --env-file ./src/pusher/.env --rm --memory=256m pusher:latest", | ||
"start:signed-api": "docker run --publish 8090:8090 -it --init --volume $(pwd)/src/signed-api:/app/config --env-file ./src/signed-api/.env --rm --memory=256m api:latest", | ||
"start:ci:pusher": "docker run --init --volume $(pwd)/src/pusher:/app/config --network host --env-file ./src/pusher/.env --rm --memory=256m pusher:latest", | ||
"start:ci:signed-api": "docker run --publish 8090:8090 --init --volume $(pwd)/src/signed-api:/app/config --env-file ./src/signed-api/.env --rm --memory=256m api:latest", | ||
"start:user": "ts-node src/user.ts", | ||
"test:e2e": "jest", | ||
"tsc": "tsc --project ." | ||
}, | ||
"license": "MIT", | ||
"dependencies": { | ||
"@api3/promise-utils": "^0.4.0", | ||
"axios": "^1.5.1", | ||
"ethers": "^5.7.2", | ||
"express": "^4.18.2", | ||
"lodash": "^4.17.21", | ||
"signed-api/common": "workspace:common@*", | ||
"zod": "^3.22.2" | ||
}, | ||
"devDependencies": { | ||
"@types/express": "^4.17.18", | ||
"@types/lodash": "^4.14.199" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import express from 'express'; | ||
import { logger } from './logger'; | ||
|
||
const app = express(); | ||
const PORT = 9876 || process.env.PORT; | ||
|
||
interface Asset { | ||
value: number; | ||
// Everytime the API is queried, the value will be updated by a random percentage. | ||
deltaPercent: number; | ||
name: string; | ||
} | ||
|
||
const assets: Asset[] = [ | ||
{ | ||
value: 1000, | ||
deltaPercent: 10, | ||
name: 'MOCK-ETH/USD', | ||
}, | ||
{ | ||
value: 5000, | ||
deltaPercent: 2, | ||
name: 'MOCK-BTC/USD', | ||
}, | ||
{ | ||
value: 750, | ||
deltaPercent: 80, | ||
name: 'MOCK-ABC/DEF', | ||
}, | ||
{ | ||
value: 50000, | ||
deltaPercent: 20, | ||
name: 'MOCK-HJK/KOP', | ||
}, | ||
]; | ||
|
||
app.get('/', (_req, res) => { | ||
logger.debug('Request GET /'); | ||
|
||
for (const asset of assets) { | ||
asset.value = parseFloat((asset.value * (1 + ((Math.random() - 0.5) * asset.deltaPercent) / 100)).toFixed(5)); | ||
} | ||
|
||
const response = Object.fromEntries(assets.map((asset) => [asset.name, asset.value])); | ||
logger.debug('Response GET /', response); | ||
|
||
res.json(response); | ||
}); | ||
|
||
app.listen(PORT, () => { | ||
logger.info(`Server is running on http://localhost:${PORT}`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { createLogger } from 'signed-api/common'; | ||
|
||
export const logger = createLogger({ | ||
colorize: true, | ||
enabled: true, | ||
minLevel: 'debug', | ||
format: 'pretty', | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
LOGGER_ENABLED=true | ||
LOG_COLORIZE=true | ||
LOG_FORMAT=pretty | ||
LOG_LEVEL=debug |
Oops, something went wrong.