-
Notifications
You must be signed in to change notification settings - Fork 104
/
Copy pathgho-variable-debt.test.ts
236 lines (193 loc) · 8.4 KB
/
gho-variable-debt.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
import hre from 'hardhat';
import { expect } from 'chai';
import { makeSuite, TestEnv } from './helpers/make-suite';
import { impersonateAccountHardhat } from '../helpers/misc-utils';
import { ONE_ADDRESS, ZERO_ADDRESS } from '../helpers/constants';
import { GhoVariableDebtToken__factory } from '../types';
import { ProtocolErrors } from '@aave/core-v3';
import {
INITIALIZED,
CALLER_NOT_DISCOUNT_TOKEN,
CALLER_NOT_A_TOKEN,
ZERO_ADDRESS_NOT_VALID,
} from './helpers/constants';
makeSuite('Gho VariableDebtToken End-To-End', (testEnv: TestEnv) => {
let ethers;
let poolSigner;
const testAddressOne = '0x2acAb3DEa77832C09420663b0E1cB386031bA17B';
const testAddressTwo = '0x6fC355D4e0EE44b292E50878F49798ff755A5bbC';
before(async () => {
ethers = hre.ethers;
const { pool } = testEnv;
poolSigner = await impersonateAccountHardhat(pool.address);
});
it('Initialize when already initialized (revert expected)', async function () {
const { variableDebtToken } = testEnv;
await expect(
variableDebtToken.initialize(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 variableDebtToken = await new GhoVariableDebtToken__factory(deployer.signer).deploy(
pool.address
);
await expect(
variableDebtToken.initialize(ZERO_ADDRESS, ZERO_ADDRESS, ZERO_ADDRESS, 0, 'test', 'test', [])
).to.be.revertedWith(ProtocolErrors.POOL_ADDRESSES_DO_NOT_MATCH);
});
it('Update discount distribution - not permissioned (revert expected)', async function () {
const { variableDebtToken } = testEnv;
const randomSigner = await impersonateAccountHardhat(ONE_ADDRESS);
const randomAddress = ONE_ADDRESS;
const randomNumber = '0';
await expect(
variableDebtToken
.connect(randomSigner)
.updateDiscountDistribution(
randomAddress,
randomAddress,
randomNumber,
randomNumber,
randomNumber
)
).to.be.revertedWith(CALLER_NOT_DISCOUNT_TOKEN);
});
it('Decrease Balance from Interest - not permissioned (revert expected)', async function () {
const { variableDebtToken } = testEnv;
const randomSigner = await impersonateAccountHardhat(ONE_ADDRESS);
const randomAddress = ONE_ADDRESS;
const randomNumber = '0';
await expect(
variableDebtToken
.connect(randomSigner)
.decreaseBalanceFromInterest(randomAddress, randomNumber)
).to.be.revertedWith(CALLER_NOT_A_TOKEN);
});
it('Check operations not permitted (revert expected)', async () => {
const { variableDebtToken } = testEnv;
const randomAddress = ONE_ADDRESS;
const randomNumber = '0';
const calls = [
{ fn: 'transfer', args: [randomAddress, randomNumber] },
{ fn: 'allowance', args: [randomAddress, randomAddress] },
{ fn: 'approve', args: [randomAddress, randomNumber] },
{ fn: 'transferFrom', args: [randomAddress, randomAddress, randomNumber] },
{ fn: 'increaseAllowance', args: [randomAddress, randomNumber] },
{ fn: 'decreaseAllowance', args: [randomAddress, randomNumber] },
];
for (const call of calls) {
await expect(variableDebtToken.connect(poolSigner)[call.fn](...call.args)).to.be.revertedWith(
ProtocolErrors.OPERATION_NOT_SUPPORTED
);
}
});
it('Check permission of onlyPool modified functions (revert expected)', async () => {
const { variableDebtToken, 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, randomNumber, randomNumber] },
];
for (const call of calls) {
await expect(
variableDebtToken.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 { variableDebtToken, users } = testEnv;
const nonPoolAdmin = users[2];
const randomAddress = ONE_ADDRESS;
const randomNumber = '0';
const calls = [
{ fn: 'setAToken', args: [randomAddress] },
{ fn: 'updateDiscountRateStrategy', args: [randomAddress] },
{ fn: 'updateDiscountToken', args: [randomAddress] },
];
for (const call of calls) {
await expect(
variableDebtToken.connect(nonPoolAdmin.signer)[call.fn](...call.args)
).to.be.revertedWith(ProtocolErrors.CALLER_NOT_POOL_ADMIN);
}
});
it('Get AToken', async function () {
const { variableDebtToken, aToken } = testEnv;
const aTokenAddress = await variableDebtToken.getAToken();
expect(aTokenAddress).to.be.equal(aToken.address);
});
it('Get Discount Rate Strategy', async function () {
const { variableDebtToken, discountRateStrategy } = testEnv;
const discountToken = await variableDebtToken.getDiscountRateStrategy();
expect(discountToken).to.be.equal(discountRateStrategy.address);
});
it('Set ZERO address as AToken (revert expected)', async function () {
const {
users: [user1],
pool,
poolAdmin,
} = testEnv;
const newGhoAToken = await new GhoVariableDebtToken__factory(user1.signer).deploy(pool.address);
await expect(newGhoAToken.connect(poolAdmin.signer).setAToken(ZERO_ADDRESS)).to.be.revertedWith(
ZERO_ADDRESS_NOT_VALID
);
});
it('Set AToken - already set (revert expected)', async function () {
const { variableDebtToken, poolAdmin } = testEnv;
await expect(
variableDebtToken.connect(poolAdmin.signer).setAToken(ONE_ADDRESS)
).to.be.revertedWith('ATOKEN_ALREADY_SET');
});
it('Set Discount Strategy', async function () {
const { variableDebtToken, deployer, discountRateStrategy } = testEnv;
await expect(variableDebtToken.connect(deployer.signer).updateDiscountRateStrategy(ONE_ADDRESS))
.to.emit(variableDebtToken, 'DiscountRateStrategyUpdated')
.withArgs(discountRateStrategy.address, ONE_ADDRESS);
});
it('Get Discount Strategy - after setting', async function () {
const { variableDebtToken } = testEnv;
expect(await variableDebtToken.getDiscountRateStrategy()).to.be.equal(ONE_ADDRESS);
});
it('Set ZERO address as Discount Strategy (revert expected)', async function () {
const { variableDebtToken, deployer } = testEnv;
await expect(
variableDebtToken.connect(deployer.signer).updateDiscountRateStrategy(ZERO_ADDRESS)
).to.be.revertedWith(ZERO_ADDRESS_NOT_VALID);
});
it('Set Discount Strategy - not permissioned (revert expected)', async function () {
const { variableDebtToken } = testEnv;
const randomSigner = await impersonateAccountHardhat(testAddressTwo);
await expect(
variableDebtToken.connect(randomSigner).updateDiscountRateStrategy(ONE_ADDRESS)
).to.be.revertedWith(ProtocolErrors.CALLER_NOT_POOL_ADMIN);
});
it('Set ZERO address as Discount Token (revert expected)', async function () {
const { variableDebtToken, deployer } = testEnv;
await expect(
variableDebtToken.connect(deployer.signer).updateDiscountToken(ZERO_ADDRESS)
).to.be.revertedWith(ZERO_ADDRESS_NOT_VALID);
});
it('Get Discount Token - before setting', async function () {
const { variableDebtToken, stakedAave } = testEnv;
expect(await variableDebtToken.getDiscountToken()).to.be.equal(stakedAave.address);
});
it('Set Discount Token', async function () {
const { variableDebtToken, stakedAave, deployer } = testEnv;
await expect(variableDebtToken.connect(deployer.signer).updateDiscountToken(testAddressOne))
.to.emit(variableDebtToken, 'DiscountTokenUpdated')
.withArgs(stakedAave.address, testAddressOne);
});
it('Get Discount Token - after setting', async function () {
const { variableDebtToken } = testEnv;
expect(await variableDebtToken.getDiscountToken()).to.be.equal(testAddressOne);
});
it('Set Discount Token - not permissioned (revert expected)', async function () {
const { variableDebtToken } = testEnv;
const randomSigner = await impersonateAccountHardhat(testAddressTwo);
await expect(
variableDebtToken.connect(randomSigner).updateDiscountToken(ONE_ADDRESS)
).to.be.revertedWith(ProtocolErrors.CALLER_NOT_POOL_ADMIN);
});
});