Skip to content

Commit

Permalink
feat: moved event test to common cases instead of separate test
Browse files Browse the repository at this point in the history
  • Loading branch information
JoaquinBattilana committed Mar 7, 2024
1 parent 1e9e2c9 commit dfabf24
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 36 deletions.
4 changes: 2 additions & 2 deletions src/contracts/misc/GhoStewardV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ contract GhoStewardV2 is Ownable, IGhoStewardV2 {
uint256 public constant GHO_BORROW_RATE_MAX = 0.0950e27; // 9.50%

/// @inheritdoc IGhoStewardV2
uint256 public constant GHO_BORROW_RATE_CHANGE_MAX = 0.0050e27; // 0.5%
uint256 public constant GHO_BORROW_RATE_CHANGE_MAX = 0.0050e27; // 0.50%

/// @inheritdoc IGhoStewardV2
uint256 public constant GSM_FEE_RATE_CHANGE_MAX = 0.0050e4; // 0.5%
uint256 public constant GSM_FEE_RATE_CHANGE_MAX = 0.0050e4; // 0.50%

/// @inheritdoc IGhoStewardV2
uint256 public constant MINIMUM_DELAY = 7 days;
Expand Down
67 changes: 33 additions & 34 deletions src/test/TestFixedRateStrategyFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,17 @@ contract TestFixedRateStrategyFactory is TestGhoBase {
address[] memory strategies = new address[](1);
strategies[0] = address(new GhoInterestRateStrategy(address(PROVIDER), 100));

FIXED_RATE_STRATEGY_FACTORY.initialize(strategies);
address[] memory strategiesCall = FIXED_RATE_STRATEGY_FACTORY.getAllStrategies();

assertEq(strategiesCall.length, 1);
assertEq(strategiesCall[0], strategies[0]);
}

function testInitializeEmitEvent() public {
address[] memory strategies = new address[](1);
strategies[0] = address(new GhoInterestRateStrategy(address(PROVIDER), 100));

vm.expectEmit(true, true, false, false, address(FIXED_RATE_STRATEGY_FACTORY));
emit RateStrategyCreated(strategies[0], 100);
FIXED_RATE_STRATEGY_FACTORY.initialize(strategies);
}

function testInitializeMultiple() public {
address[] memory strategies = new address[](3);
strategies[0] = address(new GhoInterestRateStrategy(address(PROVIDER), 100));
strategies[1] = address(new GhoInterestRateStrategy(address(PROVIDER), 200));
strategies[2] = address(new GhoInterestRateStrategy(address(PROVIDER), 300));

FIXED_RATE_STRATEGY_FACTORY.initialize(strategies);
address[] memory strategiesCall = FIXED_RATE_STRATEGY_FACTORY.getAllStrategies();

assertEq(strategiesCall.length, 3);
assertEq(strategiesCall.length, 1);
assertEq(strategiesCall[0], strategies[0]);
assertEq(strategiesCall[1], strategies[1]);
assertEq(strategiesCall[2], strategies[2]);
}

function testInitializeMultipleEmitEvent() public {
function testInitializeMultiple() public {
address[] memory strategies = new address[](3);
strategies[0] = address(new GhoInterestRateStrategy(address(PROVIDER), 100));
strategies[1] = address(new GhoInterestRateStrategy(address(PROVIDER), 200));
Expand All @@ -65,7 +44,14 @@ contract TestFixedRateStrategyFactory is TestGhoBase {
emit RateStrategyCreated(strategies[1], 200);
vm.expectEmit(true, true, false, false, address(FIXED_RATE_STRATEGY_FACTORY));
emit RateStrategyCreated(strategies[2], 300);

FIXED_RATE_STRATEGY_FACTORY.initialize(strategies);
address[] memory strategiesCall = FIXED_RATE_STRATEGY_FACTORY.getAllStrategies();

assertEq(strategiesCall.length, 3);
assertEq(strategiesCall[0], strategies[0]);
assertEq(strategiesCall[1], strategies[1]);
assertEq(strategiesCall[2], strategies[2]);
}

function testRevertInitializeTwice() public {
Expand All @@ -81,29 +67,42 @@ contract TestFixedRateStrategyFactory is TestGhoBase {
uint256[] memory rates = new uint256[](1);
rates[0] = 100;

uint256 nonce = vm.getNonce(address(FIXED_RATE_STRATEGY_FACTORY));
address deployedStrategy = computeCreateAddress(address(FIXED_RATE_STRATEGY_FACTORY), nonce);
vm.expectEmit(true, true, false, false, address(FIXED_RATE_STRATEGY_FACTORY));
emit RateStrategyCreated(deployedStrategy, 100);

address[] memory strategies = FIXED_RATE_STRATEGY_FACTORY.createStrategies(rates);

assertEq(strategies.length, 1);
assertEq(GhoInterestRateStrategy(strategies[0]).getBaseVariableBorrowRate(), rates[0]);
}

function testCreateStrategiesEmitEvent() public {
uint256[] memory rates = new uint256[](1);
function testCreateStrategiesMultiple() public {
uint256[] memory rates = new uint256[](3);
rates[0] = 100;
rates[1] = 200;
rates[2] = 300;

uint256 nonce = vm.getNonce(address(FIXED_RATE_STRATEGY_FACTORY));
address deployedStrategy = computeCreateAddress(address(FIXED_RATE_STRATEGY_FACTORY), nonce);

address deployedStrategy1 = computeCreateAddress(address(FIXED_RATE_STRATEGY_FACTORY), nonce);
vm.expectEmit(true, true, false, false, address(FIXED_RATE_STRATEGY_FACTORY));
emit RateStrategyCreated(deployedStrategy, 100);
FIXED_RATE_STRATEGY_FACTORY.createStrategies(rates);
}
emit RateStrategyCreated(deployedStrategy1, 100);

function testCreateStrategiesMultiple() public {
uint256[] memory rates = new uint256[](3);
rates[0] = 100;
rates[1] = 200;
rates[2] = 300;
address deployedStrategy2 = computeCreateAddress(
address(FIXED_RATE_STRATEGY_FACTORY),
nonce + 1
);
vm.expectEmit(true, true, false, false, address(FIXED_RATE_STRATEGY_FACTORY));
emit RateStrategyCreated(deployedStrategy2, 200);

address deployedStrategy3 = computeCreateAddress(
address(FIXED_RATE_STRATEGY_FACTORY),
nonce + 2
);
vm.expectEmit(true, true, false, false, address(FIXED_RATE_STRATEGY_FACTORY));
emit RateStrategyCreated(deployedStrategy3, 300);

address[] memory strategies = FIXED_RATE_STRATEGY_FACTORY.createStrategies(rates);

Expand Down

0 comments on commit dfabf24

Please sign in to comment.