Skip to content

Commit

Permalink
Merge pull request #3 from bgd-labs/feat/improvment-init-reserve-tests
Browse files Browse the repository at this point in the history
* Add intensive init reserve tests
  • Loading branch information
kyzia551 authored Apr 26, 2024
2 parents 07fdf89 + 0102427 commit 109595d
Show file tree
Hide file tree
Showing 6 changed files with 234 additions and 359 deletions.
11 changes: 8 additions & 3 deletions tests/core/PoolConfigurator.ACLModifiers.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@ import 'forge-std/Test.sol';

import {Errors} from 'aave-v3-core/contracts/protocol/libraries/helpers/Errors.sol';
import {ConfiguratorInputTypes} from 'aave-v3-core/contracts/protocol/pool/PoolConfigurator.sol';
import {TestnetProcedures} from '../utils/TestnetProcedures.sol';
import {TestnetProcedures, TestVars} from '../utils/TestnetProcedures.sol';

contract PoolConfiguratorACLModifiersTest is TestnetProcedures {
function setUp() public {
initTestEnvironment();
}

function test_reverts_notAdmin_initReserves(address caller) public {
ConfiguratorInputTypes.InitReserveInput[] memory input;
function test_reverts_notAdmin_initReserves(TestVars memory t, address caller) public {
ConfiguratorInputTypes.InitReserveInput[] memory input = _generateInitConfig(
t,
report,
poolAdmin,
true
);
vm.assume(
!contracts.aclManager.isPoolAdmin(caller) &&
!contracts.aclManager.isAssetListingAdmin(caller) &&
Expand Down
240 changes: 48 additions & 192 deletions tests/core/PoolConfigurator.initReserves.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,189 +23,76 @@ contract PoolConfiguratorInitReservesTest is TestnetProcedures {
initTestEnvironment();
}

function test_initReserves_singleAsset(bool isVirtualAccActive) public {
TestnetERC20 newToken = new TestnetERC20('Misc Token', 'MISC', 18, poolAdmin);

TestVars memory t;
t.aTokenName = 'Misc AToken';
t.aTokenSymbol = 'aMISC';
t.variableDebtName = 'Variable Debt Misc';
t.variableDebtSymbol = 'varDebtMISC';
t.stableDebtName = 'Stable Debt Misc';
t.stableDebtSymbol = 'stableDebtMISC';
t.rateStrategy = report.defaultInterestRateStrategyV2;
t.interestRateData = abi.encode(
IDefaultInterestRateStrategyV2.InterestRateData({
optimalUsageRatio: 80_00,
baseVariableBorrowRate: 1_00,
variableRateSlope1: 4_00,
variableRateSlope2: 60_00
})
);
function test_initReserves_validNumberOfAssets(TestVars[128] memory t, uint8 length) public {
vm.assume(length > 0 && length < 128);
uint256 previousListedAssets = contracts.poolProxy.getReservesList().length;
uint256 maxListings = contracts.poolProxy.MAX_NUMBER_RESERVES() - previousListedAssets + 1;
vm.assume(length < maxListings);

ConfiguratorInputTypes.InitReserveInput[]
memory input = new ConfiguratorInputTypes.InitReserveInput[](1);

input[0] = ConfiguratorInputTypes.InitReserveInput(
report.aToken,
report.stableDebtToken,
report.variableDebtToken,
newToken.decimals(),
isVirtualAccActive,
t.rateStrategy,
address(newToken),
report.treasury,
report.rewardsControllerProxy,
t.aTokenName,
t.aTokenSymbol,
t.variableDebtName,
t.variableDebtSymbol,
t.stableDebtName,
t.stableDebtSymbol,
t.emptyParams,
t.interestRateData
);
vm.expectEmit(true, false, false, false, address(contracts.poolConfiguratorProxy));
emit ReserveInitialized(
input[0].underlyingAsset,
address(0),
address(0),
address(0),
input[0].interestRateStrategyAddress
);

// Perform action
vm.prank(poolAdmin);
contracts.poolConfiguratorProxy.initReserves(input);

// Perform assertions
{
(address aTokenProxy, address stableDebtProxy, address variableDebtProxy) = contracts
.protocolDataProvider
.getReserveTokensAddresses(address(newToken));

assertEq(AToken(aTokenProxy).name(), t.aTokenName);
assertEq(AToken(aTokenProxy).symbol(), t.aTokenSymbol);
assertEq(AToken(aTokenProxy).decimals(), newToken.decimals());
assertEq(AToken(aTokenProxy).RESERVE_TREASURY_ADDRESS(), report.treasury);
assertEq(AToken(aTokenProxy).UNDERLYING_ASSET_ADDRESS(), address(newToken));
assertEq(
address(AToken(aTokenProxy).getIncentivesController()),
report.rewardsControllerProxy
);

assertEq(AToken(stableDebtProxy).name(), t.stableDebtName);
assertEq(AToken(stableDebtProxy).symbol(), t.stableDebtSymbol);
assertEq(AToken(stableDebtProxy).decimals(), newToken.decimals());
assertEq(AToken(stableDebtProxy).UNDERLYING_ASSET_ADDRESS(), address(newToken));
assertEq(
address(AToken(stableDebtProxy).getIncentivesController()),
report.rewardsControllerProxy
);

assertEq(AToken(variableDebtProxy).name(), t.variableDebtName);
assertEq(AToken(variableDebtProxy).symbol(), t.variableDebtSymbol);
assertEq(AToken(variableDebtProxy).decimals(), newToken.decimals());
assertEq(AToken(variableDebtProxy).UNDERLYING_ASSET_ADDRESS(), address(newToken));
assertEq(
address(AToken(variableDebtProxy).getIncentivesController()),
report.rewardsControllerProxy
);
}
// Perform default asset checks
TestReserveConfig memory c = _getReserveConfig(address(newToken), report.protocolDataProvider);

assertEq(c.isActive, true);
assertEq(c.isFrozen, false);
assertEq(c.isPaused, false);
assertEq(c.decimals, newToken.decimals());

assertEq(c.ltv, 0);
assertEq(c.liquidationThreshold, 0);
assertEq(c.liquidationBonus, 0);
assertEq(c.reserveFactor, 0);
assertEq(c.usageAsCollateralEnabled, false);
assertEq(c.borrowingEnabled, false);
assertEq(c.stableBorrowRateEnabled, false);
assertEq(c.isVirtualAccActive, isVirtualAccActive);
memory input = new ConfiguratorInputTypes.InitReserveInput[](length);
for (uint i = 0; i < length; i++) {
input[i] = _generateInitReserveInput(t[i], report, poolAdmin, true);

assertEq(contracts.poolProxy.getReservesList().length, previousListedAssets + 1);
}

function test_initReserves_multipleAssets() public {
ConfiguratorInputTypes.InitReserveInput[] memory input = _generateListingInput(
4,
report,
poolAdmin
);
uint256 previousListedAssets = contracts.poolProxy.getReservesList().length;

for (uint256 y; y < input.length; ++y) {
vm.expectEmit(true, false, false, false, address(contracts.poolConfiguratorProxy));
emit ReserveInitialized(
input[y].underlyingAsset,
input[i].underlyingAsset,
address(0),
address(0),
address(0),
input[y].interestRateStrategyAddress
input[i].interestRateStrategyAddress
);
}

// Perform action
vm.prank(poolAdmin);
contracts.poolConfiguratorProxy.initReserves(input);

// Perform assertions
for (uint256 y; y < input.length; ++y) {
ConfiguratorInputTypes.InitReserveInput memory reserveInput = input[y];

for (uint i = 0; i < length; i++) {
ConfiguratorInputTypes.InitReserveInput memory initConfig = input[i];
// Perform assertions
{
(address aTokenProxy, address stableDebtProxy, address variableDebtProxy) = contracts
.protocolDataProvider
.getReserveTokensAddresses(reserveInput.underlyingAsset);
.getReserveTokensAddresses(initConfig.underlyingAsset);

assertEq(AToken(aTokenProxy).name(), reserveInput.aTokenName);
assertEq(AToken(aTokenProxy).symbol(), reserveInput.aTokenSymbol);
assertEq(AToken(aTokenProxy).decimals(), reserveInput.underlyingAssetDecimals);
assertEq(AToken(aTokenProxy).RESERVE_TREASURY_ADDRESS(), reserveInput.treasury);
assertEq(AToken(aTokenProxy).UNDERLYING_ASSET_ADDRESS(), reserveInput.underlyingAsset);
assertEq(AToken(aTokenProxy).name(), initConfig.aTokenName);
assertEq(AToken(aTokenProxy).symbol(), initConfig.aTokenSymbol);
assertEq(AToken(aTokenProxy).decimals(), initConfig.underlyingAssetDecimals);
assertEq(AToken(aTokenProxy).RESERVE_TREASURY_ADDRESS(), initConfig.treasury);
assertEq(AToken(aTokenProxy).UNDERLYING_ASSET_ADDRESS(), initConfig.underlyingAsset);
assertEq(
address(AToken(aTokenProxy).getIncentivesController()),
reserveInput.incentivesController
initConfig.incentivesController
);

assertEq(AToken(stableDebtProxy).name(), reserveInput.stableDebtTokenName);
assertEq(AToken(stableDebtProxy).symbol(), reserveInput.stableDebtTokenSymbol);
assertEq(AToken(stableDebtProxy).decimals(), reserveInput.underlyingAssetDecimals);
assertEq(AToken(stableDebtProxy).UNDERLYING_ASSET_ADDRESS(), reserveInput.underlyingAsset);
assertEq(AToken(stableDebtProxy).name(), initConfig.stableDebtTokenName);
assertEq(AToken(stableDebtProxy).symbol(), initConfig.stableDebtTokenSymbol);
assertEq(AToken(stableDebtProxy).decimals(), initConfig.underlyingAssetDecimals);
assertEq(AToken(stableDebtProxy).UNDERLYING_ASSET_ADDRESS(), initConfig.underlyingAsset);
assertEq(
address(AToken(stableDebtProxy).getIncentivesController()),
reserveInput.incentivesController
initConfig.incentivesController
);

assertEq(AToken(variableDebtProxy).name(), reserveInput.variableDebtTokenName);
assertEq(AToken(variableDebtProxy).symbol(), reserveInput.variableDebtTokenSymbol);
assertEq(AToken(variableDebtProxy).decimals(), reserveInput.underlyingAssetDecimals);
assertEq(
AToken(variableDebtProxy).UNDERLYING_ASSET_ADDRESS(),
reserveInput.underlyingAsset
);
assertEq(AToken(variableDebtProxy).name(), initConfig.variableDebtTokenName);
assertEq(AToken(variableDebtProxy).symbol(), initConfig.variableDebtTokenSymbol);
assertEq(AToken(variableDebtProxy).decimals(), initConfig.underlyingAssetDecimals);
assertEq(AToken(variableDebtProxy).UNDERLYING_ASSET_ADDRESS(), initConfig.underlyingAsset);
assertEq(
address(AToken(variableDebtProxy).getIncentivesController()),
reserveInput.incentivesController
initConfig.incentivesController
);
}
// Perform default asset checks
TestReserveConfig memory c = _getReserveConfig(
reserveInput.underlyingAsset,
initConfig.underlyingAsset,
report.protocolDataProvider
);

assertEq(c.isActive, true);
assertEq(c.isFrozen, false);
assertEq(c.isPaused, false);
assertEq(c.decimals, reserveInput.underlyingAssetDecimals);
assertEq(c.decimals, initConfig.underlyingAssetDecimals);

assertEq(c.ltv, 0);
assertEq(c.liquidationThreshold, 0);
Expand All @@ -214,8 +101,9 @@ contract PoolConfiguratorInitReservesTest is TestnetProcedures {
assertEq(c.usageAsCollateralEnabled, false);
assertEq(c.borrowingEnabled, false);
assertEq(c.stableBorrowRateEnabled, false);
assertEq(c.isVirtualAccActive, initConfig.useVirtualBalance);
}
assertEq(contracts.poolProxy.getReservesList().length, previousListedAssets + input.length);
assertEq(contracts.poolProxy.getReservesList().length, previousListedAssets + length);
}

function test_initReserves_zeroAssets() public {
Expand All @@ -230,14 +118,16 @@ contract PoolConfiguratorInitReservesTest is TestnetProcedures {
assertEq(contracts.poolProxy.getReservesList().length, previousListedAssets);
}

function test_reverts_initReserves_maxAssets() public {
function test_reverts_initReserves_maxAssets(TestVars memory t, uint8 lengthSeed) public {
uint256 previousListedAssets = contracts.poolProxy.getReservesList().length;

uint256 maxListings = contracts.poolProxy.MAX_NUMBER_RESERVES() - previousListedAssets + 1;
ConfiguratorInputTypes.InitReserveInput[] memory input = _generateListingInput(
maxListings,
report,
poolAdmin
);
uint256 length = maxListings + lengthSeed;

ConfiguratorInputTypes.InitReserveInput[]
memory input = new ConfiguratorInputTypes.InitReserveInput[](length);
for (uint256 i = 0; i < length; i++)
input[i] = _generateInitReserveInput(t, report, poolAdmin, true);

vm.expectRevert(bytes(Errors.NO_MORE_RESERVES_ALLOWED));
vm.prank(poolAdmin);
Expand All @@ -246,48 +136,14 @@ contract PoolConfiguratorInitReservesTest is TestnetProcedures {
assertEq(contracts.poolProxy.getReservesList().length, previousListedAssets);
}

function test_initReserves_notEnoughDecimal(uint8 decimals) public {
vm.assume(decimals < 6);
TestnetERC20 newToken = new TestnetERC20('Misc Token', 'MISC', decimals, poolAdmin);
function test_initReserves_notEnoughDecimal(TestVars memory t) public {
vm.assume(t.underlyingDecimals < 6);

TestVars memory t;
t.aTokenName = 'Misc AToken';
t.aTokenSymbol = 'aMISC';
t.variableDebtName = 'Variable Debt Misc';
t.variableDebtSymbol = 'varDebtMISC';
t.stableDebtName = 'Stable Debt Misc';
t.stableDebtSymbol = 'stableDebtMISC';
t.rateStrategy = report.defaultInterestRateStrategyV2;
t.interestRateData = abi.encode(
IDefaultInterestRateStrategyV2.InterestRateData({
optimalUsageRatio: 80_00,
baseVariableBorrowRate: 1_00,
variableRateSlope1: 4_00,
variableRateSlope2: 60_00
})
);

ConfiguratorInputTypes.InitReserveInput[]
memory input = new ConfiguratorInputTypes.InitReserveInput[](1);

input[0] = ConfiguratorInputTypes.InitReserveInput(
report.aToken,
report.stableDebtToken,
report.variableDebtToken,
newToken.decimals(),
true,
t.rateStrategy,
address(newToken),
report.treasury,
report.rewardsControllerProxy,
t.aTokenName,
t.aTokenSymbol,
t.variableDebtName,
t.variableDebtSymbol,
t.stableDebtName,
t.stableDebtSymbol,
t.emptyParams,
t.interestRateData
ConfiguratorInputTypes.InitReserveInput[] memory input = _generateInitConfig(
t,
report,
poolAdmin,
false
);

vm.expectRevert(bytes(Errors.INVALID_DECIMALS));
Expand Down
Loading

0 comments on commit 109595d

Please sign in to comment.