Skip to content

Commit

Permalink
Adapt v1 tests to accommodate ordering by interest rate
Browse files Browse the repository at this point in the history
  • Loading branch information
RickGriff committed Feb 4, 2024
1 parent cbe9d80 commit f6a5f85
Show file tree
Hide file tree
Showing 17 changed files with 714 additions and 792 deletions.
18 changes: 17 additions & 1 deletion contracts/src/TestContracts/BorrowerOperationsTester.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@ import "../BorrowerOperations.sol";
for testing the parent's internal functions. */
contract BorrowerOperationsTester is BorrowerOperations {

function getNewICRFromTroveChange
(
uint _coll,
uint _debt,
uint _collChange,
bool isCollIncrease,
uint _debtChange,
bool isDebtIncrease,
uint _price
)
external
pure
returns (uint)
{
return _getNewICRFromTroveChange(_coll, _debt, _collChange, isCollIncrease, _debtChange, isDebtIncrease, _price);
}

function getNewTCRFromTroveChange
(
uint _collChange,
Expand Down Expand Up @@ -39,7 +56,6 @@ contract BorrowerOperationsTester is BorrowerOperations {
_adjustTrove(_borrower, _collWithdrawal, _debtChange, _isDebtIncrease, 0);
}


// Payable fallback function
receive() external payable { }
}
20 changes: 11 additions & 9 deletions contracts/src/TestContracts/SortedTrovesTester.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,33 @@ pragma solidity 0.8.18;

import "../Interfaces/ISortedTroves.sol";


// Used as both a wrapper for SortedTroves functions and a mock TroveManager.
contract SortedTrovesTester {
ISortedTroves sortedTroves;

// --- SortedTroves external wrapper functions --
function setSortedTroves(address _sortedTrovesAddress) external {
sortedTroves = ISortedTroves(_sortedTrovesAddress);
}

function insert(address _id, uint256 _NICR, address _prevId, address _nextId) external {
sortedTroves.insert(_id, _NICR, _prevId, _nextId);
function insert(address _id, uint256 _annualInterestRate, address _prevId, address _nextId) external {
sortedTroves.insert(_id, _annualInterestRate, _prevId, _nextId);
}

function remove(address _id) external {
sortedTroves.remove(_id);
}

function reInsert(address _id, uint256 _newNICR, address _prevId, address _nextId) external {
sortedTroves.reInsert(_id, _newNICR, _prevId, _nextId);
function reInsert(address _id, uint256 _newAnnualInterestRate, address _prevId, address _nextId) external {
sortedTroves.reInsert(_id, _newAnnualInterestRate, _prevId, _nextId);
}

function getNominalICR(address) external pure returns (uint) {
// --- Mock TroveManager functions ---
function getTroveAnnualInterestRate(address) external pure returns (uint) {
return 1;
}

function getCurrentICR(address, uint) external pure returns (uint) {
return 1;
}
// function getCurrentICR(address, uint) external pure returns (uint) {
// return 1;
// }
}
2 changes: 2 additions & 0 deletions contracts/src/TroveManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,8 @@ contract TroveManager is LiquityBase, Ownable, CheckContract, ITroveManager {
* Liquidate a sequence of troves. Closes a maximum number of n under-collateralized Troves,
* starting from the one with the lowest collateral ratio in the system, and moving upwards
*/
// TODO: remove this liquidation function, since with ordering by interest rate, it is now redundant: there's no guarantee
// the bottom of the list has Troves with CR < MCR.
function liquidateTroves(uint _n) external override {
ContractsCache memory contractsCache = ContractsCache(
activePool,
Expand Down
28 changes: 0 additions & 28 deletions contracts/test/AccessControlTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ contract(
// Attempt call from alice
try {
const tx1 = await borrowerOperations.moveETHGainToTrove(
bob,
bob,
bob,
{ from: bob }
);
Expand All @@ -93,19 +91,6 @@ contract(
}
});

// updateRewardSnapshots
it("updateRewardSnapshots(): reverts when called by an account that is not BorrowerOperations", async () => {
// Attempt call from alice
try {
const txAlice = await troveManager.updateTroveRewardSnapshots(bob, {
from: alice,
});
} catch (err) {
assert.include(err.message, "revert");
// assert.include(err.message, "Caller is not the BorrowerOperations contract")
}
});

// removeStake
it("removeStake(): reverts when called by an account that is not BorrowerOperations", async () => {
// Attempt call from alice
Expand Down Expand Up @@ -154,19 +139,6 @@ contract(
}
});

// setTroveStatus
it("setTroveStatus(): reverts when called by an account that is not BorrowerOperations", async () => {
// Attempt call from alice
try {
const txAlice = await troveManager.setTroveStatus(bob, 1, {
from: alice,
});
} catch (err) {
assert.include(err.message, "revert");
// assert.include(err.message, "Caller is not the BorrowerOperations contract")
}
});

// increaseTroveColl
it("increaseTroveColl(): reverts when called by an account that is not BorrowerOperations", async () => {
// Attempt call from alice
Expand Down
Loading

0 comments on commit f6a5f85

Please sign in to comment.