Skip to content

Commit

Permalink
feat: Add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelmtzinf committed Sep 21, 2021
1 parent 973e644 commit 0814ac2
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 4 deletions.
10 changes: 10 additions & 0 deletions contracts/mocks/helpers/MockReserveConfiguration.sol
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ contract MockReserveConfiguration {
return configuration.getSupplyCap();
}

function setUnbackedMintCap(uint256 unbackedMintCap) external {
DataTypes.ReserveConfigurationMap memory config = configuration;
config.setUnbackedMintCap(unbackedMintCap);
configuration = config;
}

function getUnbackedMintCap() external view returns (uint256) {
return configuration.getUnbackedMintCap();
}

function getFlags()
external
view
Expand Down
1 change: 1 addition & 0 deletions helpers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const MAX_UINT_AMOUNT =
'115792089237316195423570985008687907853269984665640564039457584007913129639935';
export const MAX_BORROW_CAP = '68719476735';
export const MAX_SUPPLY_CAP = '68719476735';
export const MAX_UNBACKED_MINT_CAP = '68719476735';
export const ONE_YEAR = '31536000';
export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
export const ONE_ADDRESS = '0x0000000000000000000000000000000000000001';
Expand Down
12 changes: 10 additions & 2 deletions test-suites/configurator-edge.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect } from 'chai';
import { BigNumber } from 'ethers';
import { makeSuite, TestEnv } from './helpers/make-suite';
import { ProtocolErrors } from '../helpers/types';
import { MAX_BORROW_CAP, MAX_UINT_AMOUNT } from '../helpers/constants';
import { MAX_BORROW_CAP, MAX_UNBACKED_MINT_CAP, MAX_UINT_AMOUNT, MAX_SUPPLY_CAP } from '../helpers/constants';
import { convertToCurrencyDecimals } from '../helpers/contracts-helpers';

makeSuite('PoolConfigurator: Edge cases', (testEnv: TestEnv) => {
Expand All @@ -15,6 +15,7 @@ makeSuite('PoolConfigurator: Edge cases', (testEnv: TestEnv) => {
PC_RESERVE_LIQUIDITY_NOT_0,
RC_INVALID_BORROW_CAP,
RC_INVALID_SUPPLY_CAP,
RC_INVALID_UNBACKED_MINT_CAP,
} = ProtocolErrors;

it('ReserveConfiguration setLiquidationBonus() threshold > MAX_VALID_LIQUIDATION_THRESHOLD', async () => {
Expand Down Expand Up @@ -139,10 +140,17 @@ makeSuite('PoolConfigurator: Edge cases', (testEnv: TestEnv) => {
it('Tries to update supplyCap > MAX_SUPPLY_CAP (revert expected)', async () => {
const { configurator, weth } = testEnv;
await expect(
configurator.setSupplyCap(weth.address, BigNumber.from(MAX_BORROW_CAP).add(1))
configurator.setSupplyCap(weth.address, BigNumber.from(MAX_SUPPLY_CAP).add(1))
).to.be.revertedWith(RC_INVALID_SUPPLY_CAP);
});

it('Tries to update unbackedMintCap > MAX_UNBACKED_MINT_CAP (revert expected)', async () => {
const { configurator, weth } = testEnv;
await expect(
configurator.setUnbackedMintCap(weth.address, BigNumber.from(MAX_UNBACKED_MINT_CAP).add(1))
).to.be.revertedWith(RC_INVALID_UNBACKED_MINT_CAP);
});

it('Tries to disable the DAI reserve with liquidity on it (revert expected)', async () => {
const { dai, pool, configurator } = testEnv;
const userAddress = await pool.signer.getAddress();
Expand Down
3 changes: 1 addition & 2 deletions test-suites/configurator-liquidation-protocol-fee.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { expect } from 'chai';
import { utils } from 'ethers';
import { MAX_UINT_AMOUNT, MAX_SUPPLY_CAP } from '../helpers/constants';
import { convertToCurrencyDecimals } from '../helpers/contracts-helpers';
import { MAX_UINT_AMOUNT } from '../helpers/constants';
import { ProtocolErrors } from '../helpers/types';
import { TestEnv, makeSuite } from './helpers/make-suite';

Expand Down
22 changes: 22 additions & 0 deletions test-suites/configurator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ const getReserveData = async (helpersContract: AaveProtocolDataProvider, asset:
helpersContract.getReserveConfigurationData(asset),
helpersContract.getReserveCaps(asset),
helpersContract.getPaused(asset),
helpersContract.getLiquidationProtocolFee(asset),
helpersContract.getUnbackedMintCap(asset),
]);
};

Expand Down Expand Up @@ -454,6 +456,26 @@ makeSuite('PoolConfigurator', (testEnv: TestEnv) => {
expect(isPaused).to.be.equal(false);
});

it('Updates the unbackedMintCap of WETH via pool admin', async () => {
const { configurator, helpersContract, weth } = testEnv;
const newUnbackedMintCap = '10000';
expect(await configurator.setUnbackedMintCap(weth.address, newUnbackedMintCap))
.to.emit(configurator, 'UnbackedMintCapChanged')
.withArgs(weth.address, newUnbackedMintCap);

expect(await helpersContract.getUnbackedMintCap(weth.address)).to.be.eq(newUnbackedMintCap);
});

it('Updates the unbackedMintCap of WETH via risk admin', async () => {
const { configurator, helpersContract, weth } = testEnv;
const newUnbackedMintCap = '20000';
expect(await configurator.setUnbackedMintCap(weth.address, newUnbackedMintCap))
.to.emit(configurator, 'UnbackedMintCapChanged')
.withArgs(weth.address, newUnbackedMintCap);

expect(await helpersContract.getUnbackedMintCap(weth.address)).to.be.eq(newUnbackedMintCap);
});

it('Updates the borrowCap of WETH via pool admin', async () => {
const { configurator, helpersContract, weth } = testEnv;
const newBorrowCap = '3000000';
Expand Down
9 changes: 9 additions & 0 deletions test-suites/reserve-configuration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe('ReserveConfiguration', async () => {
const DECIMALS = BigNumber.from(18);
const BORROW_CAP = BigNumber.from(100);
const SUPPLY_CAP = BigNumber.from(200);
const UNBACKED_MINT_CAP = BigNumber.from(300);

const MAX_VALID_LTV = BigNumber.from(65535);
const MAX_VALID_LIQUIDATION_THRESHOLD = BigNumber.from(65535);
Expand Down Expand Up @@ -141,6 +142,14 @@ describe('ReserveConfiguration', async () => {
expect(await configMock.getSupplyCap()).to.be.eq(ZERO);
});

it('getUnbackedMintCap()', async () => {
expect(await configMock.getUnbackedMintCap()).to.be.eq(ZERO);
expect(await configMock.setUnbackedMintCap(UNBACKED_MINT_CAP));
expect(await configMock.getUnbackedMintCap()).to.be.eq(UNBACKED_MINT_CAP);
expect(await configMock.setUnbackedMintCap(ZERO));
expect(await configMock.getUnbackedMintCap()).to.be.eq(ZERO);
});

it('setLtv() with ltv = MAX_VALID_LTV', async () => {
expect(await configMock.getParams()).to.be.eql([ZERO, ZERO, ZERO, ZERO, ZERO]);
expect(await configMock.getLtv()).to.be.eq(ZERO);
Expand Down

0 comments on commit 0814ac2

Please sign in to comment.