Skip to content

Commit

Permalink
Adds deposit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xhad committed Nov 1, 2024
1 parent 642c1e5 commit e8b4b5d
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 153 deletions.
4 changes: 0 additions & 4 deletions script/Actors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,24 @@ pragma solidity ^0.8.24;

interface IActors {
function ADMIN() external view returns (address);
function UNAUTHORIZED() external view returns (address);
function PROPOSER_1() external view returns (address);
function EXECUTOR_1() external view returns (address);
}

contract LocalActors is IActors {
address public constant ADMIN = address(1);
address public constant UNAUTHORIZED = address(3);
address public constant PROPOSER_1 = address(1);
address public constant EXECUTOR_1 = address(3);
}

contract HoleskyActors is IActors {
address public constant ADMIN = 0x743b91CDB1C694D4F51bCDA3a4A59DcC0d02b913;
address public constant UNAUTHORIZED = address(0);
address public constant PROPOSER_1 = 0x743b91CDB1C694D4F51bCDA3a4A59DcC0d02b913;
address public constant EXECUTOR_1 = 0x743b91CDB1C694D4F51bCDA3a4A59DcC0d02b913;
}

contract MainnetActors is IActors {
address public constant ADMIN = 0xfcad670592a3b24869C0b51a6c6FDED4F95D6975;
address public constant UNAUTHORIZED = address(0);
address public constant PROPOSER_1 = 0xfcad670592a3b24869C0b51a6c6FDED4F95D6975;
address public constant EXECUTOR_1 = 0xfcad670592a3b24869C0b51a6c6FDED4F95D6975;
}
6 changes: 3 additions & 3 deletions script/Constants.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.24;

contract ynBNBConstants {
contract Constants {
uint256 public constant MIN_DELAY = 84600;
string public constant VAULT_NAME = "YieldNest: BNB Liquid Restaking";
string public constant VAULT_SYMBOL = "ynBNB";
string public constant VAULT_NAME = "ynETH MAX";
string public constant VAULT_SYMBOL = "ynETHx";
}
8 changes: 4 additions & 4 deletions script/Contracts.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity ^0.8.24;

library HoleskyContracts {
address public constant WETH = 0x94373a4919B3240D86eA41593D5eBa789FEF3848;
}

library MainnetContracts {
address public constant WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
}

library HoleskyContracts {
address public constant WETH = 0x94373a4919B3240D86eA41593D5eBa789FEF3848;
}
134 changes: 0 additions & 134 deletions test/single/integration/ynBNB.bsc.t.sol

This file was deleted.

8 changes: 4 additions & 4 deletions test/single/unit/access.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ contract AccessControlTest is Test, LocalActors, TestConstants {
}

function skip_testNonAdminCannotGrantRole() public {
vm.startPrank(UNAUTHORIZED);
vm.startPrank(address(420));
vm.expectRevert(
abi.encodeWithSelector(
IAccessControl.AccessControlUnauthorizedAccount.selector, UNAUTHORIZED, vault.DEFAULT_ADMIN_ROLE()
IAccessControl.AccessControlUnauthorizedAccount.selector, address(420), vault.DEFAULT_ADMIN_ROLE()
)
);
vault.grantRole(vault.DEFAULT_ADMIN_ROLE(), address(4));
Expand All @@ -52,10 +52,10 @@ contract AccessControlTest is Test, LocalActors, TestConstants {
}

function skip_testNonAdminCannotRevokeRole() public {
vm.startPrank(UNAUTHORIZED);
vm.startPrank(address(420));
vm.expectRevert(
abi.encodeWithSelector(
IAccessControl.AccessControlUnauthorizedAccount.selector, UNAUTHORIZED, vault.DEFAULT_ADMIN_ROLE()
IAccessControl.AccessControlUnauthorizedAccount.selector, address(420), vault.DEFAULT_ADMIN_ROLE()
)
);
vault.revokeRole(vault.DEFAULT_ADMIN_ROLE(), address(1));
Expand Down
44 changes: 40 additions & 4 deletions test/single/unit/deposit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ contract DepositTest is Test, LocalActors, TestConstants {
vault = setup.createVault();
}

function testDeposit() public {
uint256 amount = 100 * 10 ** 18; // Assuming 18 decimals for the asset
function testDeposit(uint256 amount) public {
if (amount < 1) return;
if (amount > 1_000_000 ether) return;

asset.deposit{value: amount}();
asset.approve(address(vault), amount);
address USER = address(33);
Expand All @@ -44,9 +46,14 @@ contract DepositTest is Test, LocalActors, TestConstants {
assertEq(asset.balanceOf(address(vault)), amount + 1 ether, "Vault should have received the asset");
assertEq(vault.totalAssets(), amount + 1 ether, "Vault totalAsset should be amount deposited");
assertEq(vault.totalSupply(), totalShares, "Vault totalSupply should be amount deposited");
}


// Additional invariant tests
assertEq(vault.convertToAssets(shares), amount, "Converted assets should match the deposited amount");
assertEq(vault.maxDeposit(USER), type(uint256).max, "Max deposit for user should be unlimited");
assertEq(vault.maxMint(USER), type(uint256).max, "Max mint for user should be unlimited");
assertEq(vault.maxWithdraw(USER), shares, "Max withdraw for user should be equal to shares");
assertEq(vault.maxRedeem(USER), shares, "Max redeem for user should be equal to shares");
}

function skip_testDepositRevertsIfNotApproved() public {
uint256 amount = 100 * 10 ** 18; // Assuming 18 decimals for the asset
Expand All @@ -60,4 +67,33 @@ contract DepositTest is Test, LocalActors, TestConstants {
vm.expectRevert(abi.encodeWithSelector(IERC4626.deposit.selector, 0));
vault.deposit(0, ADMIN);
}

function testDepositETH(uint256 amount) public {
if (amount < 1) return;
if (amount > 1_000_000 ether) return;

uint256 bootstrap = 1 ether;
address USER = address(33);

deal(USER, amount);

// Deposit ETH directly to the vault
vm.prank(USER);
(bool success,) = address(vault).call{value: amount}("");
if (!success) revert("WETH Deposit failed");

uint256 totalShares = vault.convertToShares(amount);

assertEq(vault.balanceOf(USER), totalShares, "Balance of the user should be updated");
assertEq(asset.balanceOf(address(vault)) - bootstrap, amount, "Vault should have received the ETH");
assertEq(vault.totalAssets(), amount + bootstrap, "Vault totalAssets should be amount deposited");
assertEq(vault.totalSupply(), totalShares + bootstrap, "Vault totalSupply should be amount deposited");

// Additional invariant tests
assertEq(vault.convertToAssets(totalShares), amount, "Converted assets should match the deposited amount");
assertEq(vault.maxDeposit(USER), type(uint256).max, "Max deposit for user should be unlimited");
assertEq(vault.maxMint(USER), type(uint256).max, "Max mint for user should be unlimited");
assertEq(vault.maxWithdraw(USER), totalShares, "Max withdraw for user should be equal to total shares");
assertEq(vault.maxRedeem(USER), totalShares, "Max redeem for user should be equal to total shares");
}
}

0 comments on commit e8b4b5d

Please sign in to comment.