Skip to content

Commit

Permalink
fix: Add active trove check to setInterestIndividualDelegate
Browse files Browse the repository at this point in the history
  • Loading branch information
bingen committed Sep 3, 2024
1 parent 5a1eee7 commit 7bafe74
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions contracts/src/BorrowerOperations.sol
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,7 @@ contract BorrowerOperations is LiquityBase, AddRemoveManagers, IBorrowerOperatio
uint256 _maxUpfrontFee
) external {
_requireIsNotShutDown();
_requireTroveIsActive(troveManager, _troveId);
_requireCallerIsBorrower(_troveId);
_requireValidAnnualInterestRate(_minInterestRate);
_requireValidAnnualInterestRate(_maxInterestRate);
Expand Down
38 changes: 38 additions & 0 deletions contracts/src/test/interestIndividualDelegation.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,44 @@ contract InterestIndividualDelegationTest is DevTestSetup {
vm.stopPrank();
}

function testSetDelegateRevertsIfTroveIsClosed() public {
vm.startPrank(B);
borrowerOperations.registerBatchManager(1e16, 20e16, 5e16, 25e14, MIN_INTEREST_RATE_CHANGE_PERIOD);
vm.stopPrank();

// Open trove
uint256 troveId = openTroveNoHints100pct(A, 100e18, 5000e18, 5e16);
// Open a second one, so it’s not the last one and to have BOLD for interest
openTroveNoHints100pctWithIndex(A, 1, 100e18, 5000e18, 5e16);
// Close trove
closeTrove(A, troveId);

// Set batch manager (B)
vm.startPrank(A);
vm.expectRevert(BorrowerOperations.TroveNotActive.selector);
borrowerOperations.setInterestIndividualDelegate(troveId, C, 1e16, 20e16, 0, 0, 0, 10000e18);
vm.stopPrank();
}

function testSetDelegateRevertsIfTroveIsUnredeemable() public {
vm.startPrank(B);
borrowerOperations.registerBatchManager(1e16, 20e16, 5e16, 25e14, MIN_INTEREST_RATE_CHANGE_PERIOD);
vm.stopPrank();

// Open trove
uint256 troveId = openTroveNoHints100pct(A, 100e18, 5000e18, 5e16);
// Make trove unredeemable
redeem(A, 4000e18);
// Check A’s trove is unredeemable
assertEq(troveManager.checkTroveIsUnredeemable(troveId), true, "A trove should be unredeemable");

// Set batch manager (B)
vm.startPrank(A);
vm.expectRevert(BorrowerOperations.TroveNotActive.selector);
borrowerOperations.setInterestIndividualDelegate(troveId, C, 1e16, 20e16, 0, 0, 0, 10000e18);
vm.stopPrank();
}

function testSetDelegateRevertsIfMinTooLow() public {
vm.startPrank(B);
borrowerOperations.registerBatchManager(1e16, 20e16, 5e16, 25e14, MIN_INTEREST_RATE_CHANGE_PERIOD);
Expand Down

0 comments on commit 7bafe74

Please sign in to comment.