-
Notifications
You must be signed in to change notification settings - Fork 104
/
Copy pathgho-atoken.test.ts
304 lines (252 loc) · 9.78 KB
/
gho-atoken.test.ts
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
import hre from 'hardhat';
import { expect } from 'chai';
import { impersonateAccountHardhat } from '../helpers/misc-utils';
import { makeSuite, TestEnv } from './helpers/make-suite';
import { ONE_ADDRESS, ZERO_ADDRESS } from '../helpers/constants';
import { GhoAToken__factory } from '../types';
import { INITIALIZED, ZERO_ADDRESS_NOT_VALID } from './helpers/constants';
import { ProtocolErrors } from '@aave/core-v3';
makeSuite('Gho AToken End-To-End', (testEnv: TestEnv) => {
let ethers;
const testAddressOne = '0x2acAb3DEa77832C09420663b0E1cB386031bA17B';
const testAddressTwo = '0x6fC355D4e0EE44b292E50878F49798ff755A5bbC';
let poolSigner;
before(async () => {
ethers = hre.ethers;
const { pool } = testEnv;
poolSigner = await impersonateAccountHardhat(pool.address);
});
it('Initialize when already initialized (revert expected)', async function () {
const { aToken } = testEnv;
await expect(
aToken.initialize(
ZERO_ADDRESS,
ZERO_ADDRESS,
ZERO_ADDRESS,
ZERO_ADDRESS,
0,
'test',
'test',
[]
)
).to.be.revertedWith(INITIALIZED);
});
it('Initialize with incorrect pool (revert expected)', async function () {
const { deployer, pool } = testEnv;
const aToken = await new GhoAToken__factory(deployer.signer).deploy(pool.address);
await expect(
aToken.initialize(
ZERO_ADDRESS,
ZERO_ADDRESS,
ZERO_ADDRESS,
ZERO_ADDRESS,
0,
'test',
'test',
[]
)
).to.be.revertedWith(ProtocolErrors.POOL_ADDRESSES_DO_NOT_MATCH);
});
it('Checks initial parameters', async function () {
const { aToken, gho } = testEnv;
expect(await aToken.UNDERLYING_ASSET_ADDRESS()).to.be.equal(gho.address);
expect(await aToken.ATOKEN_REVISION()).to.be.equal(1);
});
it('Checks the domain separator', async () => {
const { aToken } = testEnv;
const EIP712_REVISION = '1';
const domain = {
name: await aToken.name(),
version: EIP712_REVISION,
chainId: hre.network.config.chainId,
verifyingContract: aToken.address,
};
const domainSeparator = ethers.utils._TypedDataEncoder.hashDomain(domain);
expect(await aToken.DOMAIN_SEPARATOR()).to.be.equal(domainSeparator);
});
it('Check permission of onlyPool modified functions (revert expected)', async () => {
const { aToken, users } = testEnv;
const nonPoolAdmin = users[2];
const randomAddress = ONE_ADDRESS;
const randomNumber = '0';
const calls = [
{ fn: 'mint', args: [randomAddress, randomAddress, randomNumber, randomNumber] },
{ fn: 'burn', args: [randomAddress, randomAddress, randomNumber, randomNumber] },
{ fn: 'mintToTreasury', args: [randomNumber, randomNumber] },
{ fn: 'transferOnLiquidation', args: [randomAddress, randomAddress, randomNumber] },
{ fn: 'transferUnderlyingTo', args: [randomAddress, randomNumber] },
{ fn: 'handleRepayment', args: [randomAddress, randomAddress, randomNumber] },
];
for (const call of calls) {
await expect(aToken.connect(nonPoolAdmin.signer)[call.fn](...call.args)).to.be.revertedWith(
ProtocolErrors.CALLER_MUST_BE_POOL
);
}
});
it('Check permission of onlyPoolAdmin modified functions (revert expected)', async () => {
const { aToken, users } = testEnv;
const nonPoolAdmin = users[2];
const randomAddress = ONE_ADDRESS;
const randomNumber = '0';
const calls = [
{ fn: 'rescueTokens', args: [randomAddress, randomAddress, randomNumber] },
{ fn: 'setVariableDebtToken', args: [randomAddress] },
{ fn: 'updateGhoTreasury', args: [randomAddress] },
];
for (const call of calls) {
await expect(aToken.connect(nonPoolAdmin.signer)[call.fn](...call.args)).to.be.revertedWith(
ProtocolErrors.CALLER_NOT_POOL_ADMIN
);
}
});
it('Check operations not permitted (revert expected)', async () => {
const { aToken } = testEnv;
const randomAddress = ONE_ADDRESS;
const randomNumber = '0';
const calls = [
{ fn: 'mint', args: [randomAddress, randomAddress, randomNumber, randomNumber] },
{ fn: 'burn', args: [randomAddress, randomAddress, randomNumber, randomNumber] },
{ fn: 'mintToTreasury', args: [randomNumber, randomNumber] },
{ fn: 'transferOnLiquidation', args: [randomAddress, randomAddress, randomNumber] },
{ fn: 'transfer', args: [randomAddress, 0] },
{
fn: 'permit',
args: [
randomAddress,
randomAddress,
randomNumber,
randomNumber,
randomNumber,
ethers.constants.HashZero,
ethers.constants.HashZero,
],
},
];
for (const call of calls) {
await expect(aToken.connect(poolSigner)[call.fn](...call.args)).to.be.revertedWith(
ProtocolErrors.OPERATION_NOT_SUPPORTED
);
}
});
it('Get VariableDebtToken', async function () {
const { aToken, variableDebtToken } = testEnv;
const variableDebtTokenAddress = await aToken.getVariableDebtToken();
expect(variableDebtTokenAddress).to.be.equal(variableDebtToken.address);
});
it('Get Treasury', async function () {
const { aToken, treasuryAddress } = testEnv;
const aTokenTreasuryAddress = await aToken.getGhoTreasury();
expect(aTokenTreasuryAddress).to.be.equal(treasuryAddress);
});
it('Burn AToken - not permissioned (revert expected)', async function () {
const { aToken, users } = testEnv;
await expect(
aToken.connect(users[5].signer).burn(testAddressOne, testAddressOne, 1000, 1)
).to.be.revertedWith(ProtocolErrors.CALLER_MUST_BE_POOL);
});
it('Get VariableDebtToken', async function () {
const { aToken, variableDebtToken } = testEnv;
const variableDebtTokenAddress = await aToken.getVariableDebtToken();
expect(variableDebtTokenAddress).to.be.equal(variableDebtToken.address);
});
it('Set Treasury', async function () {
const { aToken, deployer, treasuryAddress } = testEnv;
await expect(aToken.connect(deployer.signer).updateGhoTreasury(testAddressTwo))
.to.emit(aToken, 'GhoTreasuryUpdated')
.withArgs(treasuryAddress, testAddressTwo);
});
it('Get Treasury', async function () {
const { aToken } = testEnv;
const ghoTreasury = await aToken.getGhoTreasury();
expect(ghoTreasury).to.be.equal(testAddressTwo);
});
it('Set VariableDebtToken - already set (revert expected)', async function () {
const { aToken, poolAdmin } = testEnv;
await expect(
aToken.connect(poolAdmin.signer).setVariableDebtToken(testAddressTwo)
).to.be.revertedWith('VARIABLE_DEBT_TOKEN_ALREADY_SET');
});
it('Set ZERO address as VariableDebtToken (revert expected)', async function () {
const {
users: [user1],
pool,
poolAdmin,
} = testEnv;
const newGhoAToken = await new GhoAToken__factory(user1.signer).deploy(pool.address);
await expect(
newGhoAToken.connect(poolAdmin.signer).setVariableDebtToken(ZERO_ADDRESS)
).to.be.revertedWith(ZERO_ADDRESS_NOT_VALID);
});
it('Set ZERO address as Treasury (revert expected)', async function () {
const { aToken, poolAdmin } = testEnv;
await expect(
aToken.connect(poolAdmin.signer).updateGhoTreasury(ZERO_ADDRESS)
).to.be.revertedWith(ZERO_ADDRESS_NOT_VALID);
});
it('Set ZERO address as VariableDebtToken (revert expected)', async function () {
const {
users: [user1],
pool,
poolAdmin,
} = testEnv;
const newGhoAToken = await new GhoAToken__factory(user1.signer).deploy(pool.address);
await expect(
newGhoAToken.connect(poolAdmin.signer).setVariableDebtToken(ZERO_ADDRESS)
).to.be.revertedWith(ZERO_ADDRESS_NOT_VALID);
});
it('Set ZERO address as Treasury (revert expected)', async function () {
const { aToken, poolAdmin } = testEnv;
await expect(
aToken.connect(poolAdmin.signer).updateGhoTreasury(ZERO_ADDRESS)
).to.be.revertedWith(ZERO_ADDRESS_NOT_VALID);
});
it('Total Supply - always zero', async function () {
const { aToken } = testEnv;
await expect(await aToken.totalSupply()).to.be.equal(0);
});
it('User balanceOf - always zero', async function () {
const { aToken, users } = testEnv;
for (const user of users) {
await expect(await aToken.balanceOf(user.address)).to.be.eq(0);
}
});
it('User nonces - always zero', async function () {
const { aToken, users } = testEnv;
for (const user of users) {
await expect(await aToken.nonces(user.address)).to.be.eq(0);
}
});
it('PoolAdmin rescue tokens from AToken', async () => {
const {
poolAdmin,
pool,
gho,
usdc,
aToken,
users: [locker],
} = testEnv;
const amountToLock = 2;
// Lock GHO
const aTokenGhoBalanceBefore = await gho.balanceOf(aToken.address);
const aTokenSigner = await impersonateAccountHardhat(aToken.address);
expect(await gho.connect(aTokenSigner).mint(aToken.address, amountToLock));
expect(await gho.balanceOf(aToken.address)).to.be.eq(aTokenGhoBalanceBefore.add(amountToLock));
// Underlying cannot be rescued
await expect(
aToken.connect(poolAdmin.signer).rescueTokens(gho.address, locker.address, 2)
).to.be.revertedWith(ProtocolErrors.UNDERLYING_CANNOT_BE_RESCUED);
expect(await gho.balanceOf(aToken.address)).to.be.eq(aTokenGhoBalanceBefore.add(amountToLock));
// Lock USDC
const aTokenUsdcBalanceBefore = await usdc.balanceOf(aToken.address);
expect(await usdc.connect(locker.signer).transfer(aToken.address, amountToLock));
expect(await usdc.balanceOf(aToken.address)).to.be.eq(
aTokenUsdcBalanceBefore.add(amountToLock)
);
// Rescue
expect(
await aToken
.connect(poolAdmin.signer)
.rescueTokens(usdc.address, locker.address, amountToLock)
);
});
});