Skip to content

Commit

Permalink
fix: improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sakulstra committed Aug 15, 2024
1 parent cbad6f9 commit 8de561d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 59 deletions.
30 changes: 14 additions & 16 deletions tests/periphery/static-a-token/ERC4626StataTokenUpgradeable.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ contract ERC4626StataTokenUpgradeableTest is TestnetProcedures {
}

function test_depositATokens(uint128 assets, address receiver) public {
vm.assume(receiver != address(0));
vm.assume(receiver != address(0));
TestEnv memory env = _setupTestEnv(assets);
_fundAToken(env.amount, user);

Expand All @@ -64,7 +64,7 @@ contract ERC4626StataTokenUpgradeableTest is TestnetProcedures {
}

function test_redeemATokens(uint256 assets, address receiver) public {
vm.assume(receiver != address(0));
vm.assume(receiver != address(0));
TestEnv memory env = _setupTestEnv(assets);
uint256 shares = _fund4626(env.amount, user);

Expand Down Expand Up @@ -147,8 +147,8 @@ contract ERC4626StataTokenUpgradeableTest is TestnetProcedures {
//TODO: perhaps makes sense to add maxDeposit test with accruedToTreasury etc

function test_maxRedeem_paused(uint128 assets) public {
TestEnv memory env = _setupTestEnv(assets);
uint256 shares = _fund4626(env.amount, user);
TestEnv memory env = _setupTestEnv(assets);
uint256 shares = _fund4626(env.amount, user);

vm.prank(address(roleList.marketOwner));
contracts.poolConfiguratorProxy.setReservePause(underlying, true);
Expand All @@ -159,8 +159,8 @@ contract ERC4626StataTokenUpgradeableTest is TestnetProcedures {
}

function test_maxRedeem_sufficientAvailableLiquidity(uint128 assets) public {
TestEnv memory env = _setupTestEnv(assets);
uint256 shares = _fund4626(env.amount, user);
TestEnv memory env = _setupTestEnv(assets);
uint256 shares = _fund4626(env.amount, user);

uint256 max = erc4626Upgradeable.maxRedeem(address(user));

Expand All @@ -170,23 +170,21 @@ contract ERC4626StataTokenUpgradeableTest is TestnetProcedures {
function test_maxRedeem_inSufficientAvailableLiquidity(uint256 amountToBorrow) public {
uint128 assets = 1 ether;
amountToBorrow = bound(amountToBorrow, 1, assets);
uint256 shares = _fund4626(assets, user);

// borrow out some assets
address borrowUser = address(99);
vm.startPrank(borrowUser);
deal(address(wbtc), borrowUser, 2_000e8);
wbtc.approve(address(contracts.poolProxy), 2_000e8);
contracts.poolProxy.deposit(address(wbtc), 2_000e8, borrowUser, 0);
contracts.poolProxy.borrow(underlying, amountToBorrow, 2, 0, borrowUser);
uint256 shares = _fund4626(assets, user);

// borrow out some assets
address borrowUser = address(99);
vm.startPrank(borrowUser);
deal(address(wbtc), borrowUser, 2_000e8);
wbtc.approve(address(contracts.poolProxy), 2_000e8);
contracts.poolProxy.deposit(address(wbtc), 2_000e8, borrowUser, 0);
contracts.poolProxy.borrow(underlying, amountToBorrow, 2, 0, borrowUser);

uint256 max = erc4626Upgradeable.maxRedeem(address(user));

assertEq(max, erc4626Upgradeable.previewRedeem(assets - amountToBorrow));
}


// ### tests for the token internal oracle
function test_latestAnswer_priceShouldBeEqualOnDefaultIndex() public {
vm.mockCall(
Expand Down
43 changes: 0 additions & 43 deletions tests/periphery/static-a-token/Stata4626LM.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -180,49 +180,6 @@ contract Stata4626LMTest is BaseTest {
staticATokenLM.mint(amountToDeposit, user);
}

/**
* maxDeposit test
*/


// should be 0 as supply is ~5k


function test_maxDeposit_50kCap() public {
vm.stopPrank();
vm.startPrank(address(roleList.marketOwner));
contracts.poolConfiguratorProxy.setSupplyCap(UNDERLYING, 50_000);

uint256 max = staticATokenLM.maxDeposit(address(0));
DataTypes.ReserveDataLegacy memory reserveData = POOL.getReserveData(UNDERLYING);
assertEq(
max,
50_000 *
(10 ** IERC20Metadata(UNDERLYING).decimals()) -
(IERC20Metadata(A_TOKEN).totalSupply() +
Math.mulDiv(
reserveData.accruedToTreasury,
POOL.getReserveNormalizedIncome(UNDERLYING),
1e27
))
);
}

/**
* maxRedeem test
*/

function test_maxRedeem_allAvailable() public {
uint128 amountToDeposit = 5 ether;
_fundUser(amountToDeposit, user);

_depositAToken(amountToDeposit, user);

uint256 max = staticATokenLM.maxRedeem(address(user));

assertEq(max, staticATokenLM.balanceOf(user));
}

function test_permit() public {
SigUtils.Permit memory permit = SigUtils.Permit({
owner: user,
Expand Down

0 comments on commit 8de561d

Please sign in to comment.