Skip to content

Commit

Permalink
✅ Clean tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Flocqst committed Jun 26, 2024
1 parent 37b00d1 commit 12bfa07
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 33 deletions.
32 changes: 22 additions & 10 deletions test/KSXVault.t.sol
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.25;

import {Test} from "forge-std/Test.sol";
import {KSXVault} from "../src/KSXVault.sol";
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {Test} from "forge-std/Test.sol";
import {Bootstrap, KSXVault} from "test/utils/Bootstrap.sol";

contract KSXVaultTest is Bootstrap {

function setUp() public {
MockERC20 depositToken = new MockERC20("Deposit Token", "DT");
initializeLocal(address(depositToken), PDAOADDR);
}

/** @PR:REVIEW no tests for vault **/
/** @PR:REVIEW add pDAO test **/
/** @PR:REVIEW add share name **/
/** @PR:REVIEW add share symbol **/
/** @PR:REVIEW add use bootstrap everywhere instead of `Test` **/
function test_share_name() public {
assertEq(ksxVault.name(), "KSX Vault");
}

function test_share_symbol() public {
assertEq(ksxVault.symbol(), "KSX");
}

contract KSXVaultTest is Test {
function setUp() public {}
}

contract MockERC20 is ERC20 {
constructor(string memory name_, string memory symbol_)

constructor(
string memory name_,
string memory symbol_
)
ERC20(name_, symbol_)
{}

function mint(address to, uint256 amount) external {
_mint(to, amount);
}

}
40 changes: 17 additions & 23 deletions test/Upgrade.t.sol
Original file line number Diff line number Diff line change
@@ -1,35 +1,30 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.25;

import {Bootstrap, KSXVault} from "test/utils/Bootstrap.sol";
import {IKSXVault} from "src/interfaces/IKSXVault.sol";
import {Bootstrap, KSXVault} from "test/utils/Bootstrap.sol";
import {MockVaultUpgrade} from "test/utils/mocks/MockVaultUpgrade.sol";

contract UpgradeTest is Bootstrap {

address public _pDAO = 0xe826d43961a87fBE71C91d9B73F7ef9b16721C07;
address public _token = 0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85;

function setUp() public {
/** @PR:REVIEW unless there is a specific reason, avoid using fork tests **/
initializeOptimism();
initializeLocal(_token, _pDAO);
}
}

/** @PR:REVIEW not entirely sure why you split up UpgradeTest/MockUpgrade/UpgradeVault; if no specific reason combine. otherwise thats fine **/
}

contract MockUpgrade is UpgradeTest {

MockVaultUpgrade mockVaultUpgrade;

function deployMockVault() internal {
mockVaultUpgrade = new MockVaultUpgrade(
address(TOKEN),
address(pDAO)
);
mockVaultUpgrade = new MockVaultUpgrade(address(TOKEN), address(pDAO));
}

function test_upgrade() public {

/** @PR:REVIEW might as well fuzz the messages; never know what might be caught **/

string memory message = "hi";

function test_upgrade(string memory message) public {
bool success;
bytes memory response;

Expand Down Expand Up @@ -60,16 +55,12 @@ contract MockUpgrade is UpgradeTest {

ksxVault.upgradeToAndCall(address(mockVaultUpgrade), "");
}
}

contract UpgradeVault is UpgradeTest {}

contract RemoveUpgradability is UpgradeTest {
function test_removeUpgradability() public {

MockVaultUpgrade mockVaultUpgrade = new MockVaultUpgrade(
mockVaultUpgrade = new MockVaultUpgrade(
address(TOKEN),
address(0) // set pDAO to zero address to effectively remove upgradability
address(0) // set pDAO to zero address to effectively remove
// upgradability
);

vm.prank(pDAO);
Expand All @@ -78,8 +69,11 @@ contract RemoveUpgradability is UpgradeTest {

vm.prank(pDAO);

vm.expectRevert(abi.encodeWithSelector(IKSXVault.NonUpgradeable.selector));
vm.expectRevert(
abi.encodeWithSelector(IKSXVault.NonUpgradeable.selector)
);

ksxVault.upgradeToAndCall(address(mockVaultUpgrade), "");
}

}

0 comments on commit 12bfa07

Please sign in to comment.