Skip to content

Commit

Permalink
add revert test and assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
haythemsellami committed Mar 27, 2024
1 parent 3c47d68 commit dd2dd65
Showing 1 changed file with 36 additions and 10 deletions.
46 changes: 36 additions & 10 deletions test/unit/evault/modules/Vault/liquidation.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,50 @@ contract VaultTest_Liquidation is EVaultTestBase {

startHoax(liquidator);

// deposit into eTST2 to cover the liability from liquidation
// assetTST2.approve(address(eTST2), type(uint256).max);
// eTST2.deposit(10e18, liquidator);

(uint256 maxRepay, uint256 yield) = eTST.checkLiquidation(liquidator, borrower, address(eTST2));

console.log("maxRepay", maxRepay);
console.log("yield", yield);
assertEq(maxRepay, 0);
assertEq(yield, 0);

oracle.setPrice(address(eTST2), unitOfAccount, 5e17);

(maxRepay, yield) = eTST.checkLiquidation(liquidator, borrower, address(eTST2));

console.log("maxRepay", maxRepay);
console.log("yield", yield);

evc.enableCollateral(liquidator, address(eTST2));
evc.enableController(liquidator, address(eTST));
eTST.liquidate(borrower, address(eTST2), type(uint256).max, 0);

assertEq(eTST.debtOf(liquidator), maxRepay);
assertEq(eTST2.balanceOf(liquidator), yield);
assertEq(eTST.debtOf(borrower), 0);
assertEq(eTST2.balanceOf(borrower), 0);
}

function test_liquidation_gt_maxRepay() public {
startHoax(borrower);

eTST2.deposit(10e18, borrower);

evc.enableCollateral(borrower, address(eTST2));
evc.enableController(borrower, address(eTST));

eTST.borrow(5e18, borrower);
assertEq(assetTST.balanceOf(borrower), 5e18);
vm.stopPrank();

startHoax(liquidator);

(uint256 maxRepay, uint256 yield) = eTST.checkLiquidation(liquidator, borrower, address(eTST2));
assertEq(maxRepay, 0);
assertEq(yield, 0);

oracle.setPrice(address(eTST2), unitOfAccount, 5e17);

(maxRepay, yield) = eTST.checkLiquidation(liquidator, borrower, address(eTST2));

evc.enableCollateral(liquidator, address(eTST2));
evc.enableController(liquidator, address(eTST));

vm.expectRevert(Errors.E_ExcessiveRepayAmount.selector);
eTST.liquidate(borrower, address(eTST2), maxRepay*2, 0);
}
}

0 comments on commit dd2dd65

Please sign in to comment.