diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5612135..78b148b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/test/Solaxy.invariant.t.sol b/test/Solaxy.invariant.t.sol index 5dd95a9..6008555 100644 --- a/test/Solaxy.invariant.t.sol +++ b/test/Solaxy.invariant.t.sol @@ -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; @@ -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 { @@ -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)); } } @@ -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); @@ -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)); @@ -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"); } diff --git a/test/Solaxy.t.sol b/test/Solaxy.t.sol index 7630e73..5f0b387 100644 --- a/test/Solaxy.t.sol +++ b/test/Solaxy.t.sol @@ -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; @@ -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)); @@ -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 { @@ -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); @@ -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); @@ -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"); }