Skip to content

Commit

Permalink
✅ auctionReady tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cmontecoding committed Oct 25, 2024
1 parent 7c2891e commit 55b6342
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 72 deletions.
121 changes: 49 additions & 72 deletions test/KSXVault.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,21 @@ contract KSXVaultTest is Bootstrap {
address(stakingRewards),
address(auctionFactory),
DECIMAL_OFFSET,
1 weeks,
1 weeks,
1 weeks
DEFAULT_START_TIME,
DEFAULT_EPOCH_DURATION,
DEFAULT_START_TIME
);

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);
}
}

contract KSXVaultDepositMintTest is KSXVaultTest {
// Asserts decimals offset is correctly set to 3
function test_vault_decimalsOffset() public {
assertEq(ksxVault.decimalOffset(), 3);
Expand Down Expand Up @@ -122,87 +118,68 @@ contract KSXVaultTest is Bootstrap {
// assertEq(depositToken.balanceOf(alice), 10 ether);
vm.stopPrank();
}

}

contract KSXVaultAuctionTest is KSXVaultTest {

function test_auctionReady() public {
vm.warp(DEFAULT_START_TIME);
assertEq(ksxVault.isAuctionReady(), false);
assertEq(block.timestamp, 1);
vm.warp(block.timestamp + 1 weeks - 2);

vm.warp(block.timestamp + DEFAULT_EPOCH_DURATION - 1);
assertEq(ksxVault.isAuctionReady(), false);
vm.warp(block.timestamp + 1);
assertEq(ksxVault.isAuctionReady(), true);
}

function test_auctionReady_next_week() public {
assertEq(ksxVault.isAuctionReady(), false);
assertEq(block.timestamp, 1);
vm.warp(block.timestamp + 1 weeks - 2);
assertEq(ksxVault.isAuctionReady(), false);
vm.warp(block.timestamp + 1);
assertEq(ksxVault.isAuctionReady(), true);

ksxVault.createAuction(100, 100);

vm.warp(block.timestamp + 1 weeks - 1);
assertEq(ksxVault.isAuctionReady(), false);
// function test_auctionReady_next_week() public {
// assertEq(ksxVault.isAuctionReady(), false);
// assertEq(block.timestamp, 1);
// vm.warp(block.timestamp + 1 weeks - 2);
// assertEq(ksxVault.isAuctionReady(), false);
// vm.warp(block.timestamp + 1);
// assertEq(ksxVault.isAuctionReady(), true);

// ksxVault.createAuction(100, 100);

// vm.warp(block.timestamp + 1 weeks - 1);
// assertEq(ksxVault.isAuctionReady(), false);
// vm.warp(block.timestamp + 1);
// assertEq(ksxVault.isAuctionReady(), true);
// }

/// @notice test isAuctionReady reverts until the startTime
function test_auctionReady_before_start() public {
uint256 bootstrapStartTime = block.timestamp;
assertEq(bootstrapStartTime, 1);
vm.expectRevert();
ksxVault.isAuctionReady();

vm.warp(block.timestamp + DEFAULT_START_TIME - bootstrapStartTime - 1);
vm.expectRevert();
ksxVault.isAuctionReady();

/// @notice no longer reverts
vm.warp(block.timestamp + 1);
assertEq(ksxVault.isAuctionReady(), true);
}

function test_auctionReady_offset() public {
vm.warp(block.timestamp + 2 weeks);
initializeLocal(
address(depositToken),
address(mockUSDC),
address(stakingRewards),
address(auctionFactory),
DECIMAL_OFFSET,
1 weeks,
1 weeks,
1 weeks
);
ksxVault.createAuction(100, 100);
assertEq(ksxVault.isAuctionReady(), false);
assertEq(block.timestamp, 2 weeks + 1);
vm.warp(block.timestamp + 1 days - 2);
assertEq(ksxVault.isAuctionReady(), false);
vm.warp(block.timestamp + 1);
assertEq(ksxVault.isAuctionReady(), true);
assertEq(block.timestamp, 1 weeks);
}

function test_auctionReady_offset_next_week() public {
vm.warp(block.timestamp + 2 weeks);
initializeLocal(
address(depositToken),
address(mockUSDC),
address(stakingRewards),
address(auctionFactory),
DECIMAL_OFFSET,
1 weeks,
1 weeks,
1 weeks
);
ksxVault.createAuction(100, 100);
assertEq(ksxVault.isAuctionReady(), false);
assertEq(block.timestamp, 2 weeks + 1);
vm.warp(block.timestamp + 1 days - 2);
assertEq(ksxVault.isAuctionReady(), false);
vm.warp(block.timestamp + 1);
assertEq(ksxVault.isAuctionReady(), true);

ksxVault.createAuction(100, 100);

vm.warp(block.timestamp + 1 weeks - 1);
assertEq(ksxVault.isAuctionReady(), false);
vm.warp(block.timestamp + 1);
assertEq(ksxVault.isAuctionReady(), true);
/// @notice test isAuctionReady reverts until the startTime
function test_auctionReady_before_start_fuzz(uint128 time) public {
/// @dev using lastAuctionStartTime to get the startTime because
/// startTime is private
uint256 timeBeforeInitialStart = ksxVault.lastAuctionStartTime() - block.timestamp;
assertEq(timeBeforeInitialStart, DEFAULT_START_TIME - 1);
vm.assume(time < timeBeforeInitialStart);

vm.warp(block.timestamp + time);
vm.expectRevert();
ksxVault.isAuctionReady();
}

function test_createAuction() public {
vm.warp(block.timestamp + 1 weeks);
vm.warp(DEFAULT_START_TIME + DEFAULT_EPOCH_DURATION);
ksxVault.createAuction(100, 100);
assertEq(ksxVault.lastAuctionStartTime(), block.timestamp);
}
Expand Down
4 changes: 4 additions & 0 deletions test/utils/Constants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ contract Constants {

uint256 internal constant TEST_VALUE = 100 ether;

uint256 internal constant DEFAULT_START_TIME = 1 weeks;

uint256 internal constant DEFAULT_EPOCH_DURATION = 1 weeks;

uint256 internal constant STARTING_BID = 10 ether;

uint256 internal constant BID_BUFFER = 1 ether;
Expand Down

0 comments on commit 55b6342

Please sign in to comment.