aave-protocol-v2/test/upgradeability.spec.ts

131 lines
4.4 KiB
TypeScript
Raw Normal View History

2020-08-10 18:20:08 +00:00
import {expect} from 'chai';
import {makeSuite, TestEnv} from './helpers/make-suite';
import {ProtocolErrors, eContractid} from '../helpers/types';
2020-10-15 17:19:02 +00:00
import {deployContract, getContract} from '../helpers/contracts-helpers';
2020-08-10 18:20:08 +00:00
import {MockAToken} from '../types/MockAToken';
import {MockStableDebtToken} from '../types/MockStableDebtToken';
import {MockVariableDebtToken} from '../types/MockVariableDebtToken';
2020-09-15 14:13:29 +00:00
import {ZERO_ADDRESS} from '../helpers/constants';
2020-10-30 12:40:06 +00:00
import {
getAToken,
getMockStableDebtToken,
getMockVariableDebtToken,
getVariableDebtToken,
} from '../helpers/contracts-getters';
import {
deployMockAToken,
deployMockStableDebtToken,
deployMockVariableDebtToken,
} from '../helpers/contracts-deployments';
2020-08-10 18:20:08 +00:00
makeSuite('Upgradeability', (testEnv: TestEnv) => {
const {LPC_CALLER_NOT_AAVE_ADMIN} = ProtocolErrors;
2020-08-10 18:20:08 +00:00
let newATokenAddress: string;
let newStableTokenAddress: string;
let newVariableTokenAddress: string;
2020-08-10 18:20:08 +00:00
before('deploying instances', async () => {
const {dai, pool} = testEnv;
2020-10-30 12:40:06 +00:00
const aTokenInstance = await deployMockAToken([
2020-08-10 18:20:08 +00:00
pool.address,
dai.address,
2020-09-21 13:52:53 +00:00
ZERO_ADDRESS,
2020-08-10 18:20:08 +00:00
'Aave Interest bearing DAI updated',
'aDAI',
2020-09-15 14:13:29 +00:00
ZERO_ADDRESS,
2020-08-10 18:20:08 +00:00
]);
2020-10-30 12:40:06 +00:00
const stableDebtTokenInstance = await deployMockStableDebtToken([
pool.address,
dai.address,
'Aave stable debt bearing DAI updated',
'stableDebtDAI',
ZERO_ADDRESS,
]);
const variableDebtTokenInstance = await deployMockVariableDebtToken([
pool.address,
dai.address,
'Aave variable debt bearing DAI updated',
'variableDebtDAI',
ZERO_ADDRESS,
]);
2020-08-10 18:20:08 +00:00
newATokenAddress = aTokenInstance.address;
newVariableTokenAddress = variableDebtTokenInstance.address;
newStableTokenAddress = stableDebtTokenInstance.address;
2020-08-10 18:20:08 +00:00
});
2020-08-10 18:20:08 +00:00
it('Tries to update the DAI Atoken implementation with a different address than the lendingPoolManager', async () => {
const {dai, configurator, users} = testEnv;
2020-08-10 18:20:08 +00:00
await expect(
configurator.connect(users[1].signer).updateAToken(dai.address, newATokenAddress)
).to.be.revertedWith(LPC_CALLER_NOT_AAVE_ADMIN);
2020-08-10 18:20:08 +00:00
});
2020-08-10 18:20:08 +00:00
it('Upgrades the DAI Atoken implementation ', async () => {
const {dai, configurator, aDai} = testEnv;
2020-08-10 18:20:08 +00:00
const name = await (await getAToken(newATokenAddress)).name();
2020-08-10 18:20:08 +00:00
await configurator.updateAToken(dai.address, newATokenAddress);
2020-08-10 18:20:08 +00:00
const tokenName = await aDai.name();
2020-08-10 18:20:08 +00:00
expect(tokenName).to.be.eq('Aave Interest bearing DAI updated', 'Invalid token name');
});
it('Tries to update the DAI Stable debt token implementation with a different address than the lendingPoolManager', async () => {
const {dai, configurator, users} = testEnv;
await expect(
configurator
.connect(users[1].signer)
.updateStableDebtToken(dai.address, newStableTokenAddress)
).to.be.revertedWith(LPC_CALLER_NOT_AAVE_ADMIN);
});
it('Upgrades the DAI stable debt token implementation ', async () => {
2020-10-12 18:07:17 +00:00
const {dai, configurator, pool, helpersContract} = testEnv;
const name = await (await getAToken(newATokenAddress)).name();
await configurator.updateStableDebtToken(dai.address, newStableTokenAddress);
2020-10-12 18:07:17 +00:00
const {stableDebtTokenAddress} = await helpersContract.getReserveTokensAddresses(dai.address);
2020-10-30 12:40:06 +00:00
const debtToken = await getMockStableDebtToken(stableDebtTokenAddress);
const tokenName = await debtToken.name();
expect(tokenName).to.be.eq('Aave stable debt bearing DAI updated', 'Invalid token name');
});
it('Tries to update the DAI variable debt token implementation with a different address than the lendingPoolManager', async () => {
const {dai, configurator, users} = testEnv;
await expect(
configurator
.connect(users[1].signer)
.updateVariableDebtToken(dai.address, newVariableTokenAddress)
).to.be.revertedWith(LPC_CALLER_NOT_AAVE_ADMIN);
});
it('Upgrades the DAI variable debt token implementation ', async () => {
2020-10-12 18:07:17 +00:00
const {dai, configurator, pool, helpersContract} = testEnv;
const name = await (await getAToken(newATokenAddress)).name();
await configurator.updateVariableDebtToken(dai.address, newVariableTokenAddress);
2020-10-12 18:07:17 +00:00
const {variableDebtTokenAddress} = await helpersContract.getReserveTokensAddresses(dai.address);
2020-10-30 12:40:06 +00:00
const debtToken = await getMockVariableDebtToken(variableDebtTokenAddress);
const tokenName = await debtToken.name();
expect(tokenName).to.be.eq('Aave variable debt bearing DAI updated', 'Invalid token name');
});
2020-08-10 18:20:08 +00:00
});