forked from paraswap/paraswap-dex-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__DexName__-events.test.ts.template
109 lines (93 loc) · 3.47 KB
/
__DexName__-events.test.ts.template
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import dotenv from 'dotenv';
dotenv.config();
import { __DexName__EventPool } from './__DexNameParam__-pool';
import { Network } from '../../constants';
import { Address } from '../../types';
import { DummyDexHelper } from '../../dex-helper/index';
import { testEventSubscriber } from '../../../tests/utils-events';
import { PoolState } from './types';
/*
README
======
This test script adds unit tests for __DexName__ event based
system. This is done by fetching the state on-chain before the
event block, manually pushing the block logs to the event-subscriber,
comparing the local state with on-chain state.
Most of the logic for testing is abstracted by `testEventSubscriber`.
You need to do two things to make the tests work:
1. Fetch the block numbers where certain events were released. You
can modify the `./scripts/fetch-event-blocknumber.ts` to get the
block numbers for different events. Make sure to get sufficient
number of blockNumbers to cover all possible cases for the event
mutations.
2. Complete the implementation for fetchPoolState function. The
function should fetch the on-chain state of the event subscriber
using just the blocknumber.
The template tests only include the test for a single event
subscriber. There can be cases where multiple event subscribers
exist for a single DEX. In such cases additional tests should be
added.
You can run this individual test script by running:
`npx jest src/dex/<dex-name>/<dex-name>-events.test.ts`
(This comment should be removed from the final implementation)
*/
jest.setTimeout(50 * 1000);
async function fetchPoolState(
__DexNameCamel__Pools: __DexName__EventPool,
blockNumber: number,
poolAddress: string,
): Promise<PoolState> {
// TODO: complete me!
return {};
}
// eventName -> blockNumbers
type EventMappings = Record<string, number[]>;
describe('__DexName__ EventPool Mainnet', function () {
const dexKey = '__DexName__';
const network = Network.MAINNET;
const dexHelper = new DummyDexHelper(network);
const logger = dexHelper.getLogger(dexKey);
let __DexNameCamel__Pool: __DexName__EventPool;
// poolAddress -> EventMappings
const eventsToTest: Record<Address, EventMappings> = {
// TODO: complete me!
};
beforeEach(async () => {
__DexNameCamel__Pool = new __DexName__EventPool(
dexKey,
network,
dexHelper,
logger,
/* TODO: Put here additional constructor arguments if needed */
);
});
Object.entries(eventsToTest).forEach(
([poolAddress, events]: [string, EventMappings]) => {
describe(`Events for ${poolAddress}`, () => {
Object.entries(events).forEach(
([eventName, blockNumbers]: [string, number[]]) => {
describe(`${eventName}`, () => {
blockNumbers.forEach((blockNumber: number) => {
it(`State after ${blockNumber}`, async function () {
await testEventSubscriber(
__DexNameCamel__Pool,
__DexNameCamel__Pool.addressesSubscribed,
(_blockNumber: number) =>
fetchPoolState(
__DexNameCamel__Pool,
_blockNumber,
poolAddress,
),
blockNumber,
`${dexKey}_${poolAddress}`,
dexHelper.provider,
);
});
});
});
},
);
});
},
);
});