mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
feat: added new tests and cleaned
This commit is contained in:
parent
727cfa854d
commit
71b3b77677
|
@ -12,7 +12,6 @@ import { parseEther } from '@ethersproject/units';
|
||||||
import { BigNumber } from '@ethersproject/bignumber';
|
import { BigNumber } from '@ethersproject/bignumber';
|
||||||
import { strategyDAI } from '../../markets/amm/reservesConfigs';
|
import { strategyDAI } from '../../markets/amm/reservesConfigs';
|
||||||
import { strategyUSDC } from '../../markets/amm/reservesConfigs';
|
import { strategyUSDC } from '../../markets/amm/reservesConfigs';
|
||||||
import { strategyWETH } from '../../markets/amm/reservesConfigs';
|
|
||||||
import { ethers } from 'ethers';
|
import { ethers } from 'ethers';
|
||||||
|
|
||||||
const { expect } = require('chai');
|
const { expect } = require('chai');
|
||||||
|
@ -31,7 +30,6 @@ makeSuite('Exposure Cap', (testEnv: TestEnv) => {
|
||||||
BigNumber.from(nb).mul(BigNumber.from('10').pow((await token.decimals()) - 3));
|
BigNumber.from(nb).mul(BigNumber.from('10').pow((await token.decimals()) - 3));
|
||||||
it('Reserves should initially have exposure cap disabled (exposureCap = 0)', async () => {
|
it('Reserves should initially have exposure cap disabled (exposureCap = 0)', async () => {
|
||||||
const {
|
const {
|
||||||
configurator,
|
|
||||||
weth,
|
weth,
|
||||||
pool,
|
pool,
|
||||||
dai,
|
dai,
|
||||||
|
@ -68,13 +66,9 @@ makeSuite('Exposure Cap', (testEnv: TestEnv) => {
|
||||||
});
|
});
|
||||||
it('Deposit 10 Dai, 10 USDC, LTV for both should increase', async () => {
|
it('Deposit 10 Dai, 10 USDC, LTV for both should increase', async () => {
|
||||||
const {
|
const {
|
||||||
configurator,
|
|
||||||
weth,
|
|
||||||
pool,
|
pool,
|
||||||
dai,
|
dai,
|
||||||
usdc,
|
usdc,
|
||||||
deployer,
|
|
||||||
helpersContract,
|
|
||||||
users: [user1],
|
users: [user1],
|
||||||
} = testEnv;
|
} = testEnv;
|
||||||
|
|
||||||
|
@ -102,13 +96,9 @@ makeSuite('Exposure Cap', (testEnv: TestEnv) => {
|
||||||
it('Sets the exposure cap for DAI to 10 Units', async () => {
|
it('Sets the exposure cap for DAI to 10 Units', async () => {
|
||||||
const {
|
const {
|
||||||
configurator,
|
configurator,
|
||||||
weth,
|
|
||||||
pool,
|
|
||||||
dai,
|
dai,
|
||||||
usdc,
|
|
||||||
deployer,
|
|
||||||
helpersContract,
|
helpersContract,
|
||||||
users: [user1],
|
users: [],
|
||||||
} = testEnv;
|
} = testEnv;
|
||||||
|
|
||||||
const newExposureCap = 10;
|
const newExposureCap = 10;
|
||||||
|
@ -121,12 +111,8 @@ makeSuite('Exposure Cap', (testEnv: TestEnv) => {
|
||||||
});
|
});
|
||||||
it('should succeed to deposit 10 dai but dai ltv drops to 0', async () => {
|
it('should succeed to deposit 10 dai but dai ltv drops to 0', async () => {
|
||||||
const {
|
const {
|
||||||
usdc,
|
|
||||||
pool,
|
pool,
|
||||||
dai,
|
dai,
|
||||||
aDai,
|
|
||||||
deployer,
|
|
||||||
helpersContract,
|
|
||||||
users: [user1],
|
users: [user1],
|
||||||
} = testEnv;
|
} = testEnv;
|
||||||
const suppliedAmount = 10;
|
const suppliedAmount = 10;
|
||||||
|
@ -139,12 +125,42 @@ makeSuite('Exposure Cap', (testEnv: TestEnv) => {
|
||||||
let ltv = (await pool.getUserAccountData(user1.address)).ltv;
|
let ltv = (await pool.getUserAccountData(user1.address)).ltv;
|
||||||
expect(ltv).to.be.equal(Math.floor((usdcLTV * usdcPrice) / (usdcPrice + 2 * daiPrice)));
|
expect(ltv).to.be.equal(Math.floor((usdcLTV * usdcPrice) / (usdcPrice + 2 * daiPrice)));
|
||||||
});
|
});
|
||||||
it('Should not be able to borrow 15 USD of weth', async () => {
|
it('should succeed to deposit 1 dai but avg ltv decreases', async () => {
|
||||||
|
const {
|
||||||
|
pool,
|
||||||
|
dai,
|
||||||
|
users: [user1],
|
||||||
|
} = testEnv;
|
||||||
|
const suppliedAmount = 1;
|
||||||
|
const precisionSuppliedAmount = (suppliedAmount * 1000).toString();
|
||||||
|
let ltv = (await pool.getUserAccountData(user1.address)).ltv;
|
||||||
|
|
||||||
|
await pool
|
||||||
|
.connect(user1.signer)
|
||||||
|
.deposit(dai.address, await unitParse(dai, precisionSuppliedAmount), user1.address, 0);
|
||||||
|
|
||||||
|
expect(ltv.toNumber()).to.be.gt((await pool.getUserAccountData(user1.address)).ltv.toNumber());
|
||||||
|
});
|
||||||
|
it('should succeed to deposit 1 usdc and ltv should increase', async () => {
|
||||||
const {
|
const {
|
||||||
usdc,
|
usdc,
|
||||||
|
pool,
|
||||||
|
users: [user1],
|
||||||
|
} = testEnv;
|
||||||
|
const suppliedAmount = 1;
|
||||||
|
const precisionSuppliedAmount = (suppliedAmount * 1000).toString();
|
||||||
|
let ltv = (await pool.getUserAccountData(user1.address)).ltv;
|
||||||
|
|
||||||
|
await pool
|
||||||
|
.connect(user1.signer)
|
||||||
|
.deposit(usdc.address, await unitParse(usdc, precisionSuppliedAmount), user1.address, 0);
|
||||||
|
|
||||||
|
expect(ltv.toNumber()).to.be.lt((await pool.getUserAccountData(user1.address)).ltv.toNumber());
|
||||||
|
});
|
||||||
|
it('Should not be able to borrow 15 USD of weth', async () => {
|
||||||
|
const {
|
||||||
pool,
|
pool,
|
||||||
weth,
|
weth,
|
||||||
helpersContract,
|
|
||||||
users: [user1],
|
users: [user1],
|
||||||
} = testEnv;
|
} = testEnv;
|
||||||
const precisionBorrowedUsdAmount = 15 * 1000;
|
const precisionBorrowedUsdAmount = 15 * 1000;
|
||||||
|
@ -160,7 +176,6 @@ makeSuite('Exposure Cap', (testEnv: TestEnv) => {
|
||||||
});
|
});
|
||||||
it('should be able to borrow 15 USD of weth after dai exposure cap raised to 100', async () => {
|
it('should be able to borrow 15 USD of weth after dai exposure cap raised to 100', async () => {
|
||||||
const {
|
const {
|
||||||
usdc,
|
|
||||||
pool,
|
pool,
|
||||||
dai,
|
dai,
|
||||||
weth,
|
weth,
|
||||||
|
@ -188,7 +203,6 @@ makeSuite('Exposure Cap', (testEnv: TestEnv) => {
|
||||||
});
|
});
|
||||||
it('should not be able to withdraw 5 dai, transfer 5 aDai after cap decrease back to 10 (capped)', async () => {
|
it('should not be able to withdraw 5 dai, transfer 5 aDai after cap decrease back to 10 (capped)', async () => {
|
||||||
const {
|
const {
|
||||||
usdc,
|
|
||||||
pool,
|
pool,
|
||||||
dai,
|
dai,
|
||||||
aDai,
|
aDai,
|
||||||
|
@ -231,13 +245,10 @@ makeSuite('Exposure Cap', (testEnv: TestEnv) => {
|
||||||
});
|
});
|
||||||
it('should be able to withdraw 5 dai, transfer 5 aDai after repaying weth Debt', async () => {
|
it('should be able to withdraw 5 dai, transfer 5 aDai after repaying weth Debt', async () => {
|
||||||
const {
|
const {
|
||||||
usdc,
|
|
||||||
pool,
|
pool,
|
||||||
dai,
|
dai,
|
||||||
weth,
|
weth,
|
||||||
aDai,
|
aDai,
|
||||||
configurator,
|
|
||||||
helpersContract,
|
|
||||||
users: [user1, , , receiver],
|
users: [user1, , , receiver],
|
||||||
} = testEnv;
|
} = testEnv;
|
||||||
|
|
||||||
|
@ -251,7 +262,7 @@ makeSuite('Exposure Cap', (testEnv: TestEnv) => {
|
||||||
aDai.connect(user1.signer).transfer(receiver.address, withdrawnAmount);
|
aDai.connect(user1.signer).transfer(receiver.address, withdrawnAmount);
|
||||||
});
|
});
|
||||||
it('Should fail to set the exposure cap for usdc and DAI to max cap + 1 Units', async () => {
|
it('Should fail to set the exposure cap for usdc and DAI to max cap + 1 Units', async () => {
|
||||||
const { configurator, usdc, pool, dai, deployer, helpersContract } = testEnv;
|
const { configurator, usdc, dai } = testEnv;
|
||||||
const newCap = Number(MAX_EXPOSURE_CAP) + 1;
|
const newCap = Number(MAX_EXPOSURE_CAP) + 1;
|
||||||
|
|
||||||
await expect(configurator.setExposureCap(usdc.address, newCap)).to.be.revertedWith(
|
await expect(configurator.setExposureCap(usdc.address, newCap)).to.be.revertedWith(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user