Skip to content

Commit

Permalink
test: linear vesting supply checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Oighty committed Jul 2, 2024
1 parent f0df1c4 commit 6d0edfb
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
50 changes: 50 additions & 0 deletions test/modules/derivatives/LinearVesting.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,7 @@ contract LinearVestingTest is Test, Permit2User {
assertTrue(wrappedAddress == address(0), "wrappedAddress mismatch");
assertEq(amountCreated, _AMOUNT, "amountCreated mismatch");
assertEq(_linearVesting.balanceOf(_ALICE, tokenId), _AMOUNT, "balanceOf mismatch");
assertEq(_linearVesting.totalSupply(tokenId), _AMOUNT, "totalSupply mismatch");
}

function test_mint_params_expiryTimestampIsBeforeCurrentTimestamp()
Expand All @@ -859,6 +860,7 @@ contract LinearVestingTest is Test, Permit2User {
assertTrue(wrappedAddress == address(0), "wrappedAddress mismatch");
assertEq(amountCreated, _AMOUNT, "amountCreated mismatch");
assertEq(_linearVesting.balanceOf(_ALICE, tokenId), _AMOUNT, "balanceOf mismatch");
assertEq(_linearVesting.totalSupply(tokenId), _AMOUNT, "totalSupply mismatch");
}

function test_mint_params_afterExpiry()
Expand All @@ -880,6 +882,7 @@ contract LinearVestingTest is Test, Permit2User {
assertEq(_linearVesting.balanceOf(_ALICE, tokenId), _AMOUNT, "balanceOf mismatch");
assertEq(_underlyingToken.balanceOf(_ALICE), 0, "underlying: balanceOf mismatch");
assertEq(_linearVesting.redeemable(_ALICE, tokenId), _AMOUNT, "redeemable mismatch");
assertEq(_linearVesting.totalSupply(tokenId), _AMOUNT, "totalSupply mismatch");
}

function test_mint_params_mintAmountIsZero_reverts() public {
Expand All @@ -905,6 +908,7 @@ contract LinearVestingTest is Test, Permit2User {
// Check values
assertTrue(tokenId > 0, "tokenId mismatch");
assertEq(_linearVesting.balanceOf(address(0), tokenId), _AMOUNT, "balanceOf mismatch");
assertEq(_linearVesting.totalSupply(tokenId), _AMOUNT, "totalSupply mismatch");
}

function test_mint_params_insufficentBalance_reverts() public {
Expand Down Expand Up @@ -953,6 +957,7 @@ contract LinearVestingTest is Test, Permit2User {
);
assertEq(_underlyingToken.balanceOf(_ALICE), 0, "underlying: balanceOf mismatch");
assertEq(_linearVesting.redeemable(_ALICE, tokenId), 0, "redeemable mismatch");
assertEq(_linearVesting.totalSupply(tokenId), _AMOUNT, "totalSupply mismatch");
}

function test_mint_params_afterVestingStart(uint48 elapsed_)
Expand Down Expand Up @@ -984,6 +989,7 @@ contract LinearVestingTest is Test, Permit2User {
expectedRedeemableAmount,
"redeemable mismatch"
);
assertEq(_linearVesting.totalSupply(tokenId), _AMOUNT, "totalSupply mismatch");
}

function test_mint_params_givenExistingDerivativeTokens_afterVestingStart(uint48 elapsed_)
Expand Down Expand Up @@ -1028,6 +1034,7 @@ contract LinearVestingTest is Test, Permit2User {
expectedRedeemableAmount,
"redeemable mismatch"
);
assertEq(_linearVesting.totalSupply(tokenId), _AMOUNT + _AMOUNT_TWO, "totalSupply mismatch");
}

function test_mint_params_notWrapped_tokenNotDeployed()
Expand All @@ -1045,6 +1052,7 @@ contract LinearVestingTest is Test, Permit2User {
assertTrue(wrappedAddress == address(0), "wrappedAddress mismatch");
assertEq(amountCreated, _AMOUNT, "amountCreated mismatch");
assertEq(_linearVesting.balanceOf(_ALICE, tokenId), _AMOUNT, "balanceOf mismatch");
assertEq(_linearVesting.totalSupply(tokenId), _AMOUNT, "totalSupply mismatch");
}

function test_mint_params_notWrapped_tokenDeployed()
Expand All @@ -1063,6 +1071,7 @@ contract LinearVestingTest is Test, Permit2User {
assertTrue(wrappedAddress == address(0), "wrappedAddress mismatch");
assertEq(amountCreated, _AMOUNT, "amountCreated mismatch");
assertEq(_linearVesting.balanceOf(_ALICE, tokenId), _AMOUNT, "balanceOf mismatch");
assertEq(_linearVesting.totalSupply(tokenId), _AMOUNT, "totalSupply mismatch");
}

function test_mint_params_wrapped_wrappedTokenIsNotDeployed()
Expand All @@ -1083,6 +1092,8 @@ contract LinearVestingTest is Test, Permit2User {
assertEq(
SoulboundCloneERC20(wrappedAddress).balanceOf(_ALICE), _AMOUNT, "balanceOf mismatch"
);
assertEq(_linearVesting.totalSupply(tokenId), 0, "totalSupply mismatch");
assertEq(SoulboundCloneERC20(wrappedAddress).totalSupply(), _AMOUNT, "balanceOf mismatch");
}

function test_mint_params_wrapped_wrappedTokenIsDeployed()
Expand All @@ -1103,6 +1114,8 @@ contract LinearVestingTest is Test, Permit2User {
assertEq(
SoulboundCloneERC20(wrappedAddress).balanceOf(_ALICE), _AMOUNT, "balanceOf mismatch"
);
assertEq(_linearVesting.totalSupply(tokenId), 0, "totalSupply mismatch");
assertEq(SoulboundCloneERC20(wrappedAddress).totalSupply(), _AMOUNT, "balanceOf mismatch");
}

function test_mint_params_notParent()
Expand All @@ -1123,6 +1136,8 @@ contract LinearVestingTest is Test, Permit2User {
assertEq(
SoulboundCloneERC20(wrappedAddress).balanceOf(_ALICE), _AMOUNT, "balanceOf mismatch"
);
assertEq(_linearVesting.totalSupply(tokenId), 0, "totalSupply mismatch");
assertEq(SoulboundCloneERC20(wrappedAddress).totalSupply(), _AMOUNT, "balanceOf mismatch");
}

function test_mint_params_notParent_insufficientBalance_reverts()
Expand Down Expand Up @@ -1196,6 +1211,7 @@ contract LinearVestingTest is Test, Permit2User {

// Check values
assertEq(_linearVesting.balanceOf(address(0), tokenId), _AMOUNT);
assertEq(_linearVesting.totalSupply(tokenId), _AMOUNT, "totalSupply mismatch");
}

function test_mint_tokenId_insufficentBalance_reverts() public givenDerivativeIsDeployed {
Expand Down Expand Up @@ -1244,6 +1260,7 @@ contract LinearVestingTest is Test, Permit2User {
);
assertEq(_underlyingToken.balanceOf(_ALICE), 0, "underlying: balanceOf mismatch");
assertEq(_linearVesting.redeemable(_ALICE, tokenId), 0, "redeemable mismatch");
assertEq(_linearVesting.totalSupply(tokenId), _AMOUNT, "totalSupply mismatch");
}

function test_mint_tokenId_afterVestingStart(uint48 elapsed_)
Expand Down Expand Up @@ -1275,6 +1292,7 @@ contract LinearVestingTest is Test, Permit2User {
expectedRedeemableAmount,
"redeemable mismatch"
);
assertEq(_linearVesting.totalSupply(tokenId), _AMOUNT, "totalSupply mismatch");
}

function test_mint_tokenId_afterVestingExpiry()
Expand All @@ -1297,6 +1315,7 @@ contract LinearVestingTest is Test, Permit2User {
);
assertEq(_underlyingToken.balanceOf(_ALICE), 0, "underlying: balanceOf mismatch");
assertEq(_linearVesting.redeemable(_ALICE, tokenId), _AMOUNT, "redeemable mismatch");
assertEq(_linearVesting.totalSupply(tokenId), _AMOUNT, "totalSupply mismatch");
}

function test_mint_tokenId_givenExistingDerivativeTokens_afterVestingStart(uint48 elapsed_)
Expand Down Expand Up @@ -1340,6 +1359,7 @@ contract LinearVestingTest is Test, Permit2User {
expectedRedeemableAmount,
"redeemable mismatch"
);
assertEq(_linearVesting.totalSupply(tokenId), _AMOUNT + _AMOUNT_TWO, "totalSupply mismatch");
}

function test_mint_tokenId_givenExistingDerivativeTokens_afterVestingExpiry()
Expand Down Expand Up @@ -1377,6 +1397,7 @@ contract LinearVestingTest is Test, Permit2User {
assertEq(
_linearVesting.redeemable(_ALICE, tokenId), _AMOUNT + _AMOUNT_TWO, "redeemable mismatch"
);
assertEq(_linearVesting.totalSupply(tokenId), _AMOUNT + _AMOUNT_TWO, "totalSupply mismatch");
}

function test_mint_tokenId_notWrapped()
Expand All @@ -1394,6 +1415,7 @@ contract LinearVestingTest is Test, Permit2User {
assertTrue(wrappedAddress == address(0));
assertEq(amountCreated, _AMOUNT);
assertEq(_linearVesting.balanceOf(_ALICE, tokenId), _AMOUNT, "balanceOf mismatch");
assertEq(_linearVesting.totalSupply(tokenId), _AMOUNT, "totalSupply mismatch");
}

function test_mint_tokenId_wrapped_wrappedTokenIsNotDeployed()
Expand All @@ -1414,6 +1436,8 @@ contract LinearVestingTest is Test, Permit2User {
assertEq(
SoulboundCloneERC20(wrappedAddress).balanceOf(_ALICE), _AMOUNT, "balanceOf mismatch"
);
assertEq(_linearVesting.totalSupply(tokenId), 0, "totalSupply mismatch");
assertEq(SoulboundCloneERC20(wrappedAddress).totalSupply(), _AMOUNT, "balanceOf mismatch");
}

function test_mint_tokenId_wrapped_wrappedTokenIsDeployed()
Expand All @@ -1434,6 +1458,8 @@ contract LinearVestingTest is Test, Permit2User {
assertEq(
SoulboundCloneERC20(wrappedAddress).balanceOf(_ALICE), _AMOUNT, "balanceOf mismatch"
);
assertEq(_linearVesting.totalSupply(tokenId), 0, "totalSupply mismatch");
assertEq(SoulboundCloneERC20(wrappedAddress).totalSupply(), _AMOUNT, "balanceOf mismatch");
}

function test_mint_tokenId_notParent()
Expand All @@ -1454,6 +1480,8 @@ contract LinearVestingTest is Test, Permit2User {
assertEq(
SoulboundCloneERC20(wrappedAddress).balanceOf(_ALICE), _AMOUNT, "balanceOf mismatch"
);
assertEq(_linearVesting.totalSupply(tokenId), 0, "totalSupply mismatch");
assertEq(SoulboundCloneERC20(wrappedAddress).totalSupply(), _AMOUNT, "balanceOf mismatch");
}

// redeem
Expand Down Expand Up @@ -1538,6 +1566,7 @@ contract LinearVestingTest is Test, Permit2User {
// Check values
assertEq(_linearVesting.balanceOf(_ALICE, _derivativeTokenId), _AMOUNT - amount);
assertEq(SoulboundCloneERC20(_underlyingTokenAddress).balanceOf(_ALICE), amount);
assertEq(_linearVesting.totalSupply(_derivativeTokenId), _AMOUNT - amount);
}

function test_redeem_givenWrappedBalance(uint256 amount_)
Expand All @@ -1556,6 +1585,8 @@ contract LinearVestingTest is Test, Permit2User {
assertEq(_linearVesting.balanceOf(_ALICE, _derivativeTokenId), 0);
assertEq(SoulboundCloneERC20(_derivativeWrappedAddress).balanceOf(_ALICE), _AMOUNT - amount);
assertEq(SoulboundCloneERC20(_underlyingTokenAddress).balanceOf(_ALICE), amount);
assertEq(_linearVesting.totalSupply(_derivativeTokenId), 0);
assertEq(SoulboundCloneERC20(_derivativeWrappedAddress).totalSupply(), _AMOUNT - amount);
}

function test_redeem_givenUnwrappedBalance(uint256 amount_)
Expand All @@ -1574,6 +1605,8 @@ contract LinearVestingTest is Test, Permit2User {
assertEq(_linearVesting.balanceOf(_ALICE, _derivativeTokenId), _AMOUNT - amount);
assertEq(SoulboundCloneERC20(_derivativeWrappedAddress).balanceOf(_ALICE), 0);
assertEq(SoulboundCloneERC20(_underlyingTokenAddress).balanceOf(_ALICE), amount);
assertEq(_linearVesting.totalSupply(_derivativeTokenId), _AMOUNT - amount);
assertEq(SoulboundCloneERC20(_derivativeWrappedAddress).totalSupply(), 0);
}

function test_redeem_givenMixedBalance()
Expand All @@ -1593,6 +1626,8 @@ contract LinearVestingTest is Test, Permit2User {
assertEq(_linearVesting.balanceOf(_ALICE, _derivativeTokenId), 0); // Redeems unwrapped first
assertEq(SoulboundCloneERC20(_derivativeWrappedAddress).balanceOf(_ALICE), _AMOUNT - 1);
assertEq(SoulboundCloneERC20(_underlyingTokenAddress).balanceOf(_ALICE), amountToRedeem);
assertEq(_linearVesting.totalSupply(_derivativeTokenId), 0);
assertEq(SoulboundCloneERC20(_derivativeWrappedAddress).totalSupply(), _AMOUNT - 1);
}

// redeem max
Expand Down Expand Up @@ -1643,6 +1678,7 @@ contract LinearVestingTest is Test, Permit2User {
// Check values
assertEq(_linearVesting.balanceOf(_ALICE, _derivativeTokenId), 0);
assertEq(SoulboundCloneERC20(_underlyingTokenAddress).balanceOf(_ALICE), _AMOUNT);
assertEq(_linearVesting.totalSupply(_derivativeTokenId), 0);
}

function test_redeemMax_givenWrappedBalance_givenVestingExpiry()
Expand All @@ -1659,6 +1695,8 @@ contract LinearVestingTest is Test, Permit2User {
assertEq(_linearVesting.balanceOf(_ALICE, _derivativeTokenId), 0);
assertEq(SoulboundCloneERC20(_derivativeWrappedAddress).balanceOf(_ALICE), 0);
assertEq(SoulboundCloneERC20(_underlyingTokenAddress).balanceOf(_ALICE), _AMOUNT);
assertEq(_linearVesting.totalSupply(_derivativeTokenId), 0);
assertEq(SoulboundCloneERC20(_derivativeWrappedAddress).totalSupply(), 0);
}

function test_redeemMax_givenUnwrappedBalance_givenVestingExpiry()
Expand All @@ -1675,6 +1713,8 @@ contract LinearVestingTest is Test, Permit2User {
assertEq(_linearVesting.balanceOf(_ALICE, _derivativeTokenId), 0);
assertEq(SoulboundCloneERC20(_derivativeWrappedAddress).balanceOf(_ALICE), 0);
assertEq(SoulboundCloneERC20(_underlyingTokenAddress).balanceOf(_ALICE), _AMOUNT);
assertEq(_linearVesting.totalSupply(_derivativeTokenId), 0);
assertEq(SoulboundCloneERC20(_derivativeWrappedAddress).totalSupply(), 0);
}

function test_redeemMax(uint48 elapsed_) public givenWrappedDerivativeIsDeployed {
Expand Down Expand Up @@ -1717,6 +1757,16 @@ contract LinearVestingTest is Test, Permit2User {
redeemable,
"underlying token: balanceOf mismatch"
);
assertEq(
_linearVesting.totalSupply(_derivativeTokenId),
expectedBalanceUnwrapped,
"derivative token: totalSupply mismatch"
);
assertEq(
SoulboundCloneERC20(_derivativeWrappedAddress).totalSupply(),
expectedBalanceWrapped,
"wrapped derivative token: totalSupply mismatch"
);
}

// redeemable
Expand Down
2 changes: 2 additions & 0 deletions test/modules/derivatives/mocks/MockDerivativeModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ contract MockDerivativeModule is DerivativeModule {
}
// Otherwise mint as normal
else {
// Increment the supply
tokenMetadata[tokenId].supply += amount_;
derivativeToken.mint(to_, tokenId, outputAmount);
}

Expand Down

0 comments on commit 6d0edfb

Please sign in to comment.