Skip to content

Commit

Permalink
📚 nit: cleanup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Flocqst committed Oct 29, 2024
1 parent c79d016 commit dd40f5f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
36 changes: 14 additions & 22 deletions test/KSXVault.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ contract KSXVaultTest is Bootstrap {
depositToken.mint(alice, 10 ether);
depositToken.mint(bob, 10 ether);

// vm.prank(alice);
// depositToken.approve(address(ksxVault), type(uint256).max);

// vm.prank(bob);
// depositToken.approve(address(ksxVault), type(uint256).max);

// Give infinite approval to the staking rewards contract for the vault
vm.prank(address(ksxVault));
depositToken.approve(address(stakingRewards), type(uint256).max);
Expand All @@ -50,18 +44,18 @@ contract KSXVaultTest is Bootstrap {
// asserts deposited kwenta is correctly staked in the staking rewards
// contract
function test_vault_deposit() public {
uint256 amount = 1 ether;
uint256 amount = ONE_KWENTA;
vm.startPrank(alice);
depositToken.approve(address(ksxVault), amount);
ksxVault.deposit(1 ether, alice);
ksxVault.deposit(amount, alice);
assertEq(ksxVault.balanceOf(alice), amount * (10 ** ksxVault.offset()));
assertEq(stakingRewards.balanceOf(address(ksxVault)), amount);
vm.stopPrank();
}

// Asserts correct deposit at 1000 shares ratio
function test_vault_deposit_1000_ratio() public {
uint256 depositAmount = 1 ether;
uint256 depositAmount = ONE_KWENTA;
uint256 expectedShares = 1000 ether; // We expect 1000x the deposit
// amount

Expand Down Expand Up @@ -93,8 +87,7 @@ contract KSXVaultTest is Bootstrap {

// Asserts the 1:1000 ratio is maintained when no rewards have accrued
function test_vault_deposits() public {
// First deposit: 1 KWENTA
uint256 firstDeposit = 1 ether;
uint256 firstDeposit = ONE_KWENTA;

vm.startPrank(alice);

Expand All @@ -106,8 +99,7 @@ contract KSXVaultTest is Bootstrap {
assertEq(firstShares, 1000 ether);
assertEq(stakingRewards.balanceOf(address(ksxVault)), firstDeposit);

// Second deposit: 2 KWENTA
uint256 secondDeposit = 2 ether;
uint256 secondDeposit = 2 * ONE_KWENTA;
depositToken.approve(address(ksxVault), secondDeposit);
uint256 secondShares = ksxVault.deposit(secondDeposit, alice);

Expand All @@ -120,15 +112,15 @@ contract KSXVaultTest is Bootstrap {

// Verify final state
assertEq(ksxVault.balanceOf(alice), 3000 ether);
assertEq(stakingRewards.balanceOf(address(ksxVault)), 3 ether);
assertEq(stakingRewards.balanceOf(address(ksxVault)), 3 * ONE_KWENTA);

vm.stopPrank();
}

function test_vault_deposits_with_rewards_between() public {
// Initial setup
uint256 initialDeposit = 1 ether;
uint256 rewardsAmount = 0.5 ether;
uint256 initialDeposit = ONE_KWENTA;
uint256 rewardsAmount = REWARDS;

// First deposit from Alice
vm.startPrank(alice);
Expand All @@ -151,7 +143,7 @@ contract KSXVaultTest is Bootstrap {
);

// Bob's deposit
uint256 bobDeposit = 1 ether;
uint256 bobDeposit = ONE_KWENTA;

// Calculate expected shares for Bob
// At this point, ratio is no longer 1:1000 due to rewards:
Expand Down Expand Up @@ -215,7 +207,7 @@ contract KSXVaultTest is Bootstrap {
}

function test_vault_redeem() public {
uint256 depositAmount = 1 ether;
uint256 depositAmount = ONE_KWENTA;
vm.startPrank(alice);

uint256 initialBalance = depositToken.balanceOf(alice);
Expand All @@ -242,7 +234,7 @@ contract KSXVaultTest is Bootstrap {

function test_vault_redeem_1000_ratio() public {
// Setup: Alice deposits 1 KWENTA first
uint256 depositAmount = 1 ether;
uint256 depositAmount = ONE_KWENTA;
uint256 expectedShares = 1000 ether; // 1000 KSX for 1 KWENTA

vm.startPrank(alice);
Expand Down Expand Up @@ -271,8 +263,8 @@ contract KSXVaultTest is Bootstrap {
}

function test_vault_redeem_with_rewards() public {
uint256 depositAmount = 1 ether;
uint256 rewardsAmount = 0.5 ether;
uint256 depositAmount = ONE_KWENTA;
uint256 rewardsAmount = REWARDS;

// Initial Deposit
vm.startPrank(alice);
Expand Down Expand Up @@ -301,7 +293,7 @@ contract KSXVaultTest is Bootstrap {
ksxVault.redeem(sharesToRedeem, alice, alice);

// ~ 1.5 KWENTA in the vault so 2/3 of shares should be ~ 1 KWENTA
assertApproxEqAbs(firstRedeemAssets, 1 ether, 1);
assertApproxEqAbs(firstRedeemAssets, ONE_KWENTA, 1);

// Alice Should have 1/3 of shares remaining
assertEq(ksxVault.balanceOf(alice), aliceShares - sharesToRedeem);
Expand Down
4 changes: 4 additions & 0 deletions test/utils/Constants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ contract Constants {

uint8 public constant DECIMAL_OFFSET = 3;

uint256 internal constant ONE_KWENTA = 1 ether;

uint256 internal constant REWARDS = 0.5 ether;

}

0 comments on commit dd40f5f

Please sign in to comment.