forked from OpenZeppelin/contracts-wizard
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherc20.test.ts
More file actions
278 lines (237 loc) · 5.85 KB
/
erc20.test.ts
File metadata and controls
278 lines (237 loc) · 5.85 KB
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
import test from 'ava';
import type { OptionsError } from '.';
import { erc20 } from '.';
import type { ERC20Options } from './erc20';
import { buildERC20 } from './erc20';
import { printContract } from './print';
function testERC20(title: string, opts: Partial<ERC20Options>) {
test(title, t => {
const c = buildERC20({
name: 'MyToken',
symbol: 'MTK',
...opts,
});
t.snapshot(printContract(c));
});
}
/**
* Tests external API for equivalence with internal API
*/
function testAPIEquivalence(title: string, opts?: ERC20Options) {
test(title, t => {
t.is(
erc20.print(opts),
printContract(
buildERC20({
name: 'MyToken',
symbol: 'MTK',
...opts,
}),
),
);
});
}
testERC20('basic erc20', {});
testERC20('erc20 burnable', {
burnable: true,
});
testERC20('erc20 pausable', {
pausable: true,
access: 'ownable',
});
testERC20('erc20 pausable with roles', {
pausable: true,
access: 'roles',
});
testERC20('erc20 pausable with managed', {
pausable: true,
access: 'managed',
});
testERC20('erc20 burnable pausable', {
burnable: true,
pausable: true,
});
testERC20('erc20 preminted', {
premint: '1000',
});
testERC20('erc20 premint of 0', {
premint: '0',
});
testERC20('erc20 mintable', {
mintable: true,
access: 'ownable',
});
testERC20('erc20 mintable with roles', {
mintable: true,
access: 'roles',
});
testERC20('erc20 permit', {
permit: true,
});
testERC20('erc20 votes', {
votes: true,
});
testERC20('erc20 votes + blocknumber', {
votes: 'blocknumber',
});
testERC20('erc20 votes + timestamp', {
votes: 'timestamp',
});
testERC20('erc20 flashmint', {
flashmint: true,
});
testERC20('erc20 crossChainBridging custom', {
crossChainBridging: 'custom',
});
testERC20('erc20 crossChainBridging custom ownable', {
crossChainBridging: 'custom',
access: 'ownable',
});
testERC20('erc20 crossChainBridging custom roles', {
crossChainBridging: 'custom',
access: 'roles',
});
testERC20('erc20 crossChainBridging custom managed', {
crossChainBridging: 'custom',
access: 'managed',
});
testERC20('erc20 crossChainBridging superchain', {
crossChainBridging: 'superchain',
});
testERC20('erc20 crossChainBridging superchain ownable', {
crossChainBridging: 'superchain',
access: 'ownable',
});
testERC20('erc20 crossChainBridging superchain roles', {
crossChainBridging: 'superchain',
access: 'roles',
});
testERC20('erc20 crossChainBridging superchain managed', {
crossChainBridging: 'superchain',
access: 'managed',
});
test('erc20 crossChainBridging custom, upgradeable not allowed', async t => {
const error = t.throws(() =>
buildERC20({
name: 'MyToken',
symbol: 'MTK',
crossChainBridging: 'custom',
upgradeable: 'transparent',
}),
);
t.is(
(error as OptionsError).messages.crossChainBridging,
'Upgradeability is not currently supported with Cross-Chain Bridging',
);
});
test('erc20 crossChainBridging superchain, upgradeable not allowed', async t => {
const error = t.throws(() =>
buildERC20({
name: 'MyToken',
symbol: 'MTK',
crossChainBridging: 'superchain',
upgradeable: 'transparent',
}),
);
t.is(
(error as OptionsError).messages.crossChainBridging,
'Upgradeability is not currently supported with Cross-Chain Bridging',
);
});
test('erc20 crossChainBridging superchain, premintChainId required', async t => {
const error = t.throws(() =>
buildERC20({
name: 'MyToken',
symbol: 'MTK',
crossChainBridging: 'superchain',
premint: '2000',
}),
);
t.is(
(error as OptionsError).messages.premintChainId,
'Chain ID is required when using Premint with Cross-Chain Bridging',
);
});
testERC20('erc20 premint ignores chainId when not crossChainBridging', {
premint: '2000',
premintChainId: '10',
});
testERC20('erc20 premint chainId crossChainBridging custom', {
premint: '2000',
premintChainId: '10',
crossChainBridging: 'custom',
});
testERC20('erc20 premint chainId crossChainBridging superchain', {
premint: '2000',
premintChainId: '10',
crossChainBridging: 'superchain',
});
testERC20('erc20 full crossChainBridging custom non-upgradeable', {
premint: '2000',
access: 'roles',
burnable: true,
mintable: true,
pausable: true,
permit: true,
votes: true,
flashmint: true,
crossChainBridging: 'custom',
premintChainId: '10',
});
testERC20('erc20 full upgradeable transparent', {
premint: '2000',
access: 'roles',
burnable: true,
mintable: true,
pausable: true,
permit: true,
votes: true,
flashmint: true,
upgradeable: 'transparent',
});
testERC20('erc20 full upgradeable uups', {
premint: '2000',
access: 'roles',
burnable: true,
mintable: true,
pausable: true,
permit: true,
votes: true,
flashmint: true,
upgradeable: 'uups',
});
testERC20('erc20 full upgradeable uups managed', {
premint: '2000',
access: 'managed',
burnable: true,
mintable: true,
pausable: true,
permit: true,
votes: true,
flashmint: true,
upgradeable: 'uups',
});
testAPIEquivalence('erc20 API default');
testAPIEquivalence('erc20 API basic', { name: 'CustomToken', symbol: 'CTK' });
testAPIEquivalence('erc20 API full upgradeable', {
name: 'CustomToken',
symbol: 'CTK',
premint: '2000',
access: 'roles',
burnable: true,
mintable: true,
pausable: true,
permit: true,
votes: true,
flashmint: true,
upgradeable: 'uups',
});
test('erc20 API assert defaults', async t => {
t.is(erc20.print(erc20.defaults), erc20.print());
});
test('erc20 API isAccessControlRequired', async t => {
t.is(erc20.isAccessControlRequired({ mintable: true }), true);
t.is(erc20.isAccessControlRequired({ pausable: true }), true);
t.is(erc20.isAccessControlRequired({ upgradeable: 'uups' }), true);
t.is(erc20.isAccessControlRequired({ upgradeable: 'transparent' }), false);
});