From 73d7ca001c3e637e9c2a2c5de70e1e99388b86dd Mon Sep 17 00:00:00 2001 From: The3D Date: Thu, 10 Sep 2020 13:52:07 +0200 Subject: [PATCH] added configurator tests --- .../configuration/ReserveConfiguration.sol | 27 ++++++++++--------- test/configurator.spec.ts | 17 ++++++++++++ test/scenario.spec.ts | 2 +- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/contracts/libraries/configuration/ReserveConfiguration.sol b/contracts/libraries/configuration/ReserveConfiguration.sol index 96c0024c..10471f6e 100644 --- a/contracts/libraries/configuration/ReserveConfiguration.sol +++ b/contracts/libraries/configuration/ReserveConfiguration.sol @@ -6,6 +6,7 @@ import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol'; import {ReserveLogic} from '../logic/ReserveLogic.sol'; import {WadRayMath} from '../math/WadRayMath.sol'; import {IPriceOracleGetter} from '../../interfaces/IPriceOracleGetter.sol'; +import "@nomiclabs/buidler/console.sol"; /** * @title ReserveConfiguration library @@ -13,14 +14,14 @@ import {IPriceOracleGetter} from '../../interfaces/IPriceOracleGetter.sol'; * @notice Implements the bitmap logic to handle the reserve configuration */ library ReserveConfiguration { - uint256 constant LTV_MASK = 0xFFFFFFFFFFF0000; - uint256 constant LIQUIDATION_THRESHOLD_MASK = 0xFFFFFFF0000FFFF; - uint256 constant LIQUIDATION_BONUS_MASK = 0xFFF0000FFFFFFFF; - uint256 constant DECIMALS_MASK = 0xF00FFFFFFFFFFFF; - uint256 constant ACTIVE_MASK = 0xEFFFFFFFFFFFFFF; - uint256 constant FROZEN_MASK = 0xDFFFFFFFFFFFFFF; - uint256 constant BORROWING_MASK = 0xBFFFFFFFFFFFFFF; - uint256 constant STABLE_BORROWING_MASK = 0x7FFFFFFFFFFFFFF; + uint256 constant LTV_MASK = 0xFFFFFFFFFFFFFFFF0000; + uint256 constant LIQUIDATION_THRESHOLD_MASK = 0xFFFFFFFFFFFF0000FFFF; + uint256 constant LIQUIDATION_BONUS_MASK = 0xFFFFFFF0000FFFFFFFF; + uint256 constant DECIMALS_MASK = 0xFFFFFF00FFFFFFFFFFFF; + uint256 constant ACTIVE_MASK = 0xFFFFFEFFFFFFFFFFFFFF; + uint256 constant FROZEN_MASK = 0xFFFFFDFFFFFFFFFFFFFF; + uint256 constant BORROWING_MASK = 0xFFFFFBFFFFFFFFFFFFFF; + uint256 constant STABLE_BORROWING_MASK = 0xFFFF07FFFFFFFFFFFFFF; uint256 constant RESERVE_FACTOR_MASK = 0xFFFFFFFFFFFFFFFF; struct Map { @@ -39,10 +40,12 @@ library ReserveConfiguration { /** * @dev sets the reserve factor of the reserve * @param self the reserve configuration - * @param ltv the new ltv + * @param reserveFactor the reserve factor **/ - function setReserveFactor(ReserveConfiguration.Map memory self, uint256 ltv) internal pure { - self.data = (self.data & RESERVE_FACTOR_MASK) | ltv; + function setReserveFactor(ReserveConfiguration.Map memory self, uint256 reserveFactor) internal view { + console.log("Setting reserve factor to %s", reserveFactor); + + self.data = (self.data & RESERVE_FACTOR_MASK) | reserveFactor << 64; } /** @@ -51,7 +54,7 @@ library ReserveConfiguration { * @return the reserve factor **/ function getReserveFactor(ReserveConfiguration.Map storage self) internal view returns (uint256) { - return self.data & ~RESERVE_FACTOR_MASK; + return (self.data & ~RESERVE_FACTOR_MASK) >> 64; } /** * @dev sets the Loan to Value of the reserve diff --git a/test/configurator.spec.ts b/test/configurator.spec.ts index a6513e54..8b694afb 100644 --- a/test/configurator.spec.ts +++ b/test/configurator.spec.ts @@ -180,6 +180,23 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { ).to.be.revertedWith(CALLER_NOT_LENDING_POOL_MANAGER); }); + + it('Changes the reserve factor of the reserve', async () => { + const {configurator, pool, weth} = testEnv; + await configurator.setReserveFactor(weth.address, '1000'); + const {reserveFactor} = await pool.getReserveConfigurationData(weth.address); + expect(reserveFactor.toString()).to.be.bignumber.equal('1000', 'Invalid reserve factor'); + }); + + it('Check the onlyLendingPoolManager on setReserveFactor', async () => { + const {configurator, users, weth} = testEnv; + await expect( + configurator.connect(users[2].signer).setReserveFactor(weth.address, '2000'), + CALLER_NOT_LENDING_POOL_MANAGER + ).to.be.revertedWith(CALLER_NOT_LENDING_POOL_MANAGER); + }); + + it('Changes liquidation threshold of the reserve', async () => { const {configurator, pool, weth} = testEnv; await configurator.setLiquidationThreshold(weth.address, '75'); diff --git a/test/scenario.spec.ts b/test/scenario.spec.ts index 5d449d76..025bc720 100644 --- a/test/scenario.spec.ts +++ b/test/scenario.spec.ts @@ -12,7 +12,7 @@ BigNumber.config({DECIMAL_PLACES: 0, ROUNDING_MODE: BigNumber.ROUND_DOWN}); const scenarioFolder = './test/helpers/scenarios/'; -const selectedScenarios: string[] = []; +const selectedScenarios: string[] = ['']; fs.readdirSync(scenarioFolder).forEach((file) => { if (selectedScenarios.length > 0 && !selectedScenarios.includes(file)) return;