Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test: fix e2e tests #40

Merged
merged 3 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ jobs:
run: npm run test

- name: e2e test
run: npm run test:e2e
run: npm run pretest:e2e && npm run test:e2e
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
"serve:prod": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"lint:check": "eslint \"{src,apps,libs,test}/**/*.ts\"",
"test": "dotenv -e .env.test jest",
"test": "dotenv -e .env.test -- jest",
"test:watch": "npm run test -- --watch",
"test:cov": "npm run test -- --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "npm run test -- --runInBand --config ./test/e2e/jest-e2e.json",
"test:e2e": "npm run test -- --runInBand --config ./test/e2e/jest-e2e.json --forceExit",
"db": "docker compose up",
"db:deploy": "docker compose up -d",
"db:remove": "docker compose down -v",
Expand All @@ -30,7 +30,7 @@
"db:push-schema": "npx prisma db push",
"db:migrate": "npx prisma migrate deploy",
"postdb:deploy": "sleep 1.5; npm run db:migrate",
"pretest:e2e": "dotenv -e .env.test npm run db:push-schema",
"pretest:e2e": "dotenv -e .env.test npx prisma migrate dev",
"prisma:test-studio": "dotenv -e .env.test npx prisma studio",
"prisma:studio": "npx prisma studio"
},
Expand Down
14 changes: 11 additions & 3 deletions src/api/tokens/tokens.service.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Cache } from '@nestjs/cache-manager';
import { Injectable } from '@nestjs/common';
import { Pair, PairLiquidityInfo, Token } from '@prisma/client';

Expand All @@ -8,7 +9,10 @@ import { presentInvalidTokens } from '@/lib/utils';

@Injectable()
export class TokensService {
constructor(private readonly tokenDbService: TokenDbService) {}
constructor(
private readonly tokenDbService: TokenDbService,
private cacheManager: Cache,
) {}
async getCount(onlyListed?: boolean) {
return this.tokenDbService.count(presentInvalidTokens, onlyListed);
}
Expand All @@ -23,11 +27,15 @@ export class TokensService {
}

async listToken(address: ContractAddress) {
return this.tokenDbService.updateListedValue(address, true);
const res = this.tokenDbService.updateListedValue(address, true);
await this.cacheManager.reset();
return res;
}

async unlistToken(address: ContractAddress) {
return this.tokenDbService.updateListedValue(address, false);
const res = this.tokenDbService.updateListedValue(address, false);
await this.cacheManager.reset();
return res;
}

async getToken(address: ContractAddress): Promise<TokenWithUsd | null> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ exports[`PairLiquidityInfoHistoryDbService upsert should correctly upsert an exi
"pairId": 1,
"reserve0": "500",
"reserve1": "500",
"senderAccount": "abc",
"token0AePrice": "0.060559",
"token1AePrice": "0.060559",
"transactionHash": "th_entry2",
"transactionIndex": 200002n,
}
Expand Down
224 changes: 224 additions & 0 deletions test/e2e/__snapshots__/pairs.e2e-spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`PairsController GET /pairs should return all pairs 1`] = `
[
{
"address": "ct_pair1",
"synchronized": true,
"token0": "ct_token1",
"token1": "ct_token2",
"transactions": 2,
"tvlUsd": "0",
"volumeUsdAll": "0",
"volumeUsdDay": "0",
"volumeUsdMonth": "0",
"volumeUsdWeek": "0",
"volumeUsdYear": "0",
},
{
"address": "ct_pair2",
"synchronized": true,
"token0": "ct_token2",
"token1": "ct_token3",
"transactions": 1,
"tvlUsd": "0",
"volumeUsdAll": "0",
"volumeUsdDay": "0",
"volumeUsdMonth": "0",
"volumeUsdWeek": "0",
"volumeUsdYear": "0",
},
{
"address": "ct_pair3",
"synchronized": true,
"token0": "ct_token2",
"token1": "ct_token5",
"transactions": 0,
"tvlUsd": "0",
"volumeUsdAll": null,
"volumeUsdDay": null,
"volumeUsdMonth": null,
"volumeUsdWeek": null,
"volumeUsdYear": null,
},
{
"address": "ct_pair4",
"synchronized": true,
"token0": "ct_token1",
"token1": "ct_token5",
"transactions": 0,
"tvlUsd": "0",
"volumeUsdAll": null,
"volumeUsdDay": null,
"volumeUsdMonth": null,
"volumeUsdWeek": null,
"volumeUsdYear": null,
},
]
`;

exports[`PairsController GET /pairs should return only listed pairs with only-listed=true 1`] = `
[
{
"address": "ct_pair1",
"synchronized": true,
"token0": "ct_token1",
"token1": "ct_token2",
"transactions": 2,
"tvlUsd": "0",
"volumeUsdAll": "0",
"volumeUsdDay": "0",
"volumeUsdMonth": "0",
"volumeUsdWeek": "0",
"volumeUsdYear": "0",
},
]
`;

exports[`PairsController GET /pairs/by-address/{pair_address} should return pair if it exists 1`] = `
{
"address": "ct_pair1",
"synchronized": true,
"token0": {
"address": "ct_token1",
"decimals": 18,
"listed": false,
"malformed": false,
"name": "1",
"noContract": false,
"symbol": "1",
},
"token1": {
"address": "ct_token2",
"decimals": 18,
"listed": false,
"malformed": false,
"name": "2",
"noContract": false,
"symbol": "2",
},
}
`;

exports[`PairsController GET /pairs/swap-routes/{from}/{to} should return a direct path 1`] = `
[
[
{
"address": "ct_pair2",
"liquidityInfo": {
"height": 1,
"reserve0": "1",
"reserve1": "1",
"totalSupply": "1",
},
"synchronized": true,
"token0": "ct_token2",
"token1": "ct_token3",
},
],
]
`;

exports[`PairsController GET /pairs/swap-routes/{from}/{to} should return an indirect path 1`] = `
[
[
{
"address": "ct_pair1",
"synchronized": true,
"token0": "ct_token1",
"token1": "ct_token2",
},
{
"address": "ct_pair2",
"liquidityInfo": {
"height": 1,
"reserve0": "1",
"reserve1": "1",
"totalSupply": "1",
},
"synchronized": true,
"token0": "ct_token2",
"token1": "ct_token3",
},
],
]
`;

exports[`PairsController GET /pairs/swap-routes/{from}/{to} should return one direct path and one indirect path 1`] = `
[
[
{
"address": "ct_pair4",
"synchronized": true,
"token0": "ct_token1",
"token1": "ct_token5",
},
],
[
{
"address": "ct_pair1",
"synchronized": true,
"token0": "ct_token1",
"token1": "ct_token2",
},
{
"address": "ct_pair3",
"liquidityInfo": {
"height": 2,
"reserve0": "2",
"reserve1": "2",
"totalSupply": "2",
},
"synchronized": true,
"token0": "ct_token2",
"token1": "ct_token5",
},
],
]
`;

exports[`PairsController GET /pairs/swap-routes/{from}/{to} should return paths oven on reverse order of tokens 1`] = `
[
[
{
"address": "ct_pair4",
"synchronized": true,
"token0": "ct_token1",
"token1": "ct_token5",
},
],
[
{
"address": "ct_pair1",
"synchronized": true,
"token0": "ct_token1",
"token1": "ct_token2",
},
{
"address": "ct_pair3",
"liquidityInfo": {
"height": 2,
"reserve0": "2",
"reserve1": "2",
"totalSupply": "2",
},
"synchronized": true,
"token0": "ct_token2",
"token1": "ct_token5",
},
],
]
`;

exports[`PairsController GET /pairs/swap-routes/{from}/{to} should suppress some paths with only-listed=true 1`] = `
[
[
{
"address": "ct_pair4",
"synchronized": true,
"token0": "ct_token1",
"token1": "ct_token5",
},
],
]
`;
Loading