Skip to content

Commit

Permalink
snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
massun-onibakuchi committed Jun 3, 2024
1 parent 6e0081e commit 2e02e68
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions test/GrimReaper.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ abstract contract GrimReaperBaseTest is Test {
vm.expectCall(
POOL, abi.encodeWithSelector(MockPool.liquidationCall.selector, collateral, debt, user, amount, false)
);
vm.prank(owner);
_callLiquidate(address(collateral), address(debt), user, amount);
_callLiquidate(owner, address(collateral), address(debt), user, amount);

assertEq(debt.balanceOf(address(reaper)), 0);
assertEq(collateral.balanceOf(address(reaper)), liquidationBonus);
}

function _callLiquidate(address _col, address _debt, address _user, uint256 _debtToCover) public virtual {
function _callLiquidate(address caller, address _col, address _debt, address _user, uint256 _debtToCover) public virtual {
uint256 _before = gasleft();
vm.prank(caller);
(bool s, ) = address(reaper).call(abi.encodeCall(reaper.execute,(_col, _debt, _user, _debtToCover)));
uint256 _after = gasleft();
console2.log("Gas used: ", (_before - _after));
Expand All @@ -76,8 +76,7 @@ abstract contract GrimReaperBaseTest is Test {
function testRevertIfLiquidationFail() public {
pool.setLiquidation(false);
vm.expectRevert("ExpectRevert: liquidation failed");
vm.prank(owner);
this._callLiquidate(address(collateral), address(debt), address(0xcafe), 1000);
this._callLiquidate(owner, address(collateral), address(debt), address(0xcafe), 1000);
}

function testRecoverERC20() public virtual {
Expand All @@ -97,8 +96,7 @@ abstract contract GrimReaperBaseTest is Test {
vm.assume(non_user != owner);

vm.expectRevert();
vm.prank(non_user);
_callLiquidate(address(collateral), address(debt), address(0xcafe), 1000);
_callLiquidate(non_user, address(collateral), address(debt), address(0xcafe), 1000);

vm.expectRevert();
vm.prank(non_user);
Expand All @@ -117,10 +115,11 @@ contract OptimizedGrimReaperSolTest is GrimReaperBaseTest {
reaper = GrimReaper(address(new OptimizedGrimReaper()));
}

function _callLiquidate(address _col, address _debt, address _user, uint256 _debtToCover) public override {
function _callLiquidate(address caller, address _col, address _debt, address _user, uint256 _debtToCover) public override {
bytes memory payload = getLiquidationPayload(_col, _debt, _user, _debtToCover);

uint256 _before = gasleft();
vm.prank(caller);
(bool success,) = address(reaper).call(payload);
uint256 _after = gasleft();
console2.log("Gas used: ", (_before - _after));
Expand Down

0 comments on commit 2e02e68

Please # to comment.