Skip to content

Commit

Permalink
Adds failing ynLSD scenario test with failing invariants
Browse files Browse the repository at this point in the history
  • Loading branch information
xhad committed Mar 23, 2024
1 parent fdc503a commit e3c0d03
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions test/foundry/scenarios/ynLSD.spec.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity ^0.8.24;

import { IntegrationBaseTest } from "test/foundry/integration/IntegrationBaseTest.sol";
import { Invariants } from "test/foundry/scenarios/Invariants.sol";
import { IERC20 } from "@openzeppelin/contracts/interfaces/IERC20.sol";

contract YnLSDScenarioTest1 is IntegrationBaseTest {

/**
Scenario 1: Successful LSD Deposit and Share Minting
Objective: Test that a user can deposit stETH and receive
the correct amount of shares in return.
*/

address user1 = address(0x01);
address user2 = address(0x02);
address user3 = address(0x03);

function skip_test_ynLSD_Scenario_1_Fuzz(uint256 random1, uint256 random2, uint256 random3) public {

/**
Users deposit random amounts
- Check the total assets of ynLSD
- Check the share balance of each user
- Check the total deposited in the pool
- Check total supply of ynLSD
*/

vm.assume(random1 > 0 && random1 < 100_000_000 ether);
vm.assume(random2 > 0 && random2 < 100_000_000 ether);
vm.assume(random3 > 0 && random3 < 100_000_000 ether);

// user1 scenario depsoit random1 amount of stETH
uint256 user1Amount = random1;
(bool success1, ) = chainAddresses.lsd.STETH_ADDRESS.call{ value: user1Amount }("");
require(success1, "ETH transfer failed");
IERC20 steth = IERC20(chainAddresses.lsd.STETH_ADDRESS);

uint256 previousTotalDeposited;
uint256 previousTotalShares;

uint256 user1Shares = ynlsd.previewDeposit(steth, user1Amount);
steth.approve(address(ynlsd), user1Amount);
ynlsd.deposit(steth, user1Amount, user1);

previousTotalDeposited = 0;
previousTotalShares = 0;

runInvariants(user1, previousTotalDeposited, previousTotalShares, user1Amount, user1Shares);

// user 2 scenario depsoit random2 amount of stETH
previousTotalDeposited += user1Amount;
previousTotalShares += user1Shares;

uint256 user2Amount = random2;
(bool success2, ) = chainAddresses.lsd.STETH_ADDRESS.call{ value: user2Amount }("");
require(success2, "ETH transfer failed");

uint256 user2Shares = ynlsd.previewDeposit(steth, user2Amount);
steth.approve(address(ynlsd), user2Amount);
ynlsd.deposit(steth, user2Amount, user2);

runInvariants(user2, previousTotalDeposited, previousTotalShares, user2Amount, user2Shares);

// user 3 scenario depsoit random3 amount of stETH
previousTotalDeposited += user2Amount;
previousTotalShares += user2Shares;

uint256 user3Amount = random3;
(bool success3, ) = chainAddresses.lsd.STETH_ADDRESS.call{ value: user3Amount }("");
require(success3, "ETH transfer failed");

uint256 user3Shares = ynlsd.previewDeposit(steth, user3Amount);
steth.approve(address(ynlsd), user3Amount);
ynlsd.deposit(steth, user3Amount, user3);

runInvariants(user3, previousTotalDeposited, previousTotalShares, user3Amount, user3Shares);
}

function runInvariants(address user, uint256 previousTotalDeposited, uint256 previousTotalShares, uint256 userAmount, uint256 userShares) public view {
Invariants.totalAssetsIntegrity(ynlsd.totalAssets(), previousTotalDeposited, userAmount);
Invariants.shareMintIntegrity(ynlsd.totalSupply(), previousTotalShares, userShares);
Invariants.userSharesIntegrity(ynlsd.balanceOf(user), 0, userShares);
}
}

0 comments on commit e3c0d03

Please sign in to comment.