Skip to content

Commit

Permalink
test(StakeManager): add test to check that inital MPs are minted
Browse files Browse the repository at this point in the history
This adds a test that ensures multiplier points are minted with a 1:1
ratio to the stake token amount.

This scenario covers the case where no lock up time is set during
staking.
  • Loading branch information
0x-r4bbit committed Jan 19, 2024
1 parent 74ff357 commit 81a4afa
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 4 deletions.
4 changes: 2 additions & 2 deletions contracts/StakeManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ contract StakeManager is Ownable {
uint256 public constant MP_APY = 1;
uint256 public constant MAX_BOOST = 4;

mapping(address => Account) accounts;
mapping(address => Account) public accounts;
mapping(uint256 => Epoch) epochs;
mapping(bytes32 => bool) isVault;
mapping(bytes32 => bool) public isVault;

uint256 public currentEpoch;
uint256 public pendingReward;
Expand Down
73 changes: 71 additions & 2 deletions test/StakeManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ contract StakeManagerTest is Test {
address internal stakeToken;
address internal deployer;
address internal testUser = makeAddr("testUser");
address internal testUser2 = makeAddr("testUser2");

function setUp() public virtual {
Deploy deployment = new Deploy();
Expand All @@ -40,8 +41,10 @@ contract StakeManagerTest is Test {
vm.prank(owner);
vault = vaultFactory.createVault();

vm.prank(deployer);
stakeManager.setVault(address(vault).codehash);
if (!stakeManager.isVault(address(vault).codehash)) {
vm.prank(deployer);
stakeManager.setVault(address(vault).codehash);
}
}
}

Expand Down Expand Up @@ -71,6 +74,32 @@ contract StakeTest is StakeManagerTest {
vm.expectRevert(StakeManager.StakeManager__InvalidLockupPeriod.selector);
userVault.stake(100, lockTime);
}

function test_StakeWithoutLockUpTimeMintsMultiplierPoints() public {
// ensure user has funds
deal(stakeToken, testUser, 1000);
StakeVault userVault = _createTestVault(testUser);

vm.startPrank(testUser);
ERC20(stakeToken).approve(address(userVault), 100);

// stake without lockup time
userVault.stake(100, 0);

(,, uint256 multiplierPoints,,,) = stakeManager.accounts(address(userVault));

// total multiplier poitn supply
assertEq(stakeManager.multiplierSupply(), 100);
// user multiplier points
assertEq(multiplierPoints, 100);

userVault.unstake(100);

// multiplierpoints are burned after unstaking
(,, multiplierPoints,,,) = stakeManager.accounts(address(userVault));
assertEq(stakeManager.multiplierSupply(), 0);
assertEq(multiplierPoints, 0);
}
}

contract UnstakeTest is StakeManagerTest {
Expand Down Expand Up @@ -215,3 +244,43 @@ contract ExecuteAccountTest is StakeManagerTest {
stakeManager.executeAccount(address(userVault), currentEpoch + 1);
}
}

contract UserFlowsTest is StakeManagerTest {
function setUp() public override {
StakeManagerTest.setUp();
}

function test_StakedSupplyShouldIncreaseAndDecreaseAgain() public {
// ensure users have funds
deal(stakeToken, testUser, 1000);
deal(stakeToken, testUser2, 1000);

StakeVault userVault = _createTestVault(testUser);
StakeVault user2Vault = _createTestVault(testUser2);

vm.startPrank(testUser);
// approve user vault to spend user tokens
ERC20(stakeToken).approve(address(userVault), 100);
userVault.stake(100, 0);
vm.stopPrank();

vm.startPrank(testUser2);
ERC20(stakeToken).approve(address(user2Vault), 100);
user2Vault.stake(100, 0);
vm.stopPrank();

assertEq(ERC20(stakeToken).balanceOf(address(userVault)), 100);
assertEq(ERC20(stakeToken).balanceOf(address(user2Vault)), 100);
assertEq(stakeManager.stakeSupply(), 200);

vm.startPrank(testUser);
userVault.unstake(100);
assertEq(ERC20(stakeToken).balanceOf(address(userVault)), 0);
assertEq(stakeManager.stakeSupply(), 100);

vm.startPrank(testUser2);
user2Vault.unstake(100);
assertEq(ERC20(stakeToken).balanceOf(address(user2Vault)), 0);
assertEq(stakeManager.stakeSupply(), 0);
}
}

0 comments on commit 81a4afa

Please sign in to comment.