Skip to content

Commit

Permalink
feat: add unit test for reserve configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Valeri committed Oct 25, 2022
1 parent 748818f commit 49d0f4e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
14 changes: 13 additions & 1 deletion contracts/mocks/helpers/MockReserveConfiguration.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.10;

import {ReserveConfiguration} from '../../protocol/libraries/configuration/ReserveConfiguration.sol';
import {
ReserveConfiguration
} from '../../protocol/libraries/configuration/ReserveConfiguration.sol';
import {DataTypes} from '../../protocol/libraries/types/DataTypes.sol';

contract MockReserveConfiguration {
Expand Down Expand Up @@ -109,6 +111,16 @@ contract MockReserveConfiguration {
configuration = config;
}

function setFlashLoanEnabled(bool enabled) external {
DataTypes.ReserveConfigurationMap memory config = configuration;
config.setFlashLoanEnabled(enabled);
configuration = config;
}

function getFlashLoanEnabled() external view returns (bool) {
return configuration.getFlashLoanEnabled();
}

function setSupplyCap(uint256 supplyCap) external {
DataTypes.ReserveConfigurationMap memory config = configuration;
config.setSupplyCap(supplyCap);
Expand Down
27 changes: 17 additions & 10 deletions test-suites/reserve-configuration.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { expect } from 'chai';
import { BigNumber } from 'ethers';
import { deployMockReserveConfiguration } from '@aave/deploy-v3/dist/helpers/contract-deployments';
import { ProtocolErrors } from '../helpers/types';
import { evmSnapshot, evmRevert } from '@aave/deploy-v3';
import { MockReserveConfiguration } from '../types';
import {expect} from 'chai';
import {BigNumber} from 'ethers';
import {deployMockReserveConfiguration} from '@aave/deploy-v3/dist/helpers/contract-deployments';
import {ProtocolErrors} from '../helpers/types';
import {evmSnapshot, evmRevert} from '@aave/deploy-v3';
import {MockReserveConfiguration} from '../types';

describe('ReserveConfiguration', async () => {
let snap: string;
Expand Down Expand Up @@ -232,6 +232,13 @@ describe('ReserveConfiguration', async () => {
expect(await configMock.getUnbackedMintCap()).to.be.eq(ZERO);
});

it('getFlashLoanEnabled()', async () => {
expect(await configMock.getFlashLoanEnabled()).to.be.eq(false);
expect(await configMock.setFlashLoanEnabled(true));
expect(await configMock.getFlashLoanEnabled()).to.be.eq(true);
expect(await configMock.setFlashLoanEnabled(false));
});

it('setLtv() with ltv = MAX_VALID_LTV', async () => {
expect(bigNumbersToArrayString(await configMock.getParams())).to.be.eql(
bigNumbersToArrayString([ZERO, ZERO, ZERO, ZERO, ZERO, ZERO])
Expand All @@ -253,7 +260,7 @@ describe('ReserveConfiguration', async () => {
it('setLtv() with ltv > MAX_VALID_LTV (revert expected)', async () => {
expect(await configMock.getLtv()).to.be.eq(ZERO);

const { INVALID_LTV } = ProtocolErrors;
const {INVALID_LTV} = ProtocolErrors;

// setLTV to MAX_VALID_LTV + 1
await expect(configMock.setLtv(MAX_VALID_LTV.add(1))).to.be.revertedWith(INVALID_LTV);
Expand Down Expand Up @@ -281,7 +288,7 @@ describe('ReserveConfiguration', async () => {
it('setLiquidationThreshold() with threshold > MAX_VALID_LIQUIDATION_THRESHOLD (revert expected)', async () => {
expect(await configMock.getLiquidationThreshold()).to.be.eq(ZERO);

const { INVALID_LIQ_THRESHOLD } = ProtocolErrors;
const {INVALID_LIQ_THRESHOLD} = ProtocolErrors;

// setLiquidationThreshold to MAX_VALID_LIQUIDATION_THRESHOLD + 1
await expect(
Expand Down Expand Up @@ -311,7 +318,7 @@ describe('ReserveConfiguration', async () => {
it('setDecimals() with decimals > MAX_VALID_DECIMALS (revert expected)', async () => {
expect(await configMock.getDecimals()).to.be.eq(ZERO);

const { INVALID_DECIMALS } = ProtocolErrors;
const {INVALID_DECIMALS} = ProtocolErrors;

// setDecimals to MAX_VALID_DECIMALS + 1
await expect(configMock.setDecimals(MAX_VALID_DECIMALS.add(1))).to.be.revertedWith(
Expand All @@ -331,7 +338,7 @@ describe('ReserveConfiguration', async () => {
it('setEModeCategory() with categoryID > MAX_VALID_EMODE_CATEGORY (revert expected)', async () => {
expect(await configMock.getEModeCategory()).to.be.eq(ZERO);

const { INVALID_EMODE_CATEGORY } = ProtocolErrors;
const {INVALID_EMODE_CATEGORY} = ProtocolErrors;

await expect(configMock.setEModeCategory(MAX_VALID_EMODE_CATEGORY.add(1))).to.be.revertedWith(
INVALID_EMODE_CATEGORY
Expand Down

0 comments on commit 49d0f4e

Please sign in to comment.