Skip to content

Commit

Permalink
updated tests have a rough draft of imp
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Harvey committed Nov 14, 2023
1 parent 1b6292c commit 513d2d3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/libraries/external/LenderActions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ library LenderActions {
) external returns (uint256 fromBucketRedeemedLP_, uint256 toBucketLP_, uint256 movedAmount_, uint256 lup_) {
if (params_.fromIndex == params_.toIndex)
revert MoveToSameIndex();
if (params_.maxAmountToMove != 0 && params_.maxAmountToMove < poolState_.quoteTokenScale)
if (params_.maxAmountToMove < poolState_.quoteTokenScale)
revert DustAmountNotExceeded();
if (params_.toIndex == 0 || params_.toIndex > MAX_FENWICK_INDEX)
revert InvalidIndex();
Expand Down Expand Up @@ -834,7 +834,7 @@ library LenderActions {
unscaledRemovedAmount = unscaledDepositAvailable;
}

if (scaledDepositAvailable - removedAmount_ < params_.dustLimit) revert DustAmountNotExceeded();
if (scaledDepositAvailable - removedAmount_ != 0 && (scaledDepositAvailable - removedAmount_ < params_.dustLimit)) revert DustAmountNotExceeded();

unscaledRemaining_ = unscaledDepositAvailable - unscaledRemovedAmount;

Expand Down
6 changes: 3 additions & 3 deletions tests/forge/unit/ERC20Pool/ERC20PoolInputValidation.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ contract ERC20PoolBorrowTest is ERC20HelperContract {
_pool.addQuoteToken(1000, MAX_FENWICK_INDEX + 1, block.timestamp + 1, false);
}

function testValidateMoveQuoteTokenInput() external tearDown {
// revert on zero amount
vm.expectRevert(IPoolErrors.InvalidAmount.selector);
function testValidateMoveQuoteTokenInput() external {
// revert on innsufficientLiquidity amount if none in bucket
vm.expectRevert(IPoolErrors.DustAmountNotExceeded.selector);
_pool.moveQuoteToken(0, 1, 2, block.timestamp + 1, false);
// revert on move to same index
vm.expectRevert(IPoolErrors.MoveToSameIndex.selector);
Expand Down
22 changes: 19 additions & 3 deletions tests/forge/unit/ERC20Pool/ERC20PoolPrecision.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ contract ERC20PoolPrecisionTest is ERC20DSTestPlus {
uint16 fromBucketId_,
uint16 toBucketId_,
uint256 amountToMove_
) external tearDown {
) external {
// setup fuzzy bounds and initialize the pool
uint256 boundColPrecision = bound(uint256(collateralPrecisionDecimals_), 1, 18);
uint256 boundQuotePrecision = bound(uint256(quotePrecisionDecimals_), 1, 18);
Expand Down Expand Up @@ -702,7 +702,23 @@ contract ERC20PoolPrecisionTest is ERC20DSTestPlus {
return;
}

if (amountToMove != 0 && amountToMove < _quoteDust) {
if (amountToMove < _quoteDust) {

_assertMoveLiquidityDustRevert({
from: _lender,
amount: amountToMove,
fromIndex: fromBucketId,
toIndex: toBucketId
});

return;
}

// if fromBucket deposit - amount to move < _quoteDust
(, uint256 deposit,, uint256 lps,,) = _poolUtils.bucketInfo(address(_pool), fromBucketId);


if (deposit > amountToMove && deposit - amountToMove < _quoteDust) {
_assertMoveLiquidityDustRevert({
from: _lender,
amount: amountToMove,
Expand All @@ -724,7 +740,7 @@ contract ERC20PoolPrecisionTest is ERC20DSTestPlus {
});

// validate from and to buckets have appropriate amounts of deposit and LP
(, uint256 deposit,, uint256 lps,,) = _poolUtils.bucketInfo(address(_pool), fromBucketId);
(, deposit,, lps,,) = _poolUtils.bucketInfo(address(_pool), fromBucketId);
uint256 remaining = _lenderDepositNormalized - amountToMove;

assertEq(deposit, remaining);
Expand Down
4 changes: 2 additions & 2 deletions tests/forge/unit/ERC721Pool/ERC721PoolInputValidation.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ contract ERC721PoolBorrowTest is ERC721HelperContract {
}

function testValidateMoveQuoteTokenInput() external tearDown {
// revert on zero amount
vm.expectRevert(IPoolErrors.InvalidAmount.selector);
// revert on innsufficientLiquidity amount if none in bucket
vm.expectRevert(IPoolErrors.DustAmountNotExceeded.selector);
_pool.moveQuoteToken(0, 1, 2, block.timestamp + 1, false);
// revert on move to same index
vm.expectRevert(IPoolErrors.MoveToSameIndex.selector);
Expand Down

0 comments on commit 513d2d3

Please sign in to comment.