Skip to content

Commit 315075e

Browse files
committed
test: add test
1 parent 7f54867 commit 315075e

File tree

5 files changed

+125
-8
lines changed

5 files changed

+125
-8
lines changed

src/contracts/extensions/v3-config-engine/IAaveV3ConfigEngine.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ interface IAaveV3ConfigEngine {
226226
* liqThreshold: 70_00,
227227
* liqBonus: EngineFlags.KEEP_CURRENT,
228228
* label: EngineFlags.KEEP_CURRENT_STRING,
229-
* borrowable:[USDC],
229+
* borrowables:[USDC],
230230
* collaterals:[ETH]
231231
* })
232232
*/
@@ -235,7 +235,7 @@ interface IAaveV3ConfigEngine {
235235
uint256 liqThreshold;
236236
uint256 liqBonus;
237237
string label;
238-
address[] borrowable;
238+
address[] borrowables;
239239
address[] collaterals;
240240
}
241241

src/contracts/extensions/v3-config-engine/libraries/EModeEngine.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ library EModeEngine {
4444
true
4545
);
4646
}
47-
for (uint256 k; k < creations[i].borrowable.length; k++) {
47+
for (uint256 k; k < creations[i].borrowables.length; k++) {
4848
engineConstants.poolConfigurator.setAssetBorrowableInEMode(
49-
creations[i].borrowable[k],
49+
creations[i].borrowables[k],
5050
categoryId,
5151
true
5252
);

tests/extensions/v3-config-engine/AaveV3ConfigEngineTest.t.sol

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {AaveV3MockPriceFeedUpdate} from './mocks/AaveV3MockPriceFeedUpdate.sol';
1717
import {AaveV3MockEModeCategoryUpdate, AaveV3MockEModeCategoryUpdateEdgeBonus} from './mocks/AaveV3MockEModeCategoryUpdate.sol';
1818
import {AaveV3MockEModeCategoryUpdateNoChange} from './mocks/AaveV3MockEModeCategoryUpdateNoChange.sol';
1919
import {AaveV3MockAssetEModeUpdate} from './mocks/AaveV3MockAssetEModeUpdate.sol';
20+
import {AaveV3MockEModeCategoryCreation} from './mocks/AaveV3MockEModeCategoryCreation.sol';
2021

2122
import {ATokenInstance} from '../../../src/contracts/instances/ATokenInstance.sol';
2223
import {EModeConfiguration} from '../../../src/contracts/protocol/libraries/configuration/EModeConfiguration.sol';
@@ -507,14 +508,59 @@ contract AaveV3ConfigEngineTest is TestnetProcedures, ProtocolV3TestBase {
507508
);
508509
}
509510

511+
function testEModeCategoryCreation() public {
512+
AaveV3MockEModeCategoryCreation payload = new AaveV3MockEModeCategoryCreation(
513+
tokenList.weth,
514+
tokenList.usdx,
515+
tokenList.wbtc,
516+
tokenList.weth,
517+
configEngine
518+
);
519+
520+
vm.prank(roleList.marketOwner);
521+
contracts.aclManager.addPoolAdmin(address(payload));
522+
523+
payload.execute();
524+
525+
DataTypes.EModeCategory memory prevEmodeCategoryData;
526+
prevEmodeCategoryData.ltv = 50_00;
527+
prevEmodeCategoryData.liquidationThreshold = 60_00;
528+
prevEmodeCategoryData.liquidationBonus = 101_00; // 100_00 + 1_00
529+
prevEmodeCategoryData.label = 'No assets';
530+
531+
uint256 bitmap = contracts.poolProxy.getEModeCategoryBorrowableBitmap(1);
532+
assertEq(bitmap, 0);
533+
bitmap = contracts.poolProxy.getEModeCategoryCollateralBitmap(1);
534+
assertEq(bitmap, 0);
535+
_validateEmodeCategory(
536+
IPoolAddressesProvider(address(contracts.poolAddressesProvider)),
537+
1,
538+
prevEmodeCategoryData
539+
);
540+
541+
prevEmodeCategoryData.ltv = 97_40;
542+
prevEmodeCategoryData.liquidationThreshold = 97_60;
543+
prevEmodeCategoryData.liquidationBonus = 101_50; // 100_00 + 1_50
544+
prevEmodeCategoryData.label = 'Test';
545+
prevEmodeCategoryData.collateralBitmap = 10; // 1010
546+
prevEmodeCategoryData.borrowableBitmap = 12; // 1100
547+
_validateEmodeCategory(
548+
IPoolAddressesProvider(address(contracts.poolAddressesProvider)),
549+
2,
550+
prevEmodeCategoryData
551+
);
552+
contracts.poolProxy.getEModeCategoryBorrowableBitmap(2);
553+
assertEq(bitmap, 0);
554+
bitmap = contracts.poolProxy.getEModeCategoryCollateralBitmap(2);
555+
assertEq(bitmap, 0);
556+
}
557+
510558
function testEModeCategoryUpdates() public {
511559
AaveV3MockEModeCategoryUpdate payload = new AaveV3MockEModeCategoryUpdate(configEngine);
512560

513561
vm.prank(roleList.marketOwner);
514562
contracts.aclManager.addPoolAdmin(address(payload));
515563

516-
contracts.poolProxy.getEModeCategoryData(1);
517-
518564
createConfigurationSnapshot(
519565
'preTestEngineEModeCategoryUpdate',
520566
IPool(address(contracts.poolProxy))
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// SPDX-License-Identifier: BUSL-1.1
2+
pragma solidity ^0.8.0;
3+
4+
import '../../../../src/contracts/extensions/v3-config-engine/AaveV3Payload.sol';
5+
6+
/**
7+
* @dev Smart contract for a mock emode category update, to be able to test
8+
* IMPORTANT Parameters are pseudo-random, DON'T USE THIS ANYHOW IN PRODUCTION
9+
* @dev Inheriting directly from AaveV3Payload for being able to inject a custom engine
10+
* @author BGD Labs
11+
*/
12+
contract AaveV3MockEModeCategoryCreation is AaveV3Payload {
13+
address immutable COLLATERAL_ONE;
14+
address immutable COLLATERAL_TWO;
15+
16+
address immutable BORROWABLE_ONE;
17+
address immutable BORROWABLE_TWO;
18+
19+
constructor(
20+
address collateral1,
21+
address collateral2,
22+
address borrowable1,
23+
address borrowable2,
24+
address customEngine
25+
) AaveV3Payload(IEngine(customEngine)) {
26+
COLLATERAL_ONE = collateral1;
27+
COLLATERAL_TWO = collateral2;
28+
BORROWABLE_ONE = borrowable1;
29+
BORROWABLE_TWO = borrowable2;
30+
}
31+
32+
function eModeCategoryCreations()
33+
public
34+
view
35+
override
36+
returns (IEngine.EModeCategoryCreation[] memory)
37+
{
38+
IEngine.EModeCategoryCreation[] memory eModeUpdates = new IEngine.EModeCategoryCreation[](2);
39+
40+
address[] memory empty = new address[](0);
41+
42+
eModeUpdates[0] = IEngine.EModeCategoryCreation({
43+
ltv: 50_00,
44+
liqThreshold: 60_00,
45+
liqBonus: 1_00,
46+
label: 'No assets',
47+
borrowables: empty,
48+
collaterals: empty
49+
});
50+
address[] memory collaterals = new address[](2);
51+
address[] memory borrowables = new address[](2);
52+
collaterals[0] = COLLATERAL_ONE;
53+
collaterals[1] = COLLATERAL_TWO;
54+
borrowables[0] = BORROWABLE_ONE;
55+
borrowables[1] = BORROWABLE_TWO;
56+
eModeUpdates[1] = IEngine.EModeCategoryCreation({
57+
ltv: 97_40,
58+
liqThreshold: 97_60,
59+
liqBonus: 1_50,
60+
label: 'Test',
61+
borrowables: borrowables,
62+
collaterals: collaterals
63+
});
64+
65+
return eModeUpdates;
66+
}
67+
68+
function getPoolContext() public pure override returns (IEngine.PoolContext memory) {
69+
return IEngine.PoolContext({networkName: 'Polygon', networkAbbreviation: 'Pol'});
70+
}
71+
}

tests/utils/ProtocolV3TestBase.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -757,12 +757,12 @@ contract ProtocolV3TestBase is DiffUtils {
757757
require(
758758
IPool(poolAddress).getEModeCategoryCollateralBitmap(uint8(category)) ==
759759
expectedCategoryData.collateralBitmap,
760-
'_validateEmodeCategory(): INVALID_LB'
760+
'_validateEmodeCategory(): INVALID_COLLATERALS'
761761
);
762762
require(
763763
IPool(poolAddress).getEModeCategoryBorrowableBitmap(uint8(category)) ==
764764
expectedCategoryData.borrowableBitmap,
765-
'_validateEmodeCategory(): INVALID_LB'
765+
'_validateEmodeCategory(): INVALID_BORROWABLES'
766766
);
767767
}
768768

0 commit comments

Comments
 (0)