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

235 lines
7.3 KiB
TypeScript
Raw Normal View History

import { expect } from 'chai';
import { makeSuite, TestEnv } from './helpers/make-suite';
import { ProtocolErrors, eContractid } from '../helpers/types';
import { deployContract, getContract } from '../helpers/contracts-helpers';
import { MockAToken } from '../types/MockAToken';
import { MockStableDebtToken } from '../types/MockStableDebtToken';
import { MockVariableDebtToken } from '../types/MockVariableDebtToken';
import { ZERO_ADDRESS } from '../helpers/constants';
2020-10-30 12:40:06 +00:00
import {
getAToken,
getMockStableDebtToken,
getMockVariableDebtToken,
2021-02-02 22:44:46 +00:00
getStableDebtToken,
2020-10-30 12:40:06 +00:00
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 { CALLER_NOT_POOL_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,
2021-02-02 22:44:46 +00:00
ZERO_ADDRESS,
2020-08-10 18:20:08 +00:00
'Aave Interest bearing DAI updated',
'aDAI',
]);
2020-10-30 12:40:06 +00:00
const stableDebtTokenInstance = await deployMockStableDebtToken([
pool.address,
dai.address,
2021-02-02 22:44:46 +00:00
ZERO_ADDRESS,
2020-10-30 12:40:06 +00:00
'Aave stable debt bearing DAI updated',
'stableDebtDAI',
]);
const variableDebtTokenInstance = await deployMockVariableDebtToken([
pool.address,
dai.address,
2021-02-02 22:44:46 +00:00
ZERO_ADDRESS,
2020-10-30 12:40:06 +00:00
'Aave variable debt bearing DAI updated',
'variableDebtDAI',
]);
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;
2021-02-02 22:44:46 +00:00
const name = await (await getAToken(newATokenAddress)).name();
const symbol = await (await getAToken(newATokenAddress)).symbol();
const updateATokenInputParams: {
asset: string;
treasury: string;
incentivesController: string;
name: string;
symbol: string;
implementation: string;
} = {
asset: dai.address,
treasury: ZERO_ADDRESS,
incentivesController: ZERO_ADDRESS,
name: name,
symbol: symbol,
implementation: newATokenAddress,
};
2020-08-10 18:20:08 +00:00
await expect(
2021-02-02 22:44:46 +00:00
configurator.connect(users[1].signer).updateAToken(updateATokenInputParams)
2020-11-05 11:35:50 +00:00
).to.be.revertedWith(CALLER_NOT_POOL_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();
2021-02-02 22:44:46 +00:00
const symbol = await (await getAToken(newATokenAddress)).symbol();
const updateATokenInputParams: {
asset: string;
treasury: string;
incentivesController: string;
name: string;
symbol: string;
implementation: string;
} = {
asset: dai.address,
treasury: ZERO_ADDRESS,
incentivesController: ZERO_ADDRESS,
name: name,
symbol: symbol,
implementation: newATokenAddress,
};
await configurator.updateAToken(updateATokenInputParams);
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;
2021-02-02 22:44:46 +00:00
const name = await (await getStableDebtToken(newStableTokenAddress)).name();
const symbol = await (await getStableDebtToken(newStableTokenAddress)).symbol();
const updateDebtTokenInput: {
asset: string;
incentivesController: string;
name: string;
symbol: string;
implementation: string;
} = {
asset: dai.address,
incentivesController: ZERO_ADDRESS,
name: name,
symbol: symbol,
implementation: newStableTokenAddress,
}
await expect(
configurator
.connect(users[1].signer)
2021-02-02 22:44:46 +00:00
.updateStableDebtToken(updateDebtTokenInput)
2020-11-05 11:35:50 +00:00
).to.be.revertedWith(CALLER_NOT_POOL_ADMIN);
});
it('Upgrades the DAI stable debt token implementation ', async () => {
const { dai, configurator, pool, helpersContract } = testEnv;
2021-02-02 22:44:46 +00:00
const name = await (await getStableDebtToken(newStableTokenAddress)).name();
const symbol = await (await getStableDebtToken(newStableTokenAddress)).symbol();
const updateDebtTokenInput: {
asset: string;
incentivesController: string;
name: string;
symbol: string;
implementation: string;
} = {
asset: dai.address,
incentivesController: ZERO_ADDRESS,
name: name,
symbol: symbol,
implementation: newStableTokenAddress,
}
await configurator.updateStableDebtToken(updateDebtTokenInput);
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;
2021-02-02 22:44:46 +00:00
const name = await (await getVariableDebtToken(newVariableTokenAddress)).name();
const symbol = await (await getVariableDebtToken(newVariableTokenAddress)).symbol();
const updateDebtTokenInput: {
asset: string;
incentivesController: string;
name: string;
symbol: string;
implementation: string;
} = {
asset: dai.address,
incentivesController: ZERO_ADDRESS,
name: name,
symbol: symbol,
implementation: newVariableTokenAddress,
}
await expect(
configurator
.connect(users[1].signer)
2021-02-02 22:44:46 +00:00
.updateVariableDebtToken(updateDebtTokenInput)
2020-11-05 11:35:50 +00:00
).to.be.revertedWith(CALLER_NOT_POOL_ADMIN);
});
it('Upgrades the DAI variable debt token implementation ', async () => {
2020-10-12 18:07:17 +00:00
const {dai, configurator, pool, helpersContract} = testEnv;
2021-02-02 22:44:46 +00:00
const name = await (await getVariableDebtToken(newVariableTokenAddress)).name();
const symbol = await (await getVariableDebtToken(newVariableTokenAddress)).symbol();
const updateDebtTokenInput: {
asset: string;
incentivesController: string;
name: string;
symbol: string;
implementation: string;
} = {
asset: dai.address,
incentivesController: ZERO_ADDRESS,
name: name,
symbol: symbol,
implementation: newVariableTokenAddress,
}
//const name = await (await getAToken(newATokenAddress)).name();
await configurator.updateVariableDebtToken(updateDebtTokenInput);
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
});