@@ -4,7 +4,6 @@ pragma solidity ^0.8.12;
44
55import {IEVC} from "ethereum-vault-connector/interfaces/IEthereumVaultConnector.sol " ;
66import {EVaultTestBase, TestERC20} from "evk-test/unit/evault/EVaultTestBase.t.sol " ;
7- import {DToken} from "euler-vault-kit/src/EVault/DToken.sol " ;
87import {IEVault, IERC4626 , IERC20 } from "evk/EVault/IEVault.sol " ;
98import {IRMTestZero} from "euler-vault-kit/test/mocks/IRMTestZero.sol " ;
109import {IAccessControl} from "openzeppelin-contracts/access/IAccessControl.sol " ;
@@ -46,18 +45,9 @@ contract HookTargetAccessControlKeyringTest is EVaultTestBase {
4645 address (evc), admin, address (factory), address (keyring), keyring.POLICY_ID ()
4746 );
4847
49- // Setup initial permissions
50- startHoax (admin);
51-
52- // Grant liquidator wild card permissions
53- hookTarget.grantRole (hookTarget.WILD_CARD (), liquidator);
54- vm.stopPrank ();
55-
56- // Setup keyring permissions
5748 keyring.setAllowed (user1, true );
5849 keyring.setAllowed (user2, true );
5950
60- // Setup vault hook for all relevant operations
6151 startHoax (address (this ));
6252 eTST.setHookConfig (
6353 address (hookTarget),
@@ -69,7 +59,7 @@ contract HookTargetAccessControlKeyringTest is EVaultTestBase {
6959 OP_DEPOSIT | OP_MINT | OP_REDEEM | OP_WITHDRAW | OP_BORROW | OP_REPAY | OP_LIQUIDATE | OP_SKIM
7060 | OP_REPAY_WITH_SHARES | OP_PULL_DEBT
7161 );
72-
62+
7363 oracle.setPrice (address (assetTST), unitOfAccount, 1e18 );
7464 oracle.setPrice (address (assetTST2), unitOfAccount, 1e18 );
7565 oracle.setPrice (address (eTST), unitOfAccount, 1e18 );
@@ -81,22 +71,18 @@ contract HookTargetAccessControlKeyringTest is EVaultTestBase {
8171 startHoax (user1);
8272 evc.enableCollateral (user1, address (eTST));
8373 evc.enableController (user1, address (eTST2));
84- vm.stopPrank ();
8574
86- // Setup test tokens and approvals
8775 startHoax (user1);
8876 assetTST.mint (user1, type (uint256 ).max);
8977 assetTST.approve (address (eTST), type (uint256 ).max);
9078 assetTST2.mint (user1, type (uint256 ).max);
9179 assetTST2.approve (address (eTST2), type (uint256 ).max);
92- vm.stopPrank ();
9380
9481 startHoax (user2);
9582 assetTST.mint (user2, type (uint256 ).max);
9683 assetTST.approve (address (eTST), type (uint256 ).max);
9784 assetTST2.mint (user2, type (uint256 ).max);
9885 assetTST2.approve (address (eTST2), type (uint256 ).max);
99- vm.stopPrank ();
10086 }
10187
10288 function swap (address tokenIn , uint256 amountIn , address tokenOut , uint256 amountOut , address recipient ) public {
@@ -361,11 +347,9 @@ contract HookTargetAccessControlKeyringTest is EVaultTestBase {
361347 function test_skim_WithValidCredentials () public {
362348 startHoax (user1);
363349 assetTST.transfer (address (eTST), 2e18 );
364- vm.stopPrank ();
365350
366351 startHoax (user2);
367352 evc.enableController (user2, address (eTST));
368- vm.stopPrank ();
369353
370354 startHoax (user2);
371355 eTST.skim (0.5e18 , user2);
@@ -375,11 +359,9 @@ contract HookTargetAccessControlKeyringTest is EVaultTestBase {
375359 function test_skim_WithInvalidCredentials () public {
376360 startHoax (user1);
377361 assetTST.transfer (address (eTST), 2e18 );
378- vm.stopPrank ();
379362
380363 startHoax (user2);
381364 evc.enableController (user2, address (eTST));
382- vm.stopPrank ();
383365
384366 keyring.setAllowed (user2, false );
385367 startHoax (user2);
@@ -390,11 +372,9 @@ contract HookTargetAccessControlKeyringTest is EVaultTestBase {
390372 function test_skim_WithMsgSenderHasInvalidCredentials () public {
391373 startHoax (user1);
392374 assetTST.transfer (address (eTST), 2e18 );
393- vm.stopPrank ();
394375
395376 startHoax (user2);
396377 evc.enableController (user2, address (eTST));
397- vm.stopPrank ();
398378
399379 keyring.setAllowed (user2, false );
400380 startHoax (user2);
@@ -405,11 +385,9 @@ contract HookTargetAccessControlKeyringTest is EVaultTestBase {
405385 function test_skim_WithOwnerHasInvalidCredentials () public {
406386 startHoax (user1);
407387 assetTST.transfer (address (eTST), 2e18 );
408- vm.stopPrank ();
409388
410389 startHoax (user2);
411390 evc.enableController (user2, address (eTST));
412- vm.stopPrank ();
413391
414392 keyring.setAllowed (user1, false );
415393 startHoax (user2);
@@ -500,7 +478,6 @@ contract HookTargetAccessControlKeyringTest is EVaultTestBase {
500478 evc.enableController (user2, address (eTST2));
501479 evc.enableCollateral (user2, address (eTST));
502480 eTST2.pullDebt (type (uint256 ).max, user1);
503- vm.stopPrank ();
504481
505482 assertEq (eTST2.debtOf (user1), 0 );
506483 assertEq (eTST2.debtOf (user2), 0.5e18 );
@@ -522,25 +499,10 @@ contract HookTargetAccessControlKeyringTest is EVaultTestBase {
522499 }
523500
524501 ///////////////////////////////
525- /// 10. Wildcard tests
502+ /// 10. liquidation tests
526503 ///////////////////////////////
527504
528- function test_roleBasedAccessControl () public {
529- vm.skip (true ); // TODO
530- }
531-
532- ///////////////////////////////
533- /// 11. liquidation tests
534- ///////////////////////////////
535-
536- function test_liquidate_WithValidCredentials () public {
537- startHoax (user2);
538- eTST2.deposit (100e18 , user2);
539- startHoax (user1);
540- eTST.deposit (10e18 , user1);
541- eTST2.borrow (4e18 , user1);
542- assertEq (eTST2.debtOf (user1), 4e18 );
543-
505+ function _buildLiquidationBatch () internal returns (IEVC.BatchItem[] memory ) {
544506 startHoax (address (this ));
545507 oracle.setPrice (address (eTST), unitOfAccount, 5e17 );
546508
@@ -600,17 +562,64 @@ contract HookTargetAccessControlKeyringTest is EVaultTestBase {
600562 value: 0 ,
601563 data: abi.encodeCall (IEVC.disableCollateral, (liquidator, address (eTST)))
602564 });
603-
565+
566+ return batchItems;
567+ }
568+
569+ function test_liquidate_WithLiquidatorHasWildCardPermissions () public {
570+ startHoax (user2);
571+ eTST2.deposit (100e18 , user2);
572+ startHoax (user1);
573+ eTST.deposit (10e18 , user1);
574+ eTST2.borrow (4e18 , user1);
575+ assertEq (eTST2.debtOf (user1), 4e18 );
576+ startHoax (admin);
577+ hookTarget.grantRole (hookTarget.WILD_CARD (), liquidator);
578+ IEVC.BatchItem[] memory batchItems = _buildLiquidationBatch ();
604579 evc.batch (batchItems);
605580 assertEq (eTST2.debtOf (user1), 0 );
606581 assertEq (eTST2.debtOf (liquidator), 0 );
607582 }
608583
609- function test_liquidate_WithInvalidCredentials () public {
610- vm.skip (true ); // TODO
584+ function test_liquidate_WithLiquidatorWithoutWildCardPermissions () public {
585+ startHoax (user2);
586+ eTST2.deposit (100e18 , user2);
587+ startHoax (user1);
588+ eTST.deposit (10e18 , user1);
589+ eTST2.borrow (4e18 , user1);
590+ assertEq (eTST2.debtOf (user1), 4e18 );
591+ IEVC.BatchItem[] memory batchItems = _buildLiquidationBatch ();
592+ vm.expectRevert (NotAuthorized.selector );
593+ evc.batch (batchItems);
611594 }
612595
613- function test_liquidate_WithPartialPermissions () public {
614- vm.skip (true ); // TODO
596+ function test_liquidate_WithLiquidatorHasWildCardPermissionsButUserNotPermitted () public {
597+ startHoax (user2);
598+ eTST2.deposit (100e18 , user2);
599+ startHoax (user1);
600+ eTST.deposit (10e18 , user1);
601+ eTST2.borrow (4e18 , user1);
602+ assertEq (eTST2.debtOf (user1), 4e18 );
603+ keyring.setAllowed (user1, false );
604+ keyring.setAllowed (user2, false );
605+ startHoax (admin);
606+ hookTarget.grantRole (hookTarget.WILD_CARD (), liquidator);
607+ IEVC.BatchItem[] memory batchItems = _buildLiquidationBatch ();
608+ evc.batch (batchItems);
609+ assertEq (eTST2.debtOf (user1), 0 );
610+ assertEq (eTST2.debtOf (liquidator), 0 );
611+ }
612+
613+ function test_liquidate_WithLiquidatorIsKeyringPermitted () public {
614+ startHoax (user2);
615+ eTST2.deposit (100e18 , user2);
616+ startHoax (user1);
617+ eTST.deposit (10e18 , user1);
618+ eTST2.borrow (4e18 , user1);
619+ assertEq (eTST2.debtOf (user1), 4e18 );
620+ keyring.setAllowed (liquidator, true );
621+ IEVC.BatchItem[] memory batchItems = _buildLiquidationBatch ();
622+ vm.expectRevert (NotAuthorized.selector );
623+ evc.batch (batchItems);
615624 }
616625}
0 commit comments