Skip to content

Commit

Permalink
cleaned up folder naming and removed redundant function calls and dep…
Browse files Browse the repository at this point in the history
…reciated tests (#1043)

Co-authored-by: Ian Harvey <iharvey@comcast.net>
  • Loading branch information
ith-harvey and Ian Harvey authored Dec 19, 2023
1 parent 04c6ccd commit 9fd555c
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 244 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# (-include to ignore error if it does not exist)
-include .env && source ./tests/forge/invariants/scenarios/scenario-${SCENARIO}.sh

CONTRACT_EXCLUDES="RegressionTest|Panic|RealWorld|Trading|Rewards"
CONTRACT_EXCLUDES="RegressionTest|Panic|RealWorld|Trading"
TEST_EXCLUDES="testLoad|invariant|test_regression"

all: clean install build
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { PositionManager } from 'src/PositionManager.sol';
import { Maths } from 'src/libraries/internal/Maths.sol';

import { IBaseHandler } from '../interfaces/IBaseHandler.sol';
import { IPositionsAndRewardsHandler } from '../interfaces/IPositionsAndRewardsHandler.sol';
import { IPositionsHandler } from '../interfaces/IPositionsHandler.sol';
import { TokenWithNDecimals } from '../../utils/Tokens.sol';

import { ERC20PoolPositionHandler } from './handlers/ERC20PoolPositionHandler.sol';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { PositionManager } from 'src/PositionManager.sol';
import { Maths } from 'src/libraries/internal/Maths.sol';

import { IBaseHandler } from '../interfaces/IBaseHandler.sol';
import { IPositionsAndRewardsHandler } from '../interfaces/IPositionsAndRewardsHandler.sol';
import { IPositionsHandler } from '../interfaces/IPositionsHandler.sol';
import { BaseInvariants } from '../base/BaseInvariants.sol';
import { TokenWithNDecimals } from '../../utils/Tokens.sol';

Expand All @@ -32,7 +32,7 @@ abstract contract PositionsInvariants is BaseInvariants {
for (uint256 poolIndex = 0; poolIndex < _pools.length; poolIndex++) {
address pool = _pools[poolIndex];

uint256[] memory bucketIndexes = IPositionsAndRewardsHandler(_handler).getBucketIndexesWithPosition(pool);
uint256[] memory bucketIndexes = IPositionsHandler(_handler).getBucketIndexesWithPosition(pool);

// loop over bucket indexes with positions
for (uint256 i = 0; i < bucketIndexes.length; i++) {
Expand All @@ -45,7 +45,7 @@ abstract contract PositionsInvariants is BaseInvariants {
poolLpAccum += poolLp;

// loop over tokenIds in bucket indexes
uint256[] memory tokenIds = IPositionsAndRewardsHandler(_handler).getTokenIdsByBucketIndex(pool, bucketIndex);
uint256[] memory tokenIds = IPositionsHandler(_handler).getTokenIdsByBucketIndex(pool, bucketIndex);
for (uint256 k = 0; k < tokenIds.length; k++) {
uint256 tokenId = tokenIds[k];

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// SPDX-License-Identifier: UNLICENSED

pragma solidity 0.8.18;

import { PositionManager } from 'src/PositionManager.sol';
import { Pool } from 'src/base/Pool.sol';
import { ERC20Pool } from 'src/ERC20Pool.sol';
import { Maths } from 'src/libraries/internal/Maths.sol';

import { TokenWithNDecimals } from '../../../utils/Tokens.sol';

import { PositionPoolHandler } from './PositionPoolHandler.sol';
import { BaseERC20PoolHandler } from '../../ERC20Pool/handlers/unbounded/BaseERC20PoolHandler.sol';
import { UnboundedBasicPoolHandler } from '../../base/handlers/unbounded/UnboundedBasicPoolHandler.sol';
import { UnboundedBasicERC20PoolHandler } from '../../ERC20Pool/handlers/unbounded/UnboundedBasicERC20PoolHandler.sol';
import { UnboundedLiquidationPoolHandler } from '../../base/handlers/unbounded/UnboundedLiquidationPoolHandler.sol';
import '@std/console.sol';

contract ERC20PoolPositionHandler is PositionPoolHandler, BaseERC20PoolHandler, UnboundedBasicERC20PoolHandler, UnboundedLiquidationPoolHandler {

address[] internal _lenders;
address[] internal _borrowers;

uint16 internal constant LENDERS = 200;
uint256 numberOfBuckets;

constructor(
address positions_,
address[] memory pools_,
address ajna_,
address poolInfoUtils_,
uint256 numOfActors_,
address testContract_
) BaseERC20PoolHandler(pools_[0], ajna_, poolInfoUtils_, numOfActors_, testContract_) {

for (uint256 i = 0; i < pools_.length; i++) {
_pools.push(pools_[i]);
}

// Position manager
_positionManager = PositionManager(positions_);

// pool hash for mint() call
_poolHash = bytes32(keccak256("ERC20_NON_SUBSET_HASH"));
}

modifier useRandomPool(uint256 poolIndex) override {
poolIndex = bound(poolIndex, 0, _pools.length - 1);
updateTokenAndPoolAddress(_pools[poolIndex]);

_;
}

function updateTokenAndPoolAddress(address pool_) internal override {
_pool = Pool(pool_);
_erc20Pool = ERC20Pool(pool_);

_quote = TokenWithNDecimals(_pool.quoteTokenAddress());
_collateral = TokenWithNDecimals(_pool.collateralAddress());
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pragma solidity 0.8.18;

interface IPositionsAndRewardsHandler {
interface IPositionsHandler {
function getBucketIndexesWithPosition(address) external view returns(uint256[] memory);
function getBucketIndexesByTokenId(uint256) external view returns(uint256[] memory);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pragma solidity 0.8.18;

import { ERC20PoolPositionsInvariants } from "../../invariants/PositionsAndRewards/ERC20PoolPositionsInvariants.t.sol";
import { ERC20PoolPositionsInvariants } from "../../invariants/Positions/ERC20PoolPositionsInvariants.t.sol";

contract RegressionTestERC20PoolPositionManager is ERC20PoolPositionsInvariants {

Expand Down Expand Up @@ -117,27 +117,6 @@ contract RegressionTestERC20PoolPositionManager is ERC20PoolPositionsInvariants
invariant_positions_PM1_PM2_PM3();
}

// Test was failing because of incorrect borrower index from borrowers array
// Fixed with bounding index to use from 0 to `length - 1` instead of `length`
function test_regression_index_out_of_bounds() external {
_erc20positionHandler.moveQuoteTokenToLowerBucket(8350, 38563772714580316601477528168172448197192851223481495804140163882250050756970, 2631419556349366366777984756718, 1211945352);
_erc20positionHandler.takeOrSettleAuction(211495175470613993028534000000, 278145600165504025408587, 27529661686764881266950946609980959649419024772429123428587103668572353435463);
_erc20positionHandler.lenderKickAuction(115792089237316195423570985008687907853269984665640564039457584007913129639932, 6893553321768, 0);
_erc20positionHandler.lenderKickAuction(999993651401512530, 102781931937447242982, 270951946802940031780297034197);
_erc20positionHandler.moveQuoteTokenToLowerBucket(142908941962660588271918613275457408417799350540, 2, 7499, 21259944100462201457856802765711375950508);
_erc20positionHandler.takeOrSettleAuction(10312411154, 11741, 808194882698130156430790172156918);

invariant_positions_PM1_PM2_PM3();
}

// Test was failing because of unbounded bucket used for `fromBucketIndex`
// Fixed with bounding `fromBucketIndex`
function test_regression_max_less_than_min() external {
_erc20positionHandler.takeOrSettleAuction(115792089237316195423570985008687907853269984665640564039457584007913129639934, 47501406159061048326781, 110986208267306903569458210414739750843311008184499947884172946209775740554);
_erc20positionHandler.takeOrSettleAuction(1881514382560036936235, 3, 14814387297039010985037823532);
_erc20positionHandler.moveQuoteTokenToLowerBucket(797766346153846154214, 41446531673892822322, 11701, 27835018298679073652989722292632508325056543016077421626954570959368347669749);
}

function test_regression_position_manager() external {
_erc20positionHandler.redeemPositions(79335468733065507138817566659594782917024872257218805, 1889027018179489664211573893, 43578107449528230070726540147644518395094194018887636259089111851, 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pragma solidity 0.8.18;

import { ERC721PoolPositionsInvariants } from "../../invariants/PositionsAndRewards/ERC721PoolPositionsInvariants.t.sol";
import { ERC721PoolPositionsInvariants } from "../../invariants/Positions/ERC721PoolPositionsInvariants.t.sol";

contract RegressionTestERC721PoolPositionsManager is ERC721PoolPositionsInvariants {

Expand Down

0 comments on commit 9fd555c

Please sign in to comment.