Skip to content

Commit

Permalink
attemping to repair tests, added test case for non-m3ter holder
Browse files Browse the repository at this point in the history
  • Loading branch information
iChristwin committed Mar 7, 2024
1 parent 59f3305 commit c0cab01
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1.0.10
uses: foundry-rs/foundry-toolchain@v1.2.0
with:
version: nightly

Expand Down
17 changes: 9 additions & 8 deletions test/Solaxy.invariant.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {Solaxy} from "../src/Solaxy.sol";
import {IERC20} from "@openzeppelin/contracts@4.9.3/interfaces/IERC20.sol";
import {CannotBeZero, Undersupply} from "../src/interfaces/ISolaxy.sol";

uint256 constant sDAI_OneBillion = 1e9 * 1e18;
uint256 constant sDAI_balanceOneBillion = 1e9 * 1e18;

contract Handler is CommonBase, StdCheats, StdUtils {
Solaxy private SLX;
Expand All @@ -19,7 +19,7 @@ contract Handler is CommonBase, StdCheats, StdUtils {
constructor(Solaxy slx, IERC20 sdai) {
SLX = slx;
sDAI = sdai;
sDAI.approve(address(slx), sDAI_OneBillion);
sDAI.approve(address(slx), sDAI_balanceOneBillion);
}

function deposit(uint256 assets) public {
Expand All @@ -44,7 +44,7 @@ contract Handler is CommonBase, StdCheats, StdUtils {
function redeem(uint256 shares) public {
shares = bound(shares, 1e8, 1e20);
if (shares > SLX.totalSupply()) vm.expectRevert(Undersupply.selector);
if (shares > SLX.balanceOf(address(this))) vm.expectRevert(bytes("ERC20: transfer amount exceeds balance"));
if (shares > SLX.balanceOf(address(this))) vm.expectRevert(bytes("ERC20: burn amount exceeds balance"));
SLX.redeem(shares, address(this), address(this));
}
}
Expand All @@ -59,7 +59,7 @@ contract SolaxyInvarantTest is Test {

function setUp() public {
string memory url = vm.rpcUrl("gnosis-mainnet");
vm.createSelectFork(url);
vm.createSelectFork(url, 31_351_993);

SLX = new Solaxy(address(99));
SLX_address = address(SLX);
Expand All @@ -69,15 +69,16 @@ contract SolaxyInvarantTest is Test {

handler = new Handler(SLX, sDAI);
handlerAddress = address(handler);
deal(sDAI_address, handlerAddress, sDAI_OneBillion, true);
targetContract(handlerAddress);

deal(sDAI_address, handlerAddress, sDAI_balanceOneBillion, true);
dealERC721(address(SLX.M3ter()), handlerAddress, 1);

targetContract(handlerAddress);
}

function invariantValuation() public {
uint256 sDAI_balanceAfterTest = sDAI.balanceOf(handlerAddress);
uint256 solaxyTVL = sDAI_OneBillion - sDAI_balanceAfterTest;
uint256 solaxyTVL = sDAI_balanceOneBillion - sDAI_balanceAfterTest;
assertEq(SLX.totalAssets(), solaxyTVL, "Total value locked should be strictly equal to total reserve assets");

uint256 totalFees = SLX.balanceOf(address(99));
Expand All @@ -95,7 +96,7 @@ contract SolaxyInvarantTest is Test {
);
}

function testKnowAccountHoldingsOnMinnet() public {
function testKnowAccountBalance() public {
uint256 knowHolderBalance = sDAI.balanceOf(sDAI_address);
assertApproxEqAbs(knowHolderBalance, 30.5e18, 0.001e18, "sDAI balance should approximately equal 30.49 sDAI");
}
Expand Down
36 changes: 28 additions & 8 deletions test/Solaxy.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ pragma solidity ^0.8.19;

import {Test} from "forge-std/Test.sol";
import {Solaxy} from "../src/Solaxy.sol";
import {PayableErr} from "../src/interfaces/ISolaxy.sol";
import {PayableErr, RequiresM3ter} from "../src/interfaces/ISolaxy.sol";
import {IERC20} from "@openzeppelin/contracts@4.9.3/interfaces/IERC20.sol";
import {IERC721} from "@openzeppelin/contracts@4.9.3/interfaces/IERC721.sol";

contract SolaxyTest is Test {
contract SolaxyTestWithoutM3ter is Test {
Solaxy public SLX;
IERC20 public sDAI;
address public here;
Expand All @@ -22,7 +22,7 @@ contract SolaxyTest is Test {

function setUp() public {
string memory url = vm.rpcUrl("gnosis-mainnet");
vm.createSelectFork(url);
vm.createSelectFork(url, 31_351_993);
here = address(this);

SLX = new Solaxy(address(99));
Expand All @@ -32,8 +32,6 @@ contract SolaxyTest is Test {
sDAI = IERC20(sDAI_address);
deal(sDAI_address, here, sDAI_balanceOneMillion, true);
sDAI.approve(SLX_address, sDAI_balanceOneMillion);

dealERC721(address(SLX.M3ter()), here, 1);
}

function testInitialBalanceWithNewSolaxyContract() public {
Expand All @@ -48,7 +46,27 @@ contract SolaxyTest is Test {
assertEq(SLX_address.balance, 0 ether, "asset ether balance is still equal to zero");
}

function testDepositAndWithdraw() public {
function testNonM3terHolder() public {
vm.expectRevert(RequiresM3ter.selector);
// Deposit sDAI to Solaxy contract
SLX.deposit(sDAI_amountDeposited, here);

vm.expectRevert(RequiresM3ter.selector);
// Withdraw sDAI from Solaxy contract
SLX.withdraw(sDAI_amountWithdrawn, here, here);

vm.expectRevert(RequiresM3ter.selector);
// Mint new SLX tokens
SLX.mint(SLX_amountMinted, here);

vm.expectRevert(RequiresM3ter.selector);
// Redeem SLX tokens
SLX.redeem(SLX_amountIn, here, here);
}

function testM3terHolderDepositAndWithdraw() public {
dealERC721(address(SLX.M3ter()), here, 1);

uint256 SLX_InitialBalance = SLX.balanceOf(here);
uint256 sDAI_initialBalance = sDAI.balanceOf(SLX_address);

Expand Down Expand Up @@ -95,7 +113,9 @@ contract SolaxyTest is Test {
assertEq(SLX_feeBalance, 1795000000000000000);
}

function testMintAndRedeem() public {
function testM3terHolderMintAndRedeem() public {
dealERC721(address(SLX.M3ter()), here, 1);

uint256 SLX_initialBalance = SLX.balanceOf(here);
uint256 sDAI_initialBalance = sDAI.balanceOf(SLX_address);

Expand Down Expand Up @@ -145,7 +165,7 @@ contract SolaxyTest is Test {
assertEq(SLX_feeBalance, 1793880000000000000);
}

function testKnowAccountHoldingsOnMinnet() public {
function testKnowAccountBalance() public {
uint256 knowHolderBalance = sDAI.balanceOf(sDAI_address);
assertApproxEqAbs(knowHolderBalance, 30.5e18, 0.001e18, "sDAI balance should approximately equal 30.49 sDAI");
}
Expand Down

0 comments on commit c0cab01

Please sign in to comment.