Skip to content

Commit

Permalink
refactor test structur.
Browse files Browse the repository at this point in the history
  • Loading branch information
clement-ux committed Sep 18, 2024
1 parent bbb36e1 commit aed6a70
Show file tree
Hide file tree
Showing 21 changed files with 536 additions and 429 deletions.
5 changes: 5 additions & 0 deletions src/contracts/utils/Addresses.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ library Mainnet {
address public constant OETH = 0x856c4Efb76C1D1AE02e20CEB03A2A6a08b0b8dC3;
address public constant WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
address public constant STETH = 0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84;
address public constant WSTETH = 0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0;

// Contracts
address public constant OETH_VAULT = 0x39254033945AA2E4809Cc2977E7087BEE48bd7Ab;
address public constant OETH_ARM = 0x6bac785889A4127dB0e0CeFEE88E0a9F1Aaf3cC7;

// Lido
address public constant LIDO_WITHDRAWAL = 0x889edC2eDab5f40e902b864aD4d7AdE8E412F9B1;
}

library Holesky {
Expand Down Expand Up @@ -66,6 +70,7 @@ contract AddressResolver {
resolver[MAINNET]["OETH"] = Mainnet.OETH;
resolver[MAINNET]["WETH"] = Mainnet.WETH;
resolver[MAINNET]["STETH"] = Mainnet.STETH;
resolver[MAINNET]["WSTETH"] = Mainnet.WSTETH;

// Contracts
resolver[MAINNET]["OETH_VAULT"] = Mainnet.OETH_VAULT;
Expand Down
9 changes: 9 additions & 0 deletions test/Base.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {Test} from "forge-std/Test.sol";
// Contracts
import {Proxy} from "contracts/Proxy.sol";
import {OethARM} from "contracts/OethARM.sol";
import {LidoOwnerLpARM} from "contracts/LidoOwnerLpARM.sol";
import {LidoFixedPriceMultiLpARM} from "contracts/LidoFixedPriceMultiLpARM.sol";

// Interfaces
import {IERC20} from "contracts/Interfaces.sol";
Expand All @@ -29,11 +31,16 @@ abstract contract Base_Test_ is Test {
/// --- CONTRACTS
//////////////////////////////////////////////////////
Proxy public proxy;
Proxy public lidoProxy;
Proxy public lidoOwnerProxy;
OethARM public oethARM;
LidoOwnerLpARM public lidoOwnerLpARM;
LidoFixedPriceMultiLpARM public lidoARM;

IERC20 public oeth;
IERC20 public weth;
IERC20 public steth;
IERC20 public wsteth;
IOETHVault public vault;

//////////////////////////////////////////////////////
Expand All @@ -44,11 +51,13 @@ abstract contract Base_Test_ is Test {
address public governor;
address public operator;
address public oethWhale;
address public feeCollector;

//////////////////////////////////////////////////////
/// --- DEFAULT VALUES
//////////////////////////////////////////////////////
uint256 public constant DEFAULT_AMOUNT = 1 ether;
uint256 public constant STETH_ERROR_ROUNDING = 2;

//////////////////////////////////////////////////////
/// --- SETUP
Expand Down
33 changes: 33 additions & 0 deletions test/fork/LidoFixedPriceMultiLpARM/Constructor.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;

// Test imports
import {Fork_Shared_Test_} from "test/fork/shared/Shared.sol";

contract Fork_Concrete_LidoFixedPriceMultiLpARM_Constructor_Test is Fork_Shared_Test_ {
//////////////////////////////////////////////////////
/// --- SETUP
//////////////////////////////////////////////////////
function setUp() public override {
super.setUp();
}

//////////////////////////////////////////////////////
/// --- PASSING TESTS
//////////////////////////////////////////////////////
function test_Initial_State() public {
assertEq(lidoARM.name(), "Lido ARM");
assertEq(lidoARM.symbol(), "ARM-ST");
assertEq(lidoARM.owner(), address(this));
assertEq(lidoARM.operator(), operator);
assertEq(lidoARM.feeCollector(), feeCollector);
assertEq(lidoARM.fee(), 2000);
assertEq(lidoARM.lastTotalAssets(), 1e12);
assertEq(lidoARM.feesAccrued(), 0);
// the 20% performance fee is removed on initialization
assertEq(lidoARM.totalAssets(), 1e12);
assertEq(lidoARM.totalSupply(), 1e12);
assertEq(weth.balanceOf(address(lidoARM)), 1e12);
assertEq(lidoARM.totalAssetsCap(), 100 ether);
}
}
76 changes: 76 additions & 0 deletions test/fork/LidoFixedPriceMultiLpARM/Deposit.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;

// Test imports
import {Fork_Shared_Test_} from "test/fork/shared/Shared.sol";

contract Fork_Concrete_LidoFixedPriceMultiLpARM_Deposit_Test_ is Fork_Shared_Test_ {
AssertData beforeData;
DeltaData noChangeDeltaData =
DeltaData({totalAssets: 10, totalSupply: 0, totalAssetsCap: 0, armWeth: 0, armSteth: 0, feesAccrued: 0});

struct AssertData {
uint256 totalAssets;
uint256 totalSupply;
uint256 totalAssetsCap;
uint256 armWeth;
uint256 armSteth;
uint256 feesAccrued;
}

struct DeltaData {
int256 totalAssets;
int256 totalSupply;
int256 totalAssetsCap;
int256 armWeth;
int256 armSteth;
int256 feesAccrued;
}

function _snapData() internal view returns (AssertData memory data) {
return AssertData({
totalAssets: lidoARM.totalAssets(),
totalSupply: lidoARM.totalSupply(),
totalAssetsCap: lidoARM.totalAssetsCap(),
armWeth: weth.balanceOf(address(lidoARM)),
armSteth: steth.balanceOf(address(lidoARM)),
feesAccrued: lidoARM.feesAccrued()
});
}

function assertData(AssertData memory before, DeltaData memory delta) internal view {
AssertData memory afterData = _snapData();

assertEq(int256(afterData.totalAssets), int256(before.totalAssets) + delta.totalAssets, "totalAssets");
assertEq(int256(afterData.totalSupply), int256(before.totalSupply) + delta.totalSupply, "totalSupply");
assertEq(
int256(afterData.totalAssetsCap), int256(before.totalAssetsCap) + delta.totalAssetsCap, "totalAssetsCap"
);
assertEq(int256(afterData.feesAccrued), int256(before.feesAccrued) + delta.feesAccrued, "feesAccrued");
assertEq(int256(afterData.armWeth), int256(before.armWeth) + delta.armWeth, "armWeth");
assertEq(int256(afterData.armSteth), int256(before.armSteth) + delta.armSteth, "armSteth");
}

//////////////////////////////////////////////////////
/// --- SETUP
//////////////////////////////////////////////////////
function setUp() public override {
super.setUp();
}

//////////////////////////////////////////////////////
/// --- PASSING TESTS
//////////////////////////////////////////////////////
function test_Deposit_SimpleCase() public setLiquidityProviderCap(address(this), 20 ether) {
deal(address(weth), address(this), 10 ether);
beforeData = _snapData();

lidoARM.deposit(10 ether);

DeltaData memory delta = noChangeDeltaData;
delta.totalAssets = 10 ether;
delta.totalSupply = 10 ether;
delta.armWeth = 10 ether;
assertData(beforeData, delta);
}
}
24 changes: 24 additions & 0 deletions test/fork/LidoFixedPriceMultiLpARM/RequestRedeem.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;

// Test imports
import {Fork_Shared_Test_} from "test/fork/shared/Shared.sol";

contract Fork_Concrete_LidoFixedPriceMultiLpARM_RequestRedeem_Test_ is Fork_Shared_Test_ {
//////////////////////////////////////////////////////
/// --- SETUP
//////////////////////////////////////////////////////
function setUp() public override {
super.setUp();
}

//////////////////////////////////////////////////////
/// --- PASSING TESTS
//////////////////////////////////////////////////////
function test_RequestRedeem_SimpleCase() public setLiquidityProviderCap(address(this), 20 ether) {
deal(address(weth), address(this), 10 ether);

lidoARM.deposit(10 ether);
lidoARM.requestRedeem(8 ether);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

/*
import {Test, console2} from "forge-std/Test.sol";
import {IERC20} from "contracts/Interfaces.sol";
Expand Down Expand Up @@ -207,3 +207,4 @@ contract Fork_Concrete_LidoMultiPriceMultiLpARM_Test is Fork_Shared_Test_ {
// with only liquidity in the fifth tranche
//// swap stETH to WETH using just the fifth tranche
}
*/
97 changes: 97 additions & 0 deletions test/fork/LidoOwnerLpARM/Setters.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;

// Test imports
import {Fork_Shared_Test_} from "test/fork/shared/Shared.sol";

contract Fork_Concrete_LidoOwnerLpARM_Setters_Test_ is Fork_Shared_Test_ {
//////////////////////////////////////////////////////
/// --- SETUP
//////////////////////////////////////////////////////
function setUp() public override {
super.setUp();
}

//////////////////////////////////////////////////////
/// --- REVERTING TESTS
//////////////////////////////////////////////////////
function test_RevertWhen_SetPrices_Because_PriceCross() public {
vm.expectRevert("ARM: Price cross");
lidoOwnerLpARM.setPrices(90 * 1e33, 89 * 1e33);
vm.expectRevert("ARM: Price cross");
lidoOwnerLpARM.setPrices(72, 70);
vm.expectRevert("ARM: Price cross");
lidoOwnerLpARM.setPrices(1005 * 1e33, 1000 * 1e33);
}

function test_RevertWhen_SetPrices_Because_TraderateTooHigh() public {
//vm.expectRevert("ARM: Traderates too high");
//lidoOwnerLpARM.setPrices(1010 * 1e33, 1020 * 1e33);
//vm.expectRevert("ARM: Traderates too high");
//lidoOwnerLpARM.setPrices(993 * 1e33, 994 * 1e33);
}

function test_RevertWhen_SetPrices_Because_TooMuchLoss() public {
// Failing
/*
uint256 currentFunds = lidoOwnerLpARM.token0().balanceOf(address(lidoOwnerLpARM))
+ lidoOwnerLpARM.token1().balanceOf(address(lidoOwnerLpARM));
// Reduce minimum funds by 100
lidoOwnerLpARM.setMinimumFunds(currentFunds + 100 ether);
vm.expectRevert("ARM: Too much loss");
lidoOwnerLpARM.setPrices(992 * 1e33, 1001 * 1e33);
*/
}

function test_RevertWhen_SetPrices_Because_NotOwnerOrOperator() public asRandomAddress {
vm.expectRevert("ARM: Only operator or owner can call this function.");
lidoOwnerLpARM.setPrices(0, 0);
}

function test_RevertWhen_SetOwner_Because_NotOwner() public asRandomAddress {
vm.expectRevert("ARM: Only owner can call this function.");
lidoOwnerLpARM.setOwner(address(0));
}

function test_RevertWhen_SetOperator_Because_NotOwner() public asRandomAddress {
vm.expectRevert("ARM: Only owner can call this function.");
lidoOwnerLpARM.setOperator(address(0));
}

//////////////////////////////////////////////////////
/// --- PASSING TESTS
//////////////////////////////////////////////////////
// Todo: create a aslidoOwnerLpARMOwner modifier
function test_SetPrices() public {
lidoOwnerLpARM.setPrices(992 * 1e33, 1001 * 1e33);
lidoOwnerLpARM.setPrices(1001 * 1e33, 1004 * 1e33);
lidoOwnerLpARM.setPrices(992 * 1e33, 2000 * 1e33);

// Check the traderates
assertEq(lidoOwnerLpARM.traderate0(), 500 * 1e33);
assertEq(lidoOwnerLpARM.traderate1(), 992 * 1e33);
}

function test_SetPrices_When_MinimumFundsHasBeenDecrease() public {
deal(address(weth), address(lidoOwnerLpARM), 100 ether);
uint256 currentFunds = lidoOwnerLpARM.token0().balanceOf(address(lidoOwnerLpARM))
+ lidoOwnerLpARM.token1().balanceOf(address(lidoOwnerLpARM));

// Reduce minimum funds by 100
lidoOwnerLpARM.setMinimumFunds(currentFunds - 100);

lidoOwnerLpARM.setPrices(992 * 1e33, 1001 * 1e33);
}

function test_SetOperator() public {
lidoOwnerLpARM.setOperator(address(this));
assertEq(lidoOwnerLpARM.operator(), address(this));
}

function test_SetMinimumFunds() external {
lidoOwnerLpARM.setMinimumFunds(100 ether);
assertEq(lidoOwnerLpARM.minimumFunds(), 100 ether);
}
}
Loading

0 comments on commit aed6a70

Please sign in to comment.