Skip to content

Commit

Permalink
feat: Add tests for the new unbackedMint cap control
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelmtzinf committed Sep 21, 2021
1 parent bde09e3 commit ad92076
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 28 deletions.
2 changes: 2 additions & 0 deletions helpers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ export enum ProtocolErrors {
PC_FLASHLOAN_PREMIUM_INVALID = '96',
RC_INVALID_LIQUIDATION_PROTOCOL_FEE = '97',
P_CALLER_NOT_BRIDGE = '98',
RC_INVALID_UNBACKED_MINT_CAP = '99',
VL_UNBACKED_MINT_CAP_EXCEEDED = '100',

// old

Expand Down
72 changes: 44 additions & 28 deletions test-suites/bridge-logic.spec.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
import { parseEther } from 'ethers/lib/utils';
import { TestEnv, makeSuite } from './helpers/make-suite';
const { expect } = require('chai');

import { BigNumber, utils } from 'ethers';
import { ReserveData, UserReserveData } from './helpers/utils/interfaces';
import { waitForTx, advanceTimeAndBlock } from '../helpers/misc-utils';
import { ProtocolErrors, RateMode } from '../helpers/types';
import { getACLManager } from '../helpers/contracts-getters';
import { MAX_UINT_AMOUNT } from '../helpers/constants';
import { ACLManager } from '../types';
import AaveConfig from '../market-config';
import { TestEnv, makeSuite } from './helpers/make-suite';
import { getReserveData } from './helpers/utils/helpers';
import { getTxCostAndTimestamp } from './helpers/actions';
import {
calcExpectedReserveDataAfterMintUnbacked,
calcExpectedReserveDataAfterBackUnbacked,
configuration as calculationsConfiguration,
} from './helpers/utils/calculations';

import './helpers/utils/wadraymath';
import { getTxCostAndTimestamp } from './helpers/actions';

import { getReserveData } from './helpers/utils/helpers';

import { ReserveData, UserReserveData } from './helpers/utils/interfaces';
import { BigNumber } from 'ethers';
import { MAX_UINT_AMOUNT } from '../helpers/constants';
import { DRE, waitForTx, advanceTimeAndBlock } from '../helpers/misc-utils';
import { ProtocolErrors, RateMode } from '../helpers/types';

import AaveConfig from '../market-config';
import { ACLManager, Errors } from '../types';
import { getACLManager } from '../helpers/contracts-getters';

const expectEqual = (
actual: UserReserveData | ReserveData,
Expand All @@ -30,12 +24,12 @@ const expectEqual = (
expect(actual).to.be.almostEqualOrEqual(expected);
};

makeSuite('Bridge-logic testing with borrows', (testEnv: TestEnv) => {
const { P_CALLER_NOT_BRIDGE } = ProtocolErrors;
makeSuite('BridgeLogic: Testing with borrows', (testEnv: TestEnv) => {
const { P_CALLER_NOT_BRIDGE, VL_UNBACKED_MINT_CAP_EXCEEDED } = ProtocolErrors;

const depositAmount = parseEther('1000');
const borrowAmount = parseEther('200');
const withdrawAmount = parseEther('100');
const depositAmount = utils.parseEther('1000');
const borrowAmount = utils.parseEther('200');
const withdrawAmount = utils.parseEther('100');
const feeBP = BigNumber.from(30);
const denominatorBP = BigNumber.from(10000);

Expand All @@ -44,7 +38,7 @@ makeSuite('Bridge-logic testing with borrows', (testEnv: TestEnv) => {

let aclManager: ACLManager;

before('setup', async () => {
before(async () => {
calculationsConfiguration.reservesParams = AaveConfig.ReservesConfig;

const { users } = testEnv;
Expand All @@ -64,9 +58,11 @@ makeSuite('Bridge-logic testing with borrows', (testEnv: TestEnv) => {

it('User 1 deposit 2 eth', async () => {
const { users, pool, weth } = testEnv;
await weth.connect(users[1].signer).deposit({ value: parseEther('2') });
await weth.connect(users[1].signer).deposit({ value: utils.parseEther('2') });
await weth.connect(users[1].signer).approve(pool.address, MAX_UINT_AMOUNT);
await pool.connect(users[1].signer).deposit(weth.address, parseEther('2'), users[1].address, 0);
await pool
.connect(users[1].signer)
.deposit(weth.address, utils.parseEther('2'), users[1].address, 0);
});

it('User 1 borrows 200 dai with variable debt', async () => {
Expand All @@ -83,14 +79,24 @@ makeSuite('Bridge-logic testing with borrows', (testEnv: TestEnv) => {
.borrow(dai.address, borrowAmount, RateMode.Stable, 0, users[1].address);
});

it('User 1 tries to perform was withdraw 100 aDai from L2 (reverts)', async () => {
it('User 1 tries to perform fast withdraw 100 aDai from L2 (revert expected)', async () => {
const { users, pool, dai } = testEnv;
await expect(
pool.connect(users[1].signer).mintUnbacked(dai.address, mintAmount, users[0].address, 0)
).to.be.revertedWith(P_CALLER_NOT_BRIDGE);
});

it('User 2 perform fast withdraw 100 aDAi from L2', async () => {
it('RiskAdmin updates the unbackedMintCap to 10 aDai (10 left) and user 1 tries to perform fast withdraw 100 aDai from L2 (revert expected)', async () => {
const { users, riskAdmin, pool, configurator, dai } = testEnv;
expect(await configurator.connect(riskAdmin.signer).setUnbackedMintCap(dai.address, '10'));
await expect(
pool.connect(users[2].signer).mintUnbacked(dai.address, mintAmount, users[0].address, 0)
).to.be.revertedWith(VL_UNBACKED_MINT_CAP_EXCEEDED);

expect(await configurator.connect(riskAdmin.signer).setUnbackedMintCap(dai.address, '0'));
});

it('User 2 perform fast withdraw 100 aDai from L2', async () => {
const { users, pool, dai, helpersContract } = testEnv;
const reserveDataBefore = await getReserveData(helpersContract, dai.address);
const tx = await waitForTx(
Expand All @@ -106,7 +112,17 @@ makeSuite('Bridge-logic testing with borrows', (testEnv: TestEnv) => {
expectEqual(reserveDataAfter, expectedDataAfter);
});

it('User 2 perform another fast withdraw 100 aDAi from L2', async () => {
it('RiskAdmin updates the unbackedMintCap to 100 aDai (0 left) and user 1 tries to perform fast withdraw 1 aDai from L2 (revert expected)', async () => {
const { users, riskAdmin, pool, configurator, dai } = testEnv;
expect(await configurator.connect(riskAdmin.signer).setUnbackedMintCap(dai.address, '100'));
await expect(
pool.connect(users[2].signer).mintUnbacked(dai.address, mintAmount, users[0].address, 0)
).to.be.revertedWith(VL_UNBACKED_MINT_CAP_EXCEEDED);

expect(await configurator.connect(riskAdmin.signer).setUnbackedMintCap(dai.address, '0'));
});

it('User 2 perform another fast withdraw 100 aDai from L2', async () => {
const { users, pool, dai, helpersContract } = testEnv;
const reserveDataBefore = await getReserveData(helpersContract, dai.address);
const tx = await waitForTx(
Expand Down

0 comments on commit ad92076

Please sign in to comment.