mirror of
https://github.com/cerc-io/watcher-ts
synced 2024-11-19 20:36:19 +00:00
Test for all entities after MintEvent. (#188)
Co-authored-by: prathamesh0 <prathamesh.musale0@gmail.com>
This commit is contained in:
parent
0487c05ee1
commit
95f830178d
@ -26,7 +26,7 @@
|
|||||||
},
|
},
|
||||||
"overrides": [
|
"overrides": [
|
||||||
{
|
{
|
||||||
"files": ["*.test.ts"],
|
"files": ["*.test.ts", "test/*.ts"],
|
||||||
"rules": {
|
"rules": {
|
||||||
"no-unused-expressions": "off"
|
"no-unused-expressions": "off"
|
||||||
}
|
}
|
||||||
|
@ -15,9 +15,9 @@
|
|||||||
"typeorm": "^0.2.32"
|
"typeorm": "^0.2.32"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"server": "DEBUG=vulcanize:* nodemon src/server.ts -f environments/local.toml",
|
"server": "DEBUG=vulcanize:* nodemon --watch src src/server.ts -f environments/local.toml",
|
||||||
"server:mock": "MOCK=1 nodemon src/server.ts -f environments/local.toml",
|
"server:mock": "MOCK=1 nodemon src/server.ts -f environments/local.toml",
|
||||||
"job-runner": "DEBUG=vulcanize:* nodemon src/job-runner.ts -f environments/local.toml",
|
"job-runner": "DEBUG=vulcanize:* nodemon --watch src src/job-runner.ts -f environments/local.toml",
|
||||||
"test": "mocha -r ts-node/register src/**/*.spec.ts",
|
"test": "mocha -r ts-node/register src/**/*.spec.ts",
|
||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import { ethers, Contract, ContractTransaction, Signer } from 'ethers';
|
import { ethers, Contract, Signer } from 'ethers';
|
||||||
import { request } from 'graphql-request';
|
import { request } from 'graphql-request';
|
||||||
import 'mocha';
|
import 'mocha';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
@ -32,10 +32,15 @@ import {
|
|||||||
queryToken,
|
queryToken,
|
||||||
queryPoolsByTokens,
|
queryPoolsByTokens,
|
||||||
queryPoolById,
|
queryPoolById,
|
||||||
queryPoolDayData,
|
|
||||||
queryMints,
|
queryMints,
|
||||||
queryTicks
|
queryTicks
|
||||||
} from '../test/queries';
|
} from '../test/queries';
|
||||||
|
import {
|
||||||
|
checkUniswapDayData,
|
||||||
|
checkPoolDayData,
|
||||||
|
checkTokenDayData,
|
||||||
|
checkTokenHourData
|
||||||
|
} from '../test/utils';
|
||||||
|
|
||||||
const NETWORK_RPC_URL = 'http://localhost:8545';
|
const NETWORK_RPC_URL = 'http://localhost:8545';
|
||||||
|
|
||||||
@ -92,7 +97,7 @@ describe('uni-info-watcher', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('PoolCreatedEvent', () => {
|
describe('PoolCreatedEvent', () => {
|
||||||
// NOTE Skipping checking entity updates that cannot be gotten using queries.
|
// NOTE Skipping checking entity updates that cannot be gotten/derived using queries.
|
||||||
|
|
||||||
const fee = 500;
|
const fee = 500;
|
||||||
|
|
||||||
@ -114,6 +119,7 @@ describe('uni-info-watcher', () => {
|
|||||||
|
|
||||||
it('should trigger PoolCreatedEvent', async () => {
|
it('should trigger PoolCreatedEvent', async () => {
|
||||||
// Create Pool.
|
// Create Pool.
|
||||||
|
// Not doing tx.wait() here as we are waiting for the event.
|
||||||
createPool(factory, token0Address, token1Address, fee);
|
createPool(factory, token0Address, token1Address, fee);
|
||||||
|
|
||||||
// Wait for PoolCreatedEvent.
|
// Wait for PoolCreatedEvent.
|
||||||
@ -182,29 +188,7 @@ describe('uni-info-watcher', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should update PoolDayData entity', async () => {
|
it('should update PoolDayData entity', async () => {
|
||||||
// Get the latest PoolDayData.
|
checkPoolDayData(endpoint, pool.address);
|
||||||
const variables = {
|
|
||||||
first: 1,
|
|
||||||
orderBy: 'date',
|
|
||||||
orderDirection: 'desc',
|
|
||||||
pool: pool.address
|
|
||||||
};
|
|
||||||
const data = await request(endpoint, queryPoolDayData, variables);
|
|
||||||
expect(data.poolDayDatas).to.not.be.empty;
|
|
||||||
|
|
||||||
const dayPoolID: string = data.poolDayDatas[0].id;
|
|
||||||
const poolID: string = dayPoolID.split('-')[0];
|
|
||||||
const dayID: number = +dayPoolID.split('-')[1];
|
|
||||||
const date = data.poolDayDatas[0].date;
|
|
||||||
const tvlUSD = data.poolDayDatas[0].tvlUSD;
|
|
||||||
|
|
||||||
const dayStartTimestamp = dayID * 86400;
|
|
||||||
const poolData = await request(endpoint, queryPoolById, { id: pool.address });
|
|
||||||
const totalValueLockedUSD: string = poolData.pool.totalValueLockedUSD;
|
|
||||||
|
|
||||||
expect(poolID).to.be.equal(pool.address);
|
|
||||||
expect(date).to.be.equal(dayStartTimestamp);
|
|
||||||
expect(tvlUSD).to.be.equal(totalValueLockedUSD);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -251,8 +235,7 @@ describe('uni-info-watcher', () => {
|
|||||||
|
|
||||||
it('should trigger MintEvent', async () => {
|
it('should trigger MintEvent', async () => {
|
||||||
// Pool mint.
|
// Pool mint.
|
||||||
const transaction: ContractTransaction = await poolCallee.mint(pool.address, recipient, BigInt(tickLower), BigInt(tickUpper), BigInt(amount));
|
poolCallee.mint(pool.address, recipient, BigInt(tickLower), BigInt(tickUpper), BigInt(amount));
|
||||||
await transaction.wait();
|
|
||||||
|
|
||||||
// Wait for MintEvent.
|
// Wait for MintEvent.
|
||||||
const eventType = 'MintEvent';
|
const eventType = 'MintEvent';
|
||||||
@ -317,15 +300,18 @@ describe('uni-info-watcher', () => {
|
|||||||
|
|
||||||
const id: string = data.mints[0].id;
|
const id: string = data.mints[0].id;
|
||||||
const txCountID = id.split('#')[1];
|
const txCountID = id.split('#')[1];
|
||||||
|
const origin = data.mints[0].origin;
|
||||||
const owner = data.mints[0].owner;
|
const owner = data.mints[0].owner;
|
||||||
const sender = data.mints[0].sender;
|
const sender = data.mints[0].sender;
|
||||||
|
|
||||||
data = await request(endpoint, queryPoolById, { id: pool.address });
|
data = await request(endpoint, queryPoolById, { id: pool.address });
|
||||||
const poolTxCount = data.pool.txCount;
|
const poolTxCount = data.pool.txCount;
|
||||||
|
const expectedOrigin = recipient;
|
||||||
const expectedOwner = recipient;
|
const expectedOwner = recipient;
|
||||||
const expectedSender = poolCallee.address;
|
const expectedSender = poolCallee.address;
|
||||||
|
|
||||||
expect(txCountID).to.be.equal(poolTxCount);
|
expect(txCountID).to.be.equal(poolTxCount);
|
||||||
|
expect(origin).to.be.equal(expectedOrigin);
|
||||||
expect(owner).to.be.equal(expectedOwner);
|
expect(owner).to.be.equal(expectedOwner);
|
||||||
expect(sender).to.be.equal(expectedSender);
|
expect(sender).to.be.equal(expectedSender);
|
||||||
});
|
});
|
||||||
@ -343,5 +329,23 @@ describe('uni-info-watcher', () => {
|
|||||||
expect(upperTick.liquidityGross).to.be.equal(amount.toString());
|
expect(upperTick.liquidityGross).to.be.equal(amount.toString());
|
||||||
expect(upperTick.liquidityNet).to.be.equal(amount.toString());
|
expect(upperTick.liquidityNet).to.be.equal(amount.toString());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should update UniswapDayData entity', async () => {
|
||||||
|
checkUniswapDayData(endpoint);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should update PoolDayData entity', async () => {
|
||||||
|
checkPoolDayData(endpoint, pool.address);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should update TokenDayData entities', async () => {
|
||||||
|
checkTokenDayData(endpoint, token0.address);
|
||||||
|
checkTokenDayData(endpoint, token1.address);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should update TokenHourData entities', async () => {
|
||||||
|
checkTokenHourData(endpoint, token0.address);
|
||||||
|
checkTokenHourData(endpoint, token1.address);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -65,6 +65,16 @@ query queryPoolsByTokens($tokens: [String!]) {
|
|||||||
}
|
}
|
||||||
}`;
|
}`;
|
||||||
|
|
||||||
|
// Getting UniswapDayData(s).
|
||||||
|
export const queryUniswapDayData = gql`
|
||||||
|
query queryUniswapDayData($first: Int, $orderBy: UniswapDayData_orderBy, $orderDirection: OrderDirection) {
|
||||||
|
uniswapDayDatas(first: $first, orderBy: $orderBy, orderDirection: $orderDirection) {
|
||||||
|
id,
|
||||||
|
date,
|
||||||
|
tvlUSD
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
|
||||||
// Getting PoolDayData(s) filtered by pool and ordered by date.
|
// Getting PoolDayData(s) filtered by pool and ordered by date.
|
||||||
export const queryPoolDayData = gql`
|
export const queryPoolDayData = gql`
|
||||||
query queryPoolDayData($first: Int, $orderBy: PoolDayData_orderBy, $orderDirection: OrderDirection, $pool: String) {
|
query queryPoolDayData($first: Int, $orderBy: PoolDayData_orderBy, $orderDirection: OrderDirection, $pool: String) {
|
||||||
@ -75,6 +85,29 @@ query queryPoolDayData($first: Int, $orderBy: PoolDayData_orderBy, $orderDirecti
|
|||||||
}
|
}
|
||||||
}`;
|
}`;
|
||||||
|
|
||||||
|
// Getting TokenDayDatas(s) filtered by token and ordered by date.
|
||||||
|
export const queryTokenDayData = gql`
|
||||||
|
query queryTokenDayData($first: Int, $orderBy: TokenDayData_orderBy, $orderDirection: OrderDirection, $token: String) {
|
||||||
|
tokenDayDatas(first: $first, orderBy: $orderBy, orderDirection: $orderDirection, where: { token: $token }) {
|
||||||
|
id,
|
||||||
|
date,
|
||||||
|
totalValueLockedUSD
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
|
||||||
|
// Getting TokenDayDatas(s) filtered by token and ordered by date.
|
||||||
|
export const queryTokenHourData = gql`
|
||||||
|
query queryTokenHourData($first: Int, $orderBy: TokenHourData_orderBy, $orderDirection: OrderDirection, $token: String) {
|
||||||
|
tokenHourDatas(first: $first, orderBy: $orderBy, orderDirection: $orderDirection, where: { token: $token }) {
|
||||||
|
id,
|
||||||
|
low,
|
||||||
|
high,
|
||||||
|
open,
|
||||||
|
close,
|
||||||
|
periodStartUnix
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
|
||||||
// Getting mint(s) filtered by pool, tokens and ordered by timestamp.
|
// Getting mint(s) filtered by pool, tokens and ordered by timestamp.
|
||||||
export const queryMints = gql`
|
export const queryMints = gql`
|
||||||
query queryMints(
|
query queryMints(
|
||||||
|
122
packages/uni-info-watcher/test/utils.ts
Normal file
122
packages/uni-info-watcher/test/utils.ts
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
import { expect } from 'chai';
|
||||||
|
import { request } from 'graphql-request';
|
||||||
|
import Decimal from 'decimal.js';
|
||||||
|
|
||||||
|
import {
|
||||||
|
queryFactory,
|
||||||
|
queryBundle,
|
||||||
|
queryToken,
|
||||||
|
queryPoolById,
|
||||||
|
queryPoolDayData,
|
||||||
|
queryUniswapDayData,
|
||||||
|
queryTokenDayData,
|
||||||
|
queryTokenHourData
|
||||||
|
} from '../test/queries';
|
||||||
|
|
||||||
|
export const checkUniswapDayData = async (endpoint: string): Promise<void> => {
|
||||||
|
// Get the latest UniswapDayData.
|
||||||
|
const variables = {
|
||||||
|
first: 1,
|
||||||
|
orderBy: 'date',
|
||||||
|
orderDirection: 'desc'
|
||||||
|
};
|
||||||
|
const data = await request(endpoint, queryUniswapDayData, variables);
|
||||||
|
expect(data.uniswapDayDatas).to.not.be.empty;
|
||||||
|
|
||||||
|
const id: string = data.uniswapDayDatas[0].id;
|
||||||
|
const dayID = Number(id);
|
||||||
|
const date = data.uniswapDayDatas[0].date;
|
||||||
|
const tvlUSD = data.uniswapDayDatas[0].tvlUSD;
|
||||||
|
|
||||||
|
const dayStartTimestamp = dayID * 86400;
|
||||||
|
const factoryData = await request(endpoint, queryFactory);
|
||||||
|
const totalValueLockedUSD: string = factoryData.factories[0].totalValueLockedUSD;
|
||||||
|
|
||||||
|
expect(date).to.be.equal(dayStartTimestamp);
|
||||||
|
expect(tvlUSD).to.be.equal(totalValueLockedUSD);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const checkPoolDayData = async (endpoint: string, poolAddress: string): Promise<void> => {
|
||||||
|
// Get the latest PoolDayData.
|
||||||
|
const variables = {
|
||||||
|
first: 1,
|
||||||
|
orderBy: 'date',
|
||||||
|
orderDirection: 'desc',
|
||||||
|
pool: poolAddress
|
||||||
|
};
|
||||||
|
const data = await request(endpoint, queryPoolDayData, variables);
|
||||||
|
expect(data.poolDayDatas).to.not.be.empty;
|
||||||
|
|
||||||
|
const dayPoolID: string = data.poolDayDatas[0].id;
|
||||||
|
const poolID: string = dayPoolID.split('-')[0];
|
||||||
|
const dayID = Number(dayPoolID.split('-')[1]);
|
||||||
|
const date = data.poolDayDatas[0].date;
|
||||||
|
const tvlUSD = data.poolDayDatas[0].tvlUSD;
|
||||||
|
|
||||||
|
const dayStartTimestamp = dayID * 86400;
|
||||||
|
const poolData = await request(endpoint, queryPoolById, { id: poolAddress });
|
||||||
|
const totalValueLockedUSD: string = poolData.pool.totalValueLockedUSD;
|
||||||
|
|
||||||
|
expect(poolID).to.be.equal(poolAddress);
|
||||||
|
expect(date).to.be.equal(dayStartTimestamp);
|
||||||
|
expect(tvlUSD).to.be.equal(totalValueLockedUSD);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const checkTokenDayData = async (endpoint: string, tokenAddress: string): Promise<void> => {
|
||||||
|
// Get the latest TokenDayData.
|
||||||
|
const variables = {
|
||||||
|
first: 1,
|
||||||
|
orderBy: 'date',
|
||||||
|
orderDirection: 'desc',
|
||||||
|
token: tokenAddress
|
||||||
|
};
|
||||||
|
const data = await request(endpoint, queryTokenDayData, variables);
|
||||||
|
expect(data.tokenDayDatas).to.not.be.empty;
|
||||||
|
|
||||||
|
const tokenDayID: string = data.tokenDayDatas[0].id;
|
||||||
|
const tokenID: string = tokenDayID.split('-')[0];
|
||||||
|
const dayID = Number(tokenDayID.split('-')[1]);
|
||||||
|
const date = data.tokenDayDatas[0].date;
|
||||||
|
const tvlUSD = data.tokenDayDatas[0].totalValueLockedUSD;
|
||||||
|
|
||||||
|
const dayStartTimestamp = dayID * 86400;
|
||||||
|
const tokenData = await request(endpoint, queryToken, { id: tokenAddress });
|
||||||
|
const totalValueLockedUSD: string = tokenData.token.totalValueLockedUSD;
|
||||||
|
|
||||||
|
expect(tokenID).to.be.equal(tokenAddress);
|
||||||
|
expect(date).to.be.equal(dayStartTimestamp);
|
||||||
|
expect(tvlUSD).to.be.equal(totalValueLockedUSD);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const checkTokenHourData = async (endpoint: string, tokenAddress: string): Promise<void> => {
|
||||||
|
// Get the latest TokenHourData.
|
||||||
|
const variables = {
|
||||||
|
first: 1,
|
||||||
|
orderBy: 'periodStartUnix',
|
||||||
|
orderDirection: 'desc',
|
||||||
|
token: tokenAddress
|
||||||
|
};
|
||||||
|
const data = await request(endpoint, queryTokenHourData, variables);
|
||||||
|
expect(data.tokenHourDatas).to.not.be.empty;
|
||||||
|
|
||||||
|
const tokenHourID: string = data.tokenHourDatas[0].id;
|
||||||
|
const tokenID: string = tokenHourID.split('-')[0];
|
||||||
|
const hourIndex = Number(tokenHourID.split('-')[1]);
|
||||||
|
const periodStartUnix = data.tokenHourDatas[0].periodStartUnix;
|
||||||
|
const low = data.tokenHourDatas[0].low;
|
||||||
|
const high = data.tokenHourDatas[0].high;
|
||||||
|
const open = data.tokenHourDatas[0].open;
|
||||||
|
const close = data.tokenHourDatas[0].close;
|
||||||
|
|
||||||
|
const hourStartUnix = hourIndex * 3600;
|
||||||
|
const tokenData = await request(endpoint, queryToken, { id: tokenAddress });
|
||||||
|
const bundleData = await request(endpoint, queryBundle);
|
||||||
|
const tokenPrice = new Decimal(tokenData.token.derivedETH).times(bundleData.bundles[0].ethPriceUSD);
|
||||||
|
|
||||||
|
expect(tokenID).to.be.equal(tokenAddress);
|
||||||
|
expect(periodStartUnix).to.be.equal(hourStartUnix);
|
||||||
|
expect(low).to.be.equal(tokenPrice.toString());
|
||||||
|
expect(high).to.be.equal(tokenPrice.toString());
|
||||||
|
expect(open).to.be.equal(tokenPrice.toString());
|
||||||
|
expect(close).to.be.equal(tokenPrice.toString());
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user