-
Notifications
You must be signed in to change notification settings - Fork 7
/
01-tdrop-token-tnt20-basics.js
324 lines (248 loc) · 11.4 KB
/
01-tdrop-token-tnt20-basics.js
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
const { BN, constants, expectEvent, expectRevert } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');
const { ZERO_ADDRESS } = constants;
describe('TDrop Token TNT20 Basics', function () {
this.timeout(100000);
const name = 'TDrop Token';
const symbol = 'TDROP';
const initialSupply = 100;
let initialHolder;
let recipient;
let anotherAccount;
let superAdmin;
let admin;
let airdropper;
let liquidityMiner;
beforeEach(async function () {
TDropToken = await ethers.getContractFactory("TDropToken");
[initialHolder, recipient, anotherAccount, superAdmin, admin, airdropper, liquidityMiner, ...addrs] = await ethers.getSigners();
tdropToken = await TDropToken.deploy(superAdmin.address, admin.address);
await tdropToken.deployed();
await tdropToken.connect(admin).unpause();
await tdropToken.connect(admin).setAirdropper(airdropper.address);
await tdropToken.connect(airdropper).airdrop([initialHolder.address], [initialSupply]);
await tdropToken.connect(admin).setLiquidityMiner(liquidityMiner.address);
this.token = tdropToken;
});
it('has a name', async function () {
expect(await this.token.name()).to.equal(name);
});
it('has a symbol', async function () {
expect(await this.token.symbol()).to.equal(symbol);
});
it('has 18 decimals', async function () {
expect(await this.token.decimals()).to.be.equal(18);
});
describe('total supply', function () {
it('returns the total amount of tokens', async function () {
expect(await this.token.totalSupply()).to.be.equal(initialSupply);
});
});
describe('balanceOf', function () {
describe('when the requested account has no tokens', function () {
it('returns zero', async function () {
expect(await this.token.balanceOf(anotherAccount.address)).to.be.equal(0);
});
});
describe('when the requested account has some tokens', function () {
it('returns the total amount of tokens', async function () {
expect(await this.token.balanceOf(initialHolder.address)).to.be.equal(initialSupply);
});
});
});
describe('transfer from', function () {
describe('when the token owner is not the zero address', function () {
describe('when the recipient is not the zero address', function () {
describe('when the spender has enough approved balance', function () {
beforeEach(async function () {
const spender = recipient;
await this.token.connect(initialHolder).approve(spender.address, initialSupply);
});
describe('when the token owner has enough balance', function () {
it('transfers the requested amount', async function () {
const tokenOwner = initialHolder;
const to = anotherAccount;
const amount = initialSupply;
const spender = recipient;
await this.token.connect(spender).transferFrom(tokenOwner.address, to.address, amount);
expect(await this.token.balanceOf(tokenOwner.address)).to.be.equal(0);
expect(await this.token.balanceOf(to.address)).to.be.equal(amount);
});
it('decreases the spender allowance', async function () {
const tokenOwner = initialHolder;
const to = anotherAccount;
const amount = initialSupply;
const spender = recipient;
await this.token.connect(spender).transferFrom(tokenOwner.address, to.address, amount);
expect(await this.token.allowance(tokenOwner.address, spender.address)).to.be.equal(0);
});
});
describe('when the token owner does not have enough balance', function () {
it('reverts', async function () {
const tokenOwner = initialHolder;
const to = anotherAccount;
const amount = initialSupply + 1;
const spender = recipient;
await expect(this.token.connect(spender).transferFrom(tokenOwner.address, to.address, amount)).to.be.reverted;
});
});
});
describe('when the spender does not have enough approved balance', function () {
beforeEach(async function () {
const tokenOwner = initialHolder;
const spender = recipient;
await this.token.connect(tokenOwner).approve(spender.address, initialSupply - 1);
});
describe('when the token owner has enough balance', function () {
it('reverts', async function () {
const tokenOwner = initialHolder;
const to = anotherAccount;
const amount = initialSupply;
const spender = recipient;
await expect(this.token.connect(spender).transferFrom(tokenOwner.address, to.address, amount)).to.be.reverted;
});
});
describe('when the token owner does not have enough balance', function () {
it('reverts', async function () {
const amount = initialSupply + 1;
const tokenOwner = initialHolder;
const to = anotherAccount;
const spender = recipient;
await expect(this.token.connect(spender).transferFrom(tokenOwner.address, to.address, amount)).to.be.reverted;
});
});
});
});
describe('when the recipient is the zero address', function () {
beforeEach(async function () {
const amount = initialSupply;
const to = ZERO_ADDRESS;
const tokenOwner = initialHolder;
const spender = recipient;
await this.token.connect(tokenOwner).approve(spender.address, amount);
});
it('reverts', async function () {
const amount = initialSupply;
const to = ZERO_ADDRESS;
const tokenOwner = initialHolder;
const spender = recipient;
await expect(this.token.connect(spender).transferFrom(tokenOwner.address, to.address, amount)).to.be.reverted
});
});
});
describe('when the token owner is the zero address', function () {
it('reverts', async function () {
const amount = 0;
const tokenOwner = ZERO_ADDRESS;
const to = recipient;
const spender = recipient;
await expect(this.token.connect(spender).transferFrom(tokenOwner.address, to.address, amount)).to.be.reverted
});
});
});
describe('_mint', function () {
const amount = 50;
it('rejects a null account', async function () {ZERO_ADDRESS
await expect(this.token.connect(ZERO_ADDRESS).mine(amount)).to.be.reverted
});
describe('for a non zero account', function () {
beforeEach('minting', async function () {
await this.token.connect(liquidityMiner).mine(recipient.address, amount);
});
it('increments totalSupply', async function () {
const expectedSupply = initialSupply + amount;
expect(await this.token.totalSupply()).to.be.equal(expectedSupply);
});
it('increments recipient balance', async function () {
expect(await this.token.balanceOf(recipient.address)).to.be.equal(amount);
});
});
});
describe('transfer', function () {
describe('when the recipient is not the zero address', function () {
describe('when the sender does not have enough balance', function () {
const amount = initialSupply + 1;
it('reverts', async function () {
const to = recipient;
await expect(this.token.connect(initialHolder).transfer(to.address, amount)).to.be.reverted;
});
});
describe('when the sender transfers all balance', function () {
const amount = initialSupply;
it('transfers the requested amount', async function () {
const to = recipient;
await this.token.connect(initialHolder).transfer(to.address, amount)
expect(await this.token.balanceOf(initialHolder.address)).to.be.equal(0);
expect(await this.token.balanceOf(to.address)).to.be.equal(amount);
});
});
describe('when the sender transfers zero tokens', function () {
const amount = 0;
it('transfers the requested amount', async function () {
const to = recipient;
await this.token.connect(initialHolder).transfer(to.address, amount)
expect(await this.token.balanceOf(initialHolder.address)).to.be.equal(initialSupply);
expect(await this.token.balanceOf(to.address)).to.be.equal(0);
});
});
});
describe('when the recipient is the zero address', function () {
it('reverts', async function () {
const amount = 10;
await expect(this.token.connect(initialHolder).transfer(ZERO_ADDRESS, amount)).to.be.reverted
});
});
});
describe('approve', function () {
describe('when the spender is not the zero address', function () {
describe('when the sender has enough balance', function () {
const amount = initialSupply;
describe('when there was no approved amount before', function () {
it('approves the requested amount', async function () {
const owner = initialHolder;
const spender = recipient;
await this.token.connect(owner).approve(spender.address, amount);
expect(await this.token.allowance(owner.address, spender.address)).to.be.equal(amount);
});
});
describe('when the spender had an approved amount', function () {
beforeEach(async function () {
const owner = initialHolder;
const spender = recipient;
await this.token.connect(owner).approve(spender.address, 1);
});
it('approves the requested amount and replaces the previous one', async function () {
const owner = initialHolder;
const spender = recipient;
await this.token.connect(owner).approve(spender.address, amount);
expect(await this.token.allowance(owner.address, spender.address)).to.be.equal(amount);
});
});
});
describe('when the sender does not have enough balance', function () {
const amount = initialSupply + 1;
describe('when there was no approved amount before', function () {
it('approves the requested amount', async function () {
const owner = initialHolder;
const spender = recipient;
await this.token.connect(owner).approve(spender.address, amount);
expect(await this.token.allowance(owner.address, spender.address)).to.be.equal(amount);
});
});
describe('when the spender had an approved amount', function () {
beforeEach(async function () {
const owner = initialHolder;
const spender = recipient;
await this.token.connect(owner).approve(spender.address, 1);
});
it('approves the requested amount and replaces the previous one', async function () {
const owner = initialHolder;
const spender = recipient;
await this.token.connect(owner).approve(spender.address, amount);
expect(await this.token.allowance(owner.address, spender.address)).to.be.equal(amount);
});
});
});
});
});
});