-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added FixedRateStrategyFactory tests
- Loading branch information
1 parent
2de50ff
commit 4f67e2e
Showing
2 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import './TestGhoBase.t.sol'; | ||
|
||
contract TestFixedRateStrategyFactory is TestGhoBase { | ||
using ReserveConfiguration for DataTypes.ReserveConfigurationMap; | ||
|
||
function testConstructor() public { | ||
assertEq(FIXED_RATE_STRATEGY_FACTORY.POOL_ADDRESSES_PROVIDER(), address(PROVIDER)); | ||
address[] memory strategies = FIXED_RATE_STRATEGY_FACTORY.getAllStrategies(); | ||
|
||
assertEq(strategies.length, 0); | ||
} | ||
|
||
function testRevertConstructorInvalidExecutor() public { | ||
vm.expectRevert('INVALID_ADDRESSES_PROVIDER'); | ||
new FixedRateStrategyFactory(address(0)); | ||
} | ||
|
||
function testCreateStrategies() public { | ||
uint256[] memory rates = new uint256[](1); | ||
rates[0] = 100; | ||
|
||
address[] memory strategies = FIXED_RATE_STRATEGY_FACTORY.createStrategies(rates); | ||
|
||
assertEq(strategies.length, 1); | ||
assertEq(GhoInterestRateStrategy(strategies[0]).getBaseVariableBorrowRate(), rates[0]); | ||
} | ||
|
||
function testCreateStrategiesMultiple() public { | ||
uint256[] memory rates = new uint256[](3); | ||
rates[0] = 100; | ||
rates[1] = 200; | ||
rates[2] = 300; | ||
|
||
address[] memory strategies = FIXED_RATE_STRATEGY_FACTORY.createStrategies(rates); | ||
|
||
assertEq(strategies.length, 3); | ||
assertEq(GhoInterestRateStrategy(strategies[0]).getBaseVariableBorrowRate(), rates[0]); | ||
assertEq(GhoInterestRateStrategy(strategies[1]).getBaseVariableBorrowRate(), rates[1]); | ||
assertEq(GhoInterestRateStrategy(strategies[2]).getBaseVariableBorrowRate(), rates[2]); | ||
} | ||
|
||
function testCreateStrategiesCached() public { | ||
uint256[] memory rates = new uint256[](2); | ||
rates[0] = 100; | ||
rates[1] = 100; | ||
address[] memory strategies = FIXED_RATE_STRATEGY_FACTORY.createStrategies(rates); | ||
|
||
assertEq(strategies.length, 2); | ||
assertEq(strategies[0], strategies[1]); | ||
} | ||
|
||
function testCreatedStrategiesCachedDifferentCalls() public { | ||
uint256[] memory rates = new uint256[](1); | ||
rates[0] = 100; | ||
address[] memory strategies = FIXED_RATE_STRATEGY_FACTORY.createStrategies(rates); | ||
address[] memory strategies2 = FIXED_RATE_STRATEGY_FACTORY.createStrategies(rates); | ||
assertEq(strategies[0], strategies2[0]); | ||
} | ||
|
||
function testGetAllStrategies() public { | ||
uint256[] memory rates = new uint256[](3); | ||
rates[0] = 100; | ||
rates[1] = 200; | ||
rates[2] = 300; | ||
|
||
address[] memory strategies = FIXED_RATE_STRATEGY_FACTORY.createStrategies(rates); | ||
address[] memory strategiesCall = FIXED_RATE_STRATEGY_FACTORY.getAllStrategies(); | ||
|
||
assertEq(strategies.length, strategiesCall.length); | ||
assertEq(strategies[0], strategiesCall[0]); | ||
assertEq(strategies[1], strategiesCall[1]); | ||
assertEq(strategies[2], strategiesCall[2]); | ||
} | ||
|
||
function testGetAllStrategiesCached() public { | ||
uint256[] memory rates = new uint256[](2); | ||
rates[0] = 100; | ||
rates[1] = 100; | ||
|
||
FIXED_RATE_STRATEGY_FACTORY.createStrategies(rates); | ||
address[] memory strategies = FIXED_RATE_STRATEGY_FACTORY.getAllStrategies(); | ||
assertEq(strategies.length, 1); | ||
} | ||
|
||
function testGetStrategyByRate() public { | ||
uint256[] memory rates = new uint256[](3); | ||
rates[0] = 100; | ||
rates[1] = 200; | ||
rates[2] = 300; | ||
|
||
address[] memory strategies = FIXED_RATE_STRATEGY_FACTORY.createStrategies(rates); | ||
|
||
assertEq(FIXED_RATE_STRATEGY_FACTORY.getStrategyByRate(rates[0]), strategies[0]); | ||
assertEq(FIXED_RATE_STRATEGY_FACTORY.getStrategyByRate(rates[1]), strategies[1]); | ||
assertEq(FIXED_RATE_STRATEGY_FACTORY.getStrategyByRate(rates[2]), strategies[2]); | ||
} | ||
} |