All tests working. WIP look at old error messages to remove them all

This commit is contained in:
pol 2020-09-02 17:54:34 +02:00
parent 6122826ef4
commit 76b4fc6b2d
11 changed files with 136 additions and 116 deletions

View File

@ -5,6 +5,7 @@ import {Ownable} from '@openzeppelin/contracts/access/Ownable.sol';
import { import {
ILendingPoolAddressesProviderRegistry ILendingPoolAddressesProviderRegistry
} from '../interfaces/ILendingPoolAddressesProviderRegistry.sol'; } from '../interfaces/ILendingPoolAddressesProviderRegistry.sol';
import {Errors} from '../libraries/helpers/Errors.sol';
/** /**
* @title LendingPoolAddressesProviderRegistry contract * @title LendingPoolAddressesProviderRegistry contract
@ -16,9 +17,6 @@ contract LendingPoolAddressesProviderRegistry is Ownable, ILendingPoolAddressesP
mapping(address => uint256) addressesProviders; mapping(address => uint256) addressesProviders;
address[] addressesProvidersList; address[] addressesProvidersList;
//require error messages
string private constant PROVIDER_NOT_REGISTERED = '1'; // 'Provider is not registered'
/** /**
* @dev returns if an addressesProvider is registered or not * @dev returns if an addressesProvider is registered or not
* @param provider the addresses provider * @param provider the addresses provider
@ -66,7 +64,7 @@ contract LendingPoolAddressesProviderRegistry is Ownable, ILendingPoolAddressesP
* @param provider the pool address to be unregistered * @param provider the pool address to be unregistered
**/ **/
function unregisterAddressesProvider(address provider) external override onlyOwner { function unregisterAddressesProvider(address provider) external override onlyOwner {
require(addressesProviders[provider] > 0, PROVIDER_NOT_REGISTERED); require(addressesProviders[provider] > 0, Errors.PROVIDER_NOT_REGISTERED);
addressesProviders[provider] = 0; addressesProviders[provider] = 0;
emit AddressesProviderUnregistered(provider); emit AddressesProviderUnregistered(provider);
} }

View File

@ -13,6 +13,7 @@ import {ReserveConfiguration} from '../libraries/configuration/ReserveConfigurat
import {ILendingPoolAddressesProvider} from '../interfaces/ILendingPoolAddressesProvider.sol'; import {ILendingPoolAddressesProvider} from '../interfaces/ILendingPoolAddressesProvider.sol';
import {ILendingPool} from '../interfaces/ILendingPool.sol'; import {ILendingPool} from '../interfaces/ILendingPool.sol';
import {IERC20Detailed} from '../interfaces/IERC20Detailed.sol'; import {IERC20Detailed} from '../interfaces/IERC20Detailed.sol';
import {Errors} from '../libraries/helpers/Errors.sol';
/** /**
* @title LendingPoolConfigurator contract * @title LendingPoolConfigurator contract
@ -25,10 +26,6 @@ contract LendingPoolConfigurator is VersionedInitializable {
using SafeMath for uint256; using SafeMath for uint256;
using ReserveConfiguration for ReserveConfiguration.Map; using ReserveConfiguration for ReserveConfiguration.Map;
//require error messages
string private constant CALLER_NOT_LENDING_POOL_MANAGER = '1'; // 'The caller must be a lending pool manager'
string private constant RESERVE_LIQUIDITY_NOT_0 = '2'; // 'The liquidity of the reserve needs to be 0'
/** /**
* @dev emitted when a reserve is initialized. * @dev emitted when a reserve is initialized.
* @param asset the address of the reserve * @param asset the address of the reserve
@ -182,7 +179,7 @@ contract LendingPoolConfigurator is VersionedInitializable {
modifier onlyLendingPoolManager { modifier onlyLendingPoolManager {
require( require(
addressesProvider.getLendingPoolManager() == msg.sender, addressesProvider.getLendingPoolManager() == msg.sender,
CALLER_NOT_LENDING_POOL_MANAGER Errors.CALLER_NOT_LENDING_POOL_MANAGER
); );
_; _;
} }
@ -429,7 +426,7 @@ contract LendingPoolConfigurator is VersionedInitializable {
) = pool.getReserveData(asset); ) = pool.getReserveData(asset);
require( require(
availableLiquidity == 0 && totalBorrowsStable == 0 && totalBorrowsVariable == 0, availableLiquidity == 0 && totalBorrowsStable == 0 && totalBorrowsVariable == 0,
RESERVE_LIQUIDITY_NOT_0 Errors.RESERVE_LIQUIDITY_NOT_0
); );
ReserveConfiguration.Map memory currentConfig = pool.getConfiguration(asset); ReserveConfiguration.Map memory currentConfig = pool.getConfiguration(asset);

View File

@ -39,10 +39,19 @@ library Errors {
// require error messages - aToken // require error messages - aToken
string public constant CALLER_MUST_BE_LENDING_POOL = '27'; // 'The caller of this function must be a lending pool' string public constant CALLER_MUST_BE_LENDING_POOL = '27'; // 'The caller of this function must be a lending pool'
string public constant TRANSFER_CANNOT_BE_ALLOWED = '28'; // 'Transfer cannot be allowed.' string public constant NOT_ALLOWED_TO_REDIRECT_INTEREST = '28'; // 'Caller is not allowed to redirect the interest of the user'
string public constant NOT_ALLOWED_TO_REDIRECT_INTEREST = '29'; // 'Caller is not allowed to redirect the interest of the user' string public constant CANNOT_GIVE_ALLOWANCE_TO_HIMSELF = '29'; // 'User cannot give allowance to himself'
string public constant CANNOT_GIVE_ALLOWANCE_TO_HIMSELF = '30'; // 'User cannot give allowance to himself' string public constant TRANSFER_AMOUNT_NOT_GT_0 = '30'; // 'Transferred amount needs to be greater than zero'
string public constant TRANSFER_AMOUNT_NOT_GT_0 = '31'; // 'Transferred amount needs to be greater than zero' string public constant INTEREST_ALREADY_REDIRECTED = '31'; // 'Interest is already redirected to the user'
string public constant INTEREST_ALREADY_REDIRECTED = '32'; // 'Interest is already redirected to the user' string public constant NO_VALID_BALANCE_FOR_REDIRECT_INT_STREAM = '32'; // 'Interest stream can only be redirected if there is a valid balance'
string public constant NO_VALID_BALANCE_FOR_REDIRECT_INT_STREAM = '33'; // 'Interest stream can only be redirected if there is a valid balance'
// require error messages - ReserveLogic
string public constant RESERVE_ALREADY_INITIALIZED = '33'; // 'Reserve has already been initialized'
//require error messages - LendingPoolConfiguration
string public constant CALLER_NOT_LENDING_POOL_MANAGER = '34'; // 'The caller must be a lending pool manager'
string public constant RESERVE_LIQUIDITY_NOT_0 = '35'; // 'The liquidity of the reserve needs to be 0'
//require error messages - LendingPoolAddressesProviderRegistry
string public constant PROVIDER_NOT_REGISTERED = '36'; // 'Provider is not registered'
} }

View File

@ -10,6 +10,7 @@ import {IStableDebtToken} from '../../tokenization/interfaces/IStableDebtToken.s
import {ReserveConfiguration} from '../configuration/ReserveConfiguration.sol'; import {ReserveConfiguration} from '../configuration/ReserveConfiguration.sol';
import {IReserveInterestRateStrategy} from '../../interfaces/IReserveInterestRateStrategy.sol'; import {IReserveInterestRateStrategy} from '../../interfaces/IReserveInterestRateStrategy.sol';
import {WadRayMath} from '../math/WadRayMath.sol'; import {WadRayMath} from '../math/WadRayMath.sol';
import {Errors} from '../helpers/Errors.sol';
/** /**
* @title ReserveLogic library * @title ReserveLogic library
@ -21,9 +22,6 @@ library ReserveLogic {
using WadRayMath for uint256; using WadRayMath for uint256;
using SafeERC20 for IERC20; using SafeERC20 for IERC20;
//require error messages
string private constant RESERVE_ALREADY_INITIALIZED = '1'; // 'Reserve has already been initialized'
/** /**
* @dev Emitted when the state of a reserve is updated * @dev Emitted when the state of a reserve is updated
* @param reserve the address of the reserve * @param reserve the address of the reserve
@ -183,7 +181,7 @@ library ReserveLogic {
address variableDebtTokenAddress, address variableDebtTokenAddress,
address interestRateStrategyAddress address interestRateStrategyAddress
) external { ) external {
require(reserve.aTokenAddress == address(0), RESERVE_ALREADY_INITIALIZED); require(reserve.aTokenAddress == address(0), Errors.RESERVE_ALREADY_INITIALIZED);
if (reserve.lastLiquidityIndex == 0) { if (reserve.lastLiquidityIndex == 0) {
//if the reserve has not been initialized yet //if the reserve has not been initialized yet
reserve.lastLiquidityIndex = WadRayMath.ray(); reserve.lastLiquidityIndex = WadRayMath.ray();

View File

@ -40,7 +40,7 @@ contract AToken is VersionedInitializable, ERC20, IAToken {
} }
modifier whenTransferAllowed(address from, uint256 amount) { modifier whenTransferAllowed(address from, uint256 amount) {
require(isTransferAllowed(from, amount), Errors.TRANSFER_CANNOT_BE_ALLOWED); require(isTransferAllowed(from, amount), Errors.TRANSFER_NOT_ALLOWED);
_; _;
} }

View File

@ -9,6 +9,7 @@ import {
VersionedInitializable VersionedInitializable
} from '../../libraries/openzeppelin-upgradeability/VersionedInitializable.sol'; } from '../../libraries/openzeppelin-upgradeability/VersionedInitializable.sol';
import {IERC20Detailed} from '../../interfaces/IERC20Detailed.sol'; import {IERC20Detailed} from '../../interfaces/IERC20Detailed.sol';
import {Errors} from '../../libraries/helpers/Errors.sol';
/** /**
* @title contract DebtTokenBase * @title contract DebtTokenBase
@ -33,7 +34,7 @@ abstract contract DebtTokenBase is IERC20Detailed, VersionedInitializable {
* @dev only lending pool can call functions marked by this modifier * @dev only lending pool can call functions marked by this modifier
**/ **/
modifier onlyLendingPool { modifier onlyLendingPool {
require(msg.sender == address(_pool), 'The caller of this function must be a lending pool'); require(msg.sender == address(_pool), Errors.CALLER_MUST_BE_LENDING_POOL);
_; _;
} }

View File

@ -76,30 +76,39 @@ export enum ProtocolErrors {
// require error messages - aToken // require error messages - aToken
CALLER_MUST_BE_LENDING_POOL = '27', // 'The caller of this function must be a lending pool' CALLER_MUST_BE_LENDING_POOL = '27', // 'The caller of this function must be a lending pool'
TRANSFER_CANNOT_BE_ALLOWED = '28', // 'Transfer cannot be allowed.' NOT_ALLOWED_TO_REDIRECT_INTEREST = '28', // 'Caller is not allowed to redirect the interest of the user'
NOT_ALLOWED_TO_REDIRECT_INTEREST = '29', // 'Caller is not allowed to redirect the interest of the user' CANNOT_GIVE_ALLOWANCE_TO_HIMSELF = '29', // 'User cannot give allowance to himself'
CANNOT_GIVE_ALLOWANCE_TO_HIMSELF = '30', // 'User cannot give allowance to himself' TRANSFER_AMOUNT_NOT_GT_0 = '30', // 'Transferred amount needs to be greater than zero'
TRANSFER_AMOUNT_NOT_GT_0 = '31', // 'Transferred amount needs to be greater than zero' INTEREST_ALREADY_REDIRECTED = '31', // 'Interest is already redirected to the user'
INTEREST_ALREADY_REDIRECTED = '32', // 'Interest is already redirected to the user' NO_VALID_BALANCE_FOR_REDIRECT_INT_STREAM = '32', // 'Interest stream can only be redirected if there is a valid balance'
NO_VALID_BALANCE_FOR_REDIRECT_INT_STREAM = '33', // 'Interest stream can only be redirected if there is a valid balance'
// require error messages - ReserveLogic
RESERVE_ALREADY_INITIALIZED = '33', // 'Reserve has already been initialized'
//require error messages - LendingPoolConfiguration
CALLER_NOT_LENDING_POOL_MANAGER = '34', // 'The caller must be a lending pool manager'
RESERVE_LIQUIDITY_NOT_0 = '35', // 'The liquidity of the reserve needs to be 0'
//require error messages - LendingPoolAddressesProviderRegistry
PROVIDER_NOT_REGISTERED = '36', // 'Provider is not registered'
// old // old
INVALID_CONFIGURATOR_CALLER_MSG = 'The caller must be a lending pool configurator contract', INVALID_CONFIGURATOR_CALLER_MSG = 'The caller must be a lending pool configurator contract',
INVALID_POOL_CALLER_MSG = 'The caller must be a lending pool contract', INVALID_POOL_CALLER_MSG = 'The caller must be a lending pool contract',
// INVALID_POOL_CALLER_MSG_1 = 'The caller of this function must be a lending pool', => CALLER_MUST_BE_LENDING_POOL // INVALID_POOL_CALLER_MSG_1 = 'The caller of this function must be a lending pool', => 27
INVALID_POOL_MANAGER_CALLER_MSG = 'The caller must be a lending pool manager', // INVALID_POOL_MANAGER_CALLER_MSG = 'The caller must be a lending pool manager', => 34
INVALID_FROM_BALANCE_AFTER_TRANSFER = 'Invalid from balance after transfer', INVALID_FROM_BALANCE_AFTER_TRANSFER = 'Invalid from balance after transfer',
INVALID_TO_BALANCE_AFTER_TRANSFER = 'Invalid from balance after transfer', INVALID_TO_BALANCE_AFTER_TRANSFER = 'Invalid from balance after transfer',
INVALID_OWNER_REVERT_MSG = 'Ownable: caller is not the owner', INVALID_OWNER_REVERT_MSG = 'Ownable: caller is not the owner',
INVALID_REDIRECTED_BALANCE_BEFORE_TRANSFER = 'Invalid redirected balance before transfer', INVALID_REDIRECTED_BALANCE_BEFORE_TRANSFER = 'Invalid redirected balance before transfer',
INVALID_REDIRECTED_BALANCE_AFTER_TRANSFER = 'Invalid redirected balance after transfer', INVALID_REDIRECTED_BALANCE_AFTER_TRANSFER = 'Invalid redirected balance after transfer',
INVALID_REDIRECTION_ADDRESS = 'Invalid redirection address', INVALID_REDIRECTION_ADDRESS = 'Invalid redirection address',
TRANSFERRED_AMOUNT_GT_ZERO = 'Transferred amount needs to be greater than zero', // TRANSFERRED_AMOUNT_GT_ZERO = 'Transferred amount needs to be greater than zero', => 30
ZERO_COLLATERAL = 'The collateral balance is 0', // ZERO_COLLATERAL = 'The collateral balance is 0',
INCONSISTENT_PROTOCOL_BALANCE = 'The actual balance of the protocol is inconsistent', // INCONSISTENT_PROTOCOL_BALANCE = 'The actual balance of the protocol is inconsistent', => 26
TOO_SMALL_FLASH_LOAN = 'The requested amount is too small for a FlashLoan.', // TOO_SMALL_FLASH_LOAN = 'The requested amount is too small for a FlashLoan.', => 25
// NOT_ENOUGH_LIQUIDITY_TO_BORROW = 'There is not enough liquidity available to borrow', // NOT_ENOUGH_LIQUIDITY_TO_BORROW = 'There is not enough liquidity available to borrow', => 24
HF_IS_NOT_BELLOW_THRESHOLD = 'Health factor is not below the threshold', HF_IS_NOT_BELLOW_THRESHOLD = 'Health factor is not below the threshold',
INVALID_HF = 'Invalid health factor', INVALID_HF = 'Invalid health factor',
USER_DID_NOT_BORROW_SPECIFIED = 'User did not borrow the specified currency', USER_DID_NOT_BORROW_SPECIFIED = 'User did not borrow the specified currency',
@ -109,7 +118,7 @@ export enum ProtocolErrors {
export enum OLD_ProtocolErrors { export enum OLD_ProtocolErrors {
INVALID_CONFIGURATOR_CALLER_MSG = 'The caller must be a lending pool configurator contract', INVALID_CONFIGURATOR_CALLER_MSG = 'The caller must be a lending pool configurator contract',
INVALID_POOL_CALLER_MSG = 'The caller must be a lending pool contract', INVALID_POOL_CALLER_MSG = 'The caller must be a lending pool contract',
// INVALID_POOL_CALLER_MSG_1 = 'The caller of this function must be a lending pool', => CALLER_MUST_BE_LENDING_POOL INVALID_POOL_CALLER_MSG_1 = 'The caller of this function must be a lending pool',
INVALID_POOL_MANAGER_CALLER_MSG = 'The caller must be a lending pool manager', INVALID_POOL_MANAGER_CALLER_MSG = 'The caller must be a lending pool manager',
INVALID_FROM_BALANCE_AFTER_TRANSFER = 'Invalid from balance after transfer', INVALID_FROM_BALANCE_AFTER_TRANSFER = 'Invalid from balance after transfer',
INVALID_TO_BALANCE_AFTER_TRANSFER = 'Invalid from balance after transfer', INVALID_TO_BALANCE_AFTER_TRANSFER = 'Invalid from balance after transfer',

View File

@ -17,8 +17,10 @@ makeSuite('AToken: Transfer', (testEnv: TestEnv) => {
INVALID_REDIRECTED_BALANCE_BEFORE_TRANSFER, INVALID_REDIRECTED_BALANCE_BEFORE_TRANSFER,
INVALID_REDIRECTED_BALANCE_AFTER_TRANSFER, INVALID_REDIRECTED_BALANCE_AFTER_TRANSFER,
INVALID_REDIRECTION_ADDRESS, INVALID_REDIRECTION_ADDRESS,
ZERO_COLLATERAL, // ZERO_COLLATERAL,
TRANSFERRED_AMOUNT_GT_ZERO, TRANSFER_AMOUNT_NOT_GT_0,
COLLATERAL_BALANCE_IS_0,
TRANSFER_NOT_ALLOWED,
} = ProtocolErrors; } = ProtocolErrors;
it('User 0 deposits 1000 DAI, transfers to user 1', async () => { it('User 0 deposits 1000 DAI, transfers to user 1', async () => {
@ -96,16 +98,14 @@ makeSuite('AToken: Transfer', (testEnv: TestEnv) => {
await weth.connect(users[0].signer).mint(await convertToCurrencyDecimals(weth.address, '1')); await weth.connect(users[0].signer).mint(await convertToCurrencyDecimals(weth.address, '1'));
await weth.connect(users[0].signer).approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL); await weth.connect(users[0].signer).approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL);
await pool await pool.connect(users[0].signer).deposit(weth.address, ethers.utils.parseEther('1.0'), '0');
.connect(users[0].signer)
.deposit(weth.address, ethers.utils.parseEther('1.0'), '0');
await expect( await expect(
pool pool
.connect(users[1].signer) .connect(users[1].signer)
.borrow(weth.address, ethers.utils.parseEther('0.1'), RateMode.Stable, AAVE_REFERRAL), .borrow(weth.address, ethers.utils.parseEther('0.1'), RateMode.Stable, AAVE_REFERRAL),
ZERO_COLLATERAL COLLATERAL_BALANCE_IS_0
).to.be.revertedWith(ZERO_COLLATERAL); ).to.be.revertedWith(COLLATERAL_BALANCE_IS_0);
}); });
it('User 1 sets the DAI as collateral and borrows, tries to transfer everything back to user 0 (revert expected)', async () => { it('User 1 sets the DAI as collateral and borrows, tries to transfer everything back to user 0 (revert expected)', async () => {
@ -120,25 +120,25 @@ makeSuite('AToken: Transfer', (testEnv: TestEnv) => {
await expect( await expect(
aDai.connect(users[1].signer).transfer(users[0].address, aDAItoTransfer), aDai.connect(users[1].signer).transfer(users[0].address, aDAItoTransfer),
'Transfer cannot be allowed.' TRANSFER_NOT_ALLOWED
).to.be.revertedWith('Transfer cannot be allowed.'); ).to.be.revertedWith(TRANSFER_NOT_ALLOWED);
}); });
it('User 0 tries to transfer 0 balance (revert expected)', async () => { it('User 0 tries to transfer 0 balance (revert expected)', async () => {
const {users, pool, aDai, dai, weth} = testEnv; const {users, pool, aDai, dai, weth} = testEnv;
await expect( await expect(
aDai.connect(users[0].signer).transfer(users[1].address, '0'), aDai.connect(users[0].signer).transfer(users[1].address, '0'),
TRANSFERRED_AMOUNT_GT_ZERO TRANSFER_AMOUNT_NOT_GT_0
).to.be.revertedWith(TRANSFERRED_AMOUNT_GT_ZERO); ).to.be.revertedWith(TRANSFER_AMOUNT_NOT_GT_0);
}); });
it('User 1 repays the borrow, transfers aDAI back to user 0', async () => { it('User 1 repays the borrow, transfers aDAI back to user 0', async () => {
const {users, pool, aDai, dai, weth} = testEnv; const {users, pool, aDai, dai, weth} = testEnv;
await weth.connect(users[1].signer).mint(await convertToCurrencyDecimals(weth.address, '2')); await weth.connect(users[1].signer).mint(await convertToCurrencyDecimals(weth.address, '2'));
await weth.connect(users[1].signer).approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL); await weth.connect(users[1].signer).approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL);
await pool await pool
.connect(users[1].signer) .connect(users[1].signer)
.repay(weth.address, MAX_UINT_AMOUNT, RateMode.Stable, users[1].address); .repay(weth.address, MAX_UINT_AMOUNT, RateMode.Stable, users[1].address);

View File

@ -6,7 +6,7 @@ import {ProtocolErrors} from '../helpers/types';
const {expect} = require('chai'); const {expect} = require('chai');
makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
const {INVALID_POOL_MANAGER_CALLER_MSG} = ProtocolErrors; const {CALLER_NOT_LENDING_POOL_MANAGER, RESERVE_LIQUIDITY_NOT_0} = ProtocolErrors;
it('Deactivates the ETH reserve', async () => { it('Deactivates the ETH reserve', async () => {
const {configurator, pool, weth} = testEnv; const {configurator, pool, weth} = testEnv;
@ -27,16 +27,16 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
const {configurator, users, weth} = testEnv; const {configurator, users, weth} = testEnv;
await expect( await expect(
configurator.connect(users[2].signer).deactivateReserve(weth.address), configurator.connect(users[2].signer).deactivateReserve(weth.address),
INVALID_POOL_MANAGER_CALLER_MSG CALLER_NOT_LENDING_POOL_MANAGER
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG); ).to.be.revertedWith(CALLER_NOT_LENDING_POOL_MANAGER);
}); });
it('Check the onlyLendingPoolManager on activateReserve ', async () => { it('Check the onlyLendingPoolManager on activateReserve ', async () => {
const {configurator, users, weth} = testEnv; const {configurator, users, weth} = testEnv;
await expect( await expect(
configurator.connect(users[2].signer).activateReserve(weth.address), configurator.connect(users[2].signer).activateReserve(weth.address),
INVALID_POOL_MANAGER_CALLER_MSG CALLER_NOT_LENDING_POOL_MANAGER
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG); ).to.be.revertedWith(CALLER_NOT_LENDING_POOL_MANAGER);
}); });
it('Freezes the ETH reserve', async () => { it('Freezes the ETH reserve', async () => {
@ -58,16 +58,16 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
const {configurator, users, weth} = testEnv; const {configurator, users, weth} = testEnv;
await expect( await expect(
configurator.connect(users[2].signer).freezeReserve(weth.address), configurator.connect(users[2].signer).freezeReserve(weth.address),
INVALID_POOL_MANAGER_CALLER_MSG CALLER_NOT_LENDING_POOL_MANAGER
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG); ).to.be.revertedWith(CALLER_NOT_LENDING_POOL_MANAGER);
}); });
it('Check the onlyLendingPoolManager on unfreezeReserve ', async () => { it('Check the onlyLendingPoolManager on unfreezeReserve ', async () => {
const {configurator, users, weth} = testEnv; const {configurator, users, weth} = testEnv;
await expect( await expect(
configurator.connect(users[2].signer).unfreezeReserve(weth.address), configurator.connect(users[2].signer).unfreezeReserve(weth.address),
INVALID_POOL_MANAGER_CALLER_MSG CALLER_NOT_LENDING_POOL_MANAGER
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG); ).to.be.revertedWith(CALLER_NOT_LENDING_POOL_MANAGER);
}); });
it('Deactivates the ETH reserve for borrowing', async () => { it('Deactivates the ETH reserve for borrowing', async () => {
@ -90,16 +90,16 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
const {configurator, users, weth} = testEnv; const {configurator, users, weth} = testEnv;
await expect( await expect(
configurator.connect(users[2].signer).disableBorrowingOnReserve(weth.address), configurator.connect(users[2].signer).disableBorrowingOnReserve(weth.address),
INVALID_POOL_MANAGER_CALLER_MSG CALLER_NOT_LENDING_POOL_MANAGER
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG); ).to.be.revertedWith(CALLER_NOT_LENDING_POOL_MANAGER);
}); });
it('Check the onlyLendingPoolManager on enableBorrowingOnReserve ', async () => { it('Check the onlyLendingPoolManager on enableBorrowingOnReserve ', async () => {
const {configurator, users, weth} = testEnv; const {configurator, users, weth} = testEnv;
await expect( await expect(
configurator.connect(users[2].signer).enableBorrowingOnReserve(weth.address, true), configurator.connect(users[2].signer).enableBorrowingOnReserve(weth.address, true),
INVALID_POOL_MANAGER_CALLER_MSG CALLER_NOT_LENDING_POOL_MANAGER
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG); ).to.be.revertedWith(CALLER_NOT_LENDING_POOL_MANAGER);
}); });
it('Deactivates the ETH reserve as collateral', async () => { it('Deactivates the ETH reserve as collateral', async () => {
@ -121,8 +121,8 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
const {configurator, users, weth} = testEnv; const {configurator, users, weth} = testEnv;
await expect( await expect(
configurator.connect(users[2].signer).disableReserveAsCollateral(weth.address), configurator.connect(users[2].signer).disableReserveAsCollateral(weth.address),
INVALID_POOL_MANAGER_CALLER_MSG CALLER_NOT_LENDING_POOL_MANAGER
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG); ).to.be.revertedWith(CALLER_NOT_LENDING_POOL_MANAGER);
}); });
it('Check the onlyLendingPoolManager on enableReserveAsCollateral ', async () => { it('Check the onlyLendingPoolManager on enableReserveAsCollateral ', async () => {
@ -131,8 +131,8 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
configurator configurator
.connect(users[2].signer) .connect(users[2].signer)
.enableReserveAsCollateral(weth.address, '75', '80', '105'), .enableReserveAsCollateral(weth.address, '75', '80', '105'),
INVALID_POOL_MANAGER_CALLER_MSG CALLER_NOT_LENDING_POOL_MANAGER
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG); ).to.be.revertedWith(CALLER_NOT_LENDING_POOL_MANAGER);
}); });
it('Disable stable borrow rate on the ETH reserve', async () => { it('Disable stable borrow rate on the ETH reserve', async () => {
@ -153,16 +153,16 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
const {configurator, users, weth} = testEnv; const {configurator, users, weth} = testEnv;
await expect( await expect(
configurator.connect(users[2].signer).disableReserveStableRate(weth.address), configurator.connect(users[2].signer).disableReserveStableRate(weth.address),
INVALID_POOL_MANAGER_CALLER_MSG CALLER_NOT_LENDING_POOL_MANAGER
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG); ).to.be.revertedWith(CALLER_NOT_LENDING_POOL_MANAGER);
}); });
it('Check the onlyLendingPoolManager on enableReserveStableRate', async () => { it('Check the onlyLendingPoolManager on enableReserveStableRate', async () => {
const {configurator, users, weth} = testEnv; const {configurator, users, weth} = testEnv;
await expect( await expect(
configurator.connect(users[2].signer).enableReserveStableRate(weth.address), configurator.connect(users[2].signer).enableReserveStableRate(weth.address),
INVALID_POOL_MANAGER_CALLER_MSG CALLER_NOT_LENDING_POOL_MANAGER
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG); ).to.be.revertedWith(CALLER_NOT_LENDING_POOL_MANAGER);
}); });
it('Changes LTV of the reserve', async () => { it('Changes LTV of the reserve', async () => {
@ -176,8 +176,8 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
const {configurator, users, weth} = testEnv; const {configurator, users, weth} = testEnv;
await expect( await expect(
configurator.connect(users[2].signer).setLtv(weth.address, '75'), configurator.connect(users[2].signer).setLtv(weth.address, '75'),
INVALID_POOL_MANAGER_CALLER_MSG CALLER_NOT_LENDING_POOL_MANAGER
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG); ).to.be.revertedWith(CALLER_NOT_LENDING_POOL_MANAGER);
}); });
it('Changes liquidation threshold of the reserve', async () => { it('Changes liquidation threshold of the reserve', async () => {
@ -194,8 +194,8 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
const {configurator, users, weth} = testEnv; const {configurator, users, weth} = testEnv;
await expect( await expect(
configurator.connect(users[2].signer).setLiquidationThreshold(weth.address, '80'), configurator.connect(users[2].signer).setLiquidationThreshold(weth.address, '80'),
INVALID_POOL_MANAGER_CALLER_MSG CALLER_NOT_LENDING_POOL_MANAGER
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG); ).to.be.revertedWith(CALLER_NOT_LENDING_POOL_MANAGER);
}); });
it('Changes liquidation bonus of the reserve', async () => { it('Changes liquidation bonus of the reserve', async () => {
@ -212,24 +212,24 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
const {configurator, users, weth} = testEnv; const {configurator, users, weth} = testEnv;
await expect( await expect(
configurator.connect(users[2].signer).setLiquidationBonus(weth.address, '80'), configurator.connect(users[2].signer).setLiquidationBonus(weth.address, '80'),
INVALID_POOL_MANAGER_CALLER_MSG CALLER_NOT_LENDING_POOL_MANAGER
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG); ).to.be.revertedWith(CALLER_NOT_LENDING_POOL_MANAGER);
}); });
it('Check the onlyLendingPoolManager on setReserveDecimals', async () => { it('Check the onlyLendingPoolManager on setReserveDecimals', async () => {
const {configurator, users, weth} = testEnv; const {configurator, users, weth} = testEnv;
await expect( await expect(
configurator.connect(users[2].signer).setReserveDecimals(weth.address, '80'), configurator.connect(users[2].signer).setReserveDecimals(weth.address, '80'),
INVALID_POOL_MANAGER_CALLER_MSG CALLER_NOT_LENDING_POOL_MANAGER
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG); ).to.be.revertedWith(CALLER_NOT_LENDING_POOL_MANAGER);
}); });
it('Check the onlyLendingPoolManager on setLiquidationBonus', async () => { it('Check the onlyLendingPoolManager on setLiquidationBonus', async () => {
const {configurator, users, weth} = testEnv; const {configurator, users, weth} = testEnv;
await expect( await expect(
configurator.connect(users[2].signer).setLiquidationBonus(weth.address, '80'), configurator.connect(users[2].signer).setLiquidationBonus(weth.address, '80'),
INVALID_POOL_MANAGER_CALLER_MSG CALLER_NOT_LENDING_POOL_MANAGER
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG); ).to.be.revertedWith(CALLER_NOT_LENDING_POOL_MANAGER);
}); });
it('Reverts when trying to disable the DAI reserve with liquidity on it', async () => { it('Reverts when trying to disable the DAI reserve with liquidity on it', async () => {
@ -246,7 +246,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
await expect( await expect(
configurator.deactivateReserve(dai.address), configurator.deactivateReserve(dai.address),
'The liquidity of the reserve needs to be 0' RESERVE_LIQUIDITY_NOT_0
).to.be.revertedWith('The liquidity of the reserve needs to be 0'); ).to.be.revertedWith(RESERVE_LIQUIDITY_NOT_0);
}); });
}); });

View File

@ -11,8 +11,8 @@ const {expect} = require('chai');
makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
let _mockFlashLoanReceiver = {} as MockFlashLoanReceiver; let _mockFlashLoanReceiver = {} as MockFlashLoanReceiver;
const { const {
INCONSISTENT_PROTOCOL_BALANCE, INCONSISTENT_PROTOCOL_ACTUAL_BALANCE,
TOO_SMALL_FLASH_LOAN, REQUESTED_AMOUNT_TO_SMALL,
NOT_ENOUGH_LIQUIDITY_TO_BORROW, NOT_ENOUGH_LIQUIDITY_TO_BORROW,
} = ProtocolErrors; } = ProtocolErrors;
@ -62,7 +62,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
const reserveDataBefore = await pool.getReserveData(weth.address); const reserveDataBefore = await pool.getReserveData(weth.address);
console.log("Total liquidity is ", reserveDataBefore.availableLiquidity.toString()); console.log('Total liquidity is ', reserveDataBefore.availableLiquidity.toString());
const txResult = await pool.flashLoan( const txResult = await pool.flashLoan(
_mockFlashLoanReceiver.address, _mockFlashLoanReceiver.address,
@ -99,7 +99,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
ethers.utils.parseEther('0.8'), ethers.utils.parseEther('0.8'),
'0x10' '0x10'
) )
).to.be.revertedWith(INCONSISTENT_PROTOCOL_BALANCE); ).to.be.revertedWith(INCONSISTENT_PROTOCOL_ACTUAL_BALANCE);
}); });
it('tries to take a very small flashloan, which would result in 0 fees (revert expected)', async () => { it('tries to take a very small flashloan, which would result in 0 fees (revert expected)', async () => {
@ -112,7 +112,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
'1', //1 wei loan '1', //1 wei loan
'0x10' '0x10'
) )
).to.be.revertedWith(TOO_SMALL_FLASH_LOAN); ).to.be.revertedWith(REQUESTED_AMOUNT_TO_SMALL);
}); });
it('tries to take a flashloan that is bigger than the available liquidity (revert expected)', async () => { it('tries to take a flashloan that is bigger than the available liquidity (revert expected)', async () => {
@ -194,7 +194,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
ethers.utils.parseEther('500'), ethers.utils.parseEther('500'),
'0x10' '0x10'
), ),
INCONSISTENT_PROTOCOL_BALANCE INCONSISTENT_PROTOCOL_ACTUAL_BALANCE
).to.be.revertedWith(INCONSISTENT_PROTOCOL_BALANCE); ).to.be.revertedWith(INCONSISTENT_PROTOCOL_ACTUAL_BALANCE);
}); });
}); });

View File

@ -1,18 +1,22 @@
import {expect} from 'chai'; import {expect} from 'chai';
import {makeSuite, TestEnv} from './helpers/make-suite'; import {makeSuite, TestEnv} from './helpers/make-suite';
import {ProtocolErrors, eContractid} from '../helpers/types'; import {ProtocolErrors, eContractid} from '../helpers/types';
import {deployGenericAToken, getAToken, deployContract, getContract} from '../helpers/contracts-helpers'; import {
deployGenericAToken,
getAToken,
deployContract,
getContract,
} from '../helpers/contracts-helpers';
import {MockAToken} from '../types/MockAToken'; import {MockAToken} from '../types/MockAToken';
import { MockStableDebtToken } from '../types/MockStableDebtToken'; import {MockStableDebtToken} from '../types/MockStableDebtToken';
import { MockVariableDebtToken } from '../types/MockVariableDebtToken'; import {MockVariableDebtToken} from '../types/MockVariableDebtToken';
makeSuite('Upgradeability', (testEnv: TestEnv) => { makeSuite('Upgradeability', (testEnv: TestEnv) => {
const {INVALID_POOL_MANAGER_CALLER_MSG} = ProtocolErrors; const {CALLER_NOT_LENDING_POOL_MANAGER} = ProtocolErrors;
let newATokenAddress: string; let newATokenAddress: string;
let newStableTokenAddress: string; let newStableTokenAddress: string;
let newVariableTokenAddress: string; let newVariableTokenAddress: string;
before('deploying instances', async () => { before('deploying instances', async () => {
const {dai, pool} = testEnv; const {dai, pool} = testEnv;
const aTokenInstance = await deployContract<MockAToken>(eContractid.MockAToken, [ const aTokenInstance = await deployContract<MockAToken>(eContractid.MockAToken, [
@ -22,24 +26,19 @@ makeSuite('Upgradeability', (testEnv: TestEnv) => {
'aDAI', 'aDAI',
]); ]);
const stableDebtTokenInstance = await deployContract<MockStableDebtToken>(eContractid.MockStableDebtToken, [ const stableDebtTokenInstance = await deployContract<MockStableDebtToken>(
pool.address, eContractid.MockStableDebtToken,
dai.address, [pool.address, dai.address, 'Aave stable debt bearing DAI updated', 'stableDebtDAI']
'Aave stable debt bearing DAI updated', );
'stableDebtDAI',
]);
const variableDebtTokenInstance = await deployContract<MockVariableDebtToken>(eContractid.MockVariableDebtToken, [ const variableDebtTokenInstance = await deployContract<MockVariableDebtToken>(
pool.address, eContractid.MockVariableDebtToken,
dai.address, [pool.address, dai.address, 'Aave variable debt bearing DAI updated', 'variableDebtDAI']
'Aave variable debt bearing DAI updated', );
'variableDebtDAI',
]);
newATokenAddress = aTokenInstance.address; newATokenAddress = aTokenInstance.address;
newVariableTokenAddress = variableDebtTokenInstance.address; newVariableTokenAddress = variableDebtTokenInstance.address;
newStableTokenAddress = stableDebtTokenInstance.address; newStableTokenAddress = stableDebtTokenInstance.address;
}); });
it('Tries to update the DAI Atoken implementation with a different address than the lendingPoolManager', async () => { it('Tries to update the DAI Atoken implementation with a different address than the lendingPoolManager', async () => {
@ -47,7 +46,7 @@ makeSuite('Upgradeability', (testEnv: TestEnv) => {
await expect( await expect(
configurator.connect(users[1].signer).updateAToken(dai.address, newATokenAddress) configurator.connect(users[1].signer).updateAToken(dai.address, newATokenAddress)
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG); ).to.be.revertedWith(CALLER_NOT_LENDING_POOL_MANAGER);
}); });
it('Upgrades the DAI Atoken implementation ', async () => { it('Upgrades the DAI Atoken implementation ', async () => {
@ -66,8 +65,10 @@ makeSuite('Upgradeability', (testEnv: TestEnv) => {
const {dai, configurator, users} = testEnv; const {dai, configurator, users} = testEnv;
await expect( await expect(
configurator.connect(users[1].signer).updateStableDebtToken(dai.address, newStableTokenAddress) configurator
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG); .connect(users[1].signer)
.updateStableDebtToken(dai.address, newStableTokenAddress)
).to.be.revertedWith(CALLER_NOT_LENDING_POOL_MANAGER);
}); });
it('Upgrades the DAI stable debt token implementation ', async () => { it('Upgrades the DAI stable debt token implementation ', async () => {
@ -79,7 +80,10 @@ makeSuite('Upgradeability', (testEnv: TestEnv) => {
const {stableDebtTokenAddress} = await pool.getReserveTokensAddresses(dai.address); const {stableDebtTokenAddress} = await pool.getReserveTokensAddresses(dai.address);
const debtToken = await getContract<MockStableDebtToken>(eContractid.MockStableDebtToken, stableDebtTokenAddress); const debtToken = await getContract<MockStableDebtToken>(
eContractid.MockStableDebtToken,
stableDebtTokenAddress
);
const tokenName = await debtToken.name(); const tokenName = await debtToken.name();
@ -90,8 +94,10 @@ makeSuite('Upgradeability', (testEnv: TestEnv) => {
const {dai, configurator, users} = testEnv; const {dai, configurator, users} = testEnv;
await expect( await expect(
configurator.connect(users[1].signer).updateVariableDebtToken(dai.address, newVariableTokenAddress) configurator
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG); .connect(users[1].signer)
.updateVariableDebtToken(dai.address, newVariableTokenAddress)
).to.be.revertedWith(CALLER_NOT_LENDING_POOL_MANAGER);
}); });
it('Upgrades the DAI variable debt token implementation ', async () => { it('Upgrades the DAI variable debt token implementation ', async () => {
@ -103,11 +109,13 @@ makeSuite('Upgradeability', (testEnv: TestEnv) => {
const {variableDebtTokenAddress} = await pool.getReserveTokensAddresses(dai.address); const {variableDebtTokenAddress} = await pool.getReserveTokensAddresses(dai.address);
const debtToken = await getContract<MockStableDebtToken>(eContractid.MockStableDebtToken, variableDebtTokenAddress); const debtToken = await getContract<MockStableDebtToken>(
eContractid.MockStableDebtToken,
variableDebtTokenAddress
);
const tokenName = await debtToken.name(); const tokenName = await debtToken.name();
expect(tokenName).to.be.eq('Aave variable debt bearing DAI updated', 'Invalid token name'); expect(tokenName).to.be.eq('Aave variable debt bearing DAI updated', 'Invalid token name');
}); });
}); });