2023-09-12 16:37:30 +00:00
|
|
|
// SPDX-License-Identifier: UNLICENSED
|
|
|
|
pragma solidity ^0.8.19;
|
|
|
|
|
2023-10-10 13:44:16 +00:00
|
|
|
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
|
|
|
|
2023-09-12 16:37:30 +00:00
|
|
|
import { Test } from "forge-std/Test.sol";
|
|
|
|
import { Deploy } from "../script/Deploy.s.sol";
|
|
|
|
import { DeploymentConfig } from "../script/DeploymentConfig.s.sol";
|
|
|
|
import { StakeManager } from "../contracts/StakeManager.sol";
|
2023-10-10 13:44:16 +00:00
|
|
|
import { StakeVault } from "../contracts/StakeVault.sol";
|
2023-09-12 16:37:30 +00:00
|
|
|
|
|
|
|
contract StakeManagerTest is Test {
|
|
|
|
DeploymentConfig internal deploymentConfig;
|
|
|
|
StakeManager internal stakeManager;
|
|
|
|
|
2023-10-10 11:53:03 +00:00
|
|
|
address internal stakeToken;
|
|
|
|
address internal deployer;
|
2023-10-10 13:44:16 +00:00
|
|
|
address internal testUser = makeAddr("testUser");
|
2023-10-10 11:53:03 +00:00
|
|
|
|
2023-09-12 16:37:30 +00:00
|
|
|
function setUp() public virtual {
|
|
|
|
Deploy deployment = new Deploy();
|
|
|
|
(stakeManager, deploymentConfig) = deployment.run();
|
2023-10-10 11:53:03 +00:00
|
|
|
(deployer, stakeToken) = deploymentConfig.activeNetworkConfig();
|
2023-09-12 16:37:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testDeployment() public {
|
|
|
|
assertEq(stakeManager.owner(), deployer);
|
2023-10-10 11:53:03 +00:00
|
|
|
assertEq(stakeManager.currentEpoch(), 0);
|
|
|
|
assertEq(stakeManager.pendingReward(), 0);
|
|
|
|
assertEq(stakeManager.multiplierSupply(), 0);
|
|
|
|
assertEq(stakeManager.stakeSupply(), 0);
|
|
|
|
assertEq(address(stakeManager.stakedToken()), stakeToken);
|
|
|
|
assertEq(address(stakeManager.oldManager()), address(0));
|
2023-09-12 16:37:30 +00:00
|
|
|
assertEq(stakeManager.totalSupply(), 0);
|
|
|
|
}
|
2023-10-10 13:44:16 +00:00
|
|
|
|
|
|
|
function _createTestVault(address owner) internal returns (StakeVault vault) {
|
|
|
|
vm.prank(owner);
|
|
|
|
vault = new StakeVault(owner, ERC20(stakeToken), stakeManager);
|
|
|
|
|
|
|
|
vm.prank(deployer);
|
|
|
|
stakeManager.setVault(address(vault).codehash);
|
|
|
|
}
|
2023-09-12 16:37:30 +00:00
|
|
|
}
|
2023-10-10 13:32:46 +00:00
|
|
|
|
|
|
|
contract StakeTest is StakeManagerTest {
|
|
|
|
function setUp() public override {
|
|
|
|
StakeManagerTest.setUp();
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_RevertWhen_SenderIsNotVault() public {
|
|
|
|
vm.expectRevert(StakeManager.StakeManager__SenderIsNotVault.selector);
|
|
|
|
stakeManager.stake(100, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
contract UnstakeTest is StakeManagerTest {
|
|
|
|
function setUp() public override {
|
|
|
|
StakeManagerTest.setUp();
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_RevertWhen_SenderIsNotVault() public {
|
|
|
|
vm.expectRevert(StakeManager.StakeManager__SenderIsNotVault.selector);
|
|
|
|
stakeManager.unstake(100);
|
|
|
|
}
|
2023-10-10 13:44:16 +00:00
|
|
|
|
|
|
|
function test_RevertWhen_FundsLocked() public {
|
|
|
|
// ensure user has funds
|
|
|
|
deal(stakeToken, testUser, 1000);
|
|
|
|
StakeVault userVault = _createTestVault(testUser);
|
|
|
|
|
|
|
|
vm.startPrank(testUser);
|
|
|
|
ERC20(stakeToken).approve(address(userVault), 100);
|
|
|
|
|
|
|
|
uint256 lockTime = 1 days;
|
|
|
|
userVault.stake(100, lockTime);
|
|
|
|
|
|
|
|
vm.expectRevert(StakeManager.StakeManager__FundsLocked.selector);
|
|
|
|
userVault.unstake(100);
|
|
|
|
}
|
2023-10-10 13:32:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
contract LockTest is StakeManagerTest {
|
|
|
|
function setUp() public override {
|
|
|
|
StakeManagerTest.setUp();
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_RevertWhen_SenderIsNotVault() public {
|
|
|
|
vm.expectRevert(StakeManager.StakeManager__SenderIsNotVault.selector);
|
|
|
|
stakeManager.lock(100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
contract LeaveTest is StakeManagerTest {
|
|
|
|
function setUp() public override {
|
|
|
|
StakeManagerTest.setUp();
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_RevertWhen_SenderIsNotVault() public {
|
|
|
|
vm.expectRevert(StakeManager.StakeManager__SenderIsNotVault.selector);
|
|
|
|
stakeManager.leave();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
contract MigrateTest is StakeManagerTest {
|
|
|
|
function setUp() public override {
|
|
|
|
StakeManagerTest.setUp();
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_RevertWhen_SenderIsNotVault() public {
|
|
|
|
vm.expectRevert(StakeManager.StakeManager__SenderIsNotVault.selector);
|
|
|
|
stakeManager.migrate();
|
|
|
|
}
|
|
|
|
}
|