forked from paraswap/paraswap-dex-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__DexName__-e2e.test.ts.template
162 lines (145 loc) · 4.93 KB
/
__DexName__-e2e.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/* eslint-disable no-console */
import dotenv from 'dotenv';
dotenv.config();
import { testE2E } from '../../../tests/utils-e2e';
import {
Tokens,
Holders,
NativeTokenSymbols,
} from '../../../tests/constants-e2e';
import { Network, ContractMethod, SwapSide } from '../../constants';
import { StaticJsonRpcProvider } from '@ethersproject/providers';
import { generateConfig } from '../../config';
/*
README
======
This test script should add e2e tests for __DexName__. The tests
should cover as many cases as possible. Most of the DEXes follow
the following test structure:
- DexName
- ForkName + Network
- ContractMethod
- ETH -> Token swap
- Token -> ETH swap
- Token -> Token swap
The template already enumerates the basic structure which involves
testing simpleSwap, multiSwap, megaSwap contract methods for
ETH <> TOKEN and TOKEN <> TOKEN swaps. You should replace tokenA and
tokenB with any two highly liquid tokens on __DexName__ for the tests
to work. If the tokens that you would like to use are not defined in
Tokens or Holders map, you can update the './tests/constants-e2e'
Other than the standard cases that are already added by the template
it is highly recommended to add test cases which could be specific
to testing __DexName__ (Eg. Tests based on poolType, special tokens,
etc).
You can run this individual test script by running:
`npx jest src/dex/<dex-name>/<dex-name>-e2e.test.ts`
e2e tests use the Tenderly fork api. Please add the following to your
.env file:
TENDERLY_TOKEN=Find this under Account>Settings>Authorization.
TENDERLY_ACCOUNT_ID=Your Tenderly account name.
TENDERLY_PROJECT=Name of a Tenderly project you have created in your
dashboard.
(This comment should be removed from the final implementation)
*/
function testForNetwork(
network: Network,
dexKey: string,
tokenASymbol: string,
tokenBSymbol: string,
tokenAAmount: string,
tokenBAmount: string,
nativeTokenAmount: string,
) {
const provider = new StaticJsonRpcProvider(
generateConfig(network).privateHttpProvider,
network,
);
const tokens = Tokens[network];
const holders = Holders[network];
const nativeTokenSymbol = NativeTokenSymbols[network];
// TODO: Add any direct swap contractMethod name if it exists
const sideToContractMethods = new Map([
[
SwapSide.SELL,
[
ContractMethod.simpleSwap,
ContractMethod.multiSwap,
ContractMethod.megaSwap,
],
],
// TODO: If buy is not supported remove the buy contract methods
[SwapSide.BUY, [ContractMethod.simpleBuy, ContractMethod.buy]],
]);
describe(`${network}`, () => {
sideToContractMethods.forEach((contractMethods, side) =>
describe(`${side}`, () => {
contractMethods.forEach((contractMethod: ContractMethod) => {
describe(`${contractMethod}`, () => {
it(`${nativeTokenSymbol} -> ${tokenASymbol}`, async () => {
await testE2E(
tokens[nativeTokenSymbol],
tokens[tokenASymbol],
holders[nativeTokenSymbol],
side === SwapSide.SELL ? nativeTokenAmount : tokenAAmount,
side,
dexKey,
contractMethod,
network,
provider,
);
});
it(`${tokenASymbol} -> ${nativeTokenSymbol}`, async () => {
await testE2E(
tokens[tokenASymbol],
tokens[nativeTokenSymbol],
holders[tokenASymbol],
side === SwapSide.SELL ? tokenAAmount : nativeTokenAmount,
side,
dexKey,
contractMethod,
network,
provider,
);
});
it(`${tokenASymbol} -> ${tokenBSymbol}`, async () => {
await testE2E(
tokens[tokenASymbol],
tokens[tokenBSymbol],
holders[tokenASymbol],
side === SwapSide.SELL ? tokenAAmount : tokenBAmount,
side,
dexKey,
contractMethod,
network,
provider,
);
});
});
});
}),
);
});
}
describe('__DexName__ E2E', () => {
const dexKey = '__DexName__';
describe('Mainnet', () => {
const network = Network.MAINNET;
// TODO: Modify the tokenASymbol, tokenBSymbol, tokenAAmount;
const tokenASymbol: string = 'tokenASymbol';
const tokenBSymbol: string = 'tokenBSymbol';
const tokenAAmount: string = 'tokenAAmount';
const tokenBAmount: string = 'tokenBAmount';
const nativeTokenAmount = '1000000000000000000';
testForNetwork(
network,
dexKey,
tokenASymbol,
tokenBSymbol,
tokenAAmount,
tokenBAmount,
nativeTokenAmount,
);
// TODO: Add any additional test cases required to test __DexName__
});
});