Skip to content

Commit

Permalink
fix: Add test exploiting pricing issue
Browse files Browse the repository at this point in the history
  • Loading branch information
LHerskind committed Nov 18, 2021
1 parent cf96b2f commit 3457fb8
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions test-suites/emode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ import { ProtocolErrors, RateMode } from '../helpers/types';
import { convertToCurrencyDecimals } from '../helpers/contracts-helpers';
import { makeSuite, TestEnv } from './helpers/make-suite';
import './helpers/utils/wadraymath';
import { evmRevert, evmSnapshot } from '@aave/deploy-v3';
import { parseUnits } from '@ethersproject/units';

makeSuite('EfficiencyMode', (testEnv: TestEnv) => {
const { VL_INCONSISTENT_EMODE_CATEGORY, VL_HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD } =
ProtocolErrors;

let snapSetup: string;

const CATEGORIES = {
STABLECOINS: {
id: BigNumber.from('1'),
Expand Down Expand Up @@ -54,6 +58,8 @@ makeSuite('EfficiencyMode', (testEnv: TestEnv) => {
await usdc.connect(user1.signer).approve(pool.address, MAX_UINT_AMOUNT);
await weth.connect(user1.signer).approve(pool.address, MAX_UINT_AMOUNT);
await dai.connect(user2.signer).approve(pool.address, MAX_UINT_AMOUNT);

snapSetup = await evmSnapshot();
});

it('Admin adds a category for stablecoins with DAI and USDC', async () => {
Expand Down Expand Up @@ -575,4 +581,49 @@ makeSuite('EfficiencyMode', (testEnv: TestEnv) => {
expect(userDataAfter.availableBorrowsBase).to.be.lt(userDataBefore.availableBorrowsBase);
expect(userDataAfter.healthFactor).to.be.eq(userDataBefore.healthFactor);
});

it('Issue case', async () => {
await evmRevert(snapSetup);

const {
configurator,
helpersContract,
weth,
usdc,
poolAdmin,
pool,
users: [user],
} = testEnv;

// Setup eMode category for eth, use weth price as oracle price.
const { id, ltv, lt, lb, label } = CATEGORIES.ETHEREUM;
expect(
await configurator
.connect(poolAdmin.signer)
.setEModeCategory(id, ltv, lt, lb, weth.address, label)
);
expect(await configurator.connect(poolAdmin.signer).setAssetEModeCategory(weth.address, id));
expect(await helpersContract.getReserveEModeCategory(weth.address)).to.be.eq(id);
const data = await pool.getEModeCategoryData(id);
expect(data.priceSource).to.be.eq(weth.address);

// Deposit USDC
expect(
await pool.connect(user.signer).supply(usdc.address, parseUnits('100', 6), user.address, 0)
);

// Look at power
const baseUnit = parseUnits('1', 8);
const userDataBefore = await pool.getUserAccountData(user.address);
expect(userDataBefore.totalCollateralBase).to.be.eq(baseUnit.mul(100));

// Activate eMode for ETH
expect(await pool.connect(user.signer).setUserEMode(id));

// Look at power
const userDataAfter = await pool.getUserAccountData(user.address);

// Expect collateral to have equal value
expect(userDataAfter.totalCollateralBase).to.be.eq(userDataBefore.totalCollateralBase);
});
});

0 comments on commit 3457fb8

Please sign in to comment.