From 49d0f4e6baa5b78d31443617456331904db7dfdc Mon Sep 17 00:00:00 2001 From: Steven Valeri Date: Tue, 25 Oct 2022 09:41:46 -0400 Subject: [PATCH] feat: add unit test for reserve configuration --- .../helpers/MockReserveConfiguration.sol | 14 +++++++++- test-suites/reserve-configuration.spec.ts | 27 ++++++++++++------- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/contracts/mocks/helpers/MockReserveConfiguration.sol b/contracts/mocks/helpers/MockReserveConfiguration.sol index 4774da4b0..947a88a21 100644 --- a/contracts/mocks/helpers/MockReserveConfiguration.sol +++ b/contracts/mocks/helpers/MockReserveConfiguration.sol @@ -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 { @@ -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); diff --git a/test-suites/reserve-configuration.spec.ts b/test-suites/reserve-configuration.spec.ts index bdce2c4ca..a27003d4a 100644 --- a/test-suites/reserve-configuration.spec.ts +++ b/test-suites/reserve-configuration.spec.ts @@ -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; @@ -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]) @@ -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); @@ -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( @@ -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( @@ -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