Skip to content

Commit

Permalink
✅ test_isAuctionReady
Browse files Browse the repository at this point in the history
  • Loading branch information
cmontecoding committed Oct 28, 2024
1 parent 871548c commit a281e34
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 18 deletions.
99 changes: 83 additions & 16 deletions test/KSXVault.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,65 @@ contract KSXVaultAuctionTest is KSXVaultTest {
assertEq(ksxVault.isAuctionReady(), true);
}

// function test_isAuctionReady_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(STARTING_BID);

// vm.warp(block.timestamp + 1 weeks - 1);
// assertEq(ksxVault.isAuctionReady(), false);
// vm.warp(block.timestamp + 1);
// assertEq(ksxVault.isAuctionReady(), true);
// }
function test_isAuctionReady_next_week() public {
vm.warp(DEFAULT_START_TIME);
vm.warp(block.timestamp + DEFAULT_EPOCH_DURATION - 1);
assertEq(ksxVault.isAuctionReady(), false);
vm.warp(block.timestamp + 1);
assertEq(ksxVault.isAuctionReady(), true);

ksxVault.createAuction(STARTING_BID);

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

function test_isAuctionReady_set_one_day() public {
vm.warp(DEFAULT_START_TIME);
assertEq(ksxVault.isAuctionReady(), false);

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

vm.warp(block.timestamp + (DEFAULT_EPOCH_DURATION / 2));
assertEq(ksxVault.isAuctionReady(), false);
vm.prank(PDAOADDR);
ksxVault.setEpochDuration(1 days);
/// @dev you have to wait until the end of the epoch duration
/// you just set (we were midway through the day because of (DEFAULT_EPOCH_DURATION / 2))
vm.warp(block.timestamp + .5 days - 1);
assertEq(ksxVault.isAuctionReady(), false);
vm.warp(block.timestamp + 1);
assertEq(ksxVault.isAuctionReady(), true);
}

function test_isAuctionReady_set_one_day_then_4_weeks() public {
test_isAuctionReady_set_one_day();
ksxVault.createAuction(STARTING_BID);
assertEq(ksxVault.isAuctionReady(), false);

vm.warp(block.timestamp + 1 days - 1);
assertEq(ksxVault.isAuctionReady(), false);
vm.warp(block.timestamp + 1);
assertEq(ksxVault.isAuctionReady(), true);
vm.prank(PDAOADDR);
ksxVault.setEpochDuration(4 weeks);
assertEq(ksxVault.isAuctionReady(), false);

vm.warp(block.timestamp + 3.5 weeks);
assertEq(ksxVault.isAuctionReady(), true);

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

/// @notice test isAuctionReady reverts until the startTime
function test_isAuctionReady_before_start() public {
Expand All @@ -171,7 +215,7 @@ contract KSXVaultAuctionTest is KSXVaultTest {
/// @notice no longer reverts
vm.warp(block.timestamp + 1);
assertEq(ksxVault.isAuctionReady(), false);
assertEq(block.timestamp, 1 weeks);
assertEq(block.timestamp, DEFAULT_START_TIME);
}

/// @notice test isAuctionReady reverts until the startTime
Expand Down Expand Up @@ -210,13 +254,35 @@ contract KSXVaultAuctionTest is KSXVaultTest {
}

function test_setEpochDuration() public {
vm.warp(DEFAULT_START_TIME);
assertEq(ksxVault.epochDuration(), DEFAULT_EPOCH_DURATION);
vm.prank(PDAOADDR);
ksxVault.setEpochDuration(2 weeks);
assertEq(ksxVault.epochDuration(), 2 weeks);
}

function test_setEpochDuration_before_start() public {
uint256 bootstrapStartTime = block.timestamp;
assertEq(bootstrapStartTime, 1);
vm.expectRevert();
vm.prank(PDAOADDR);
ksxVault.setEpochDuration(2 weeks);

vm.warp(block.timestamp + DEFAULT_START_TIME - bootstrapStartTime - 1);
vm.expectRevert();
vm.prank(PDAOADDR);
ksxVault.setEpochDuration(2 weeks);

/// @notice no longer reverts
vm.warp(block.timestamp + 1);
vm.prank(PDAOADDR);
ksxVault.setEpochDuration(2 weeks);
assertEq(ksxVault.epochDuration(), 2 weeks);
assertEq(block.timestamp, DEFAULT_START_TIME);
}

function test_setEpochDuration_fuzz(uint256 duration) public {
vm.warp(DEFAULT_START_TIME);
vm.assume(duration > MIN_EPOCH_DURATION);
vm.assume(duration < MAX_EPOCH_DURATION);

Expand All @@ -227,6 +293,7 @@ contract KSXVaultAuctionTest is KSXVaultTest {
}

function test_setEpochDuration_Invalid() public {
vm.warp(DEFAULT_START_TIME);
assertEq(ksxVault.epochDuration(), DEFAULT_EPOCH_DURATION);
vm.prank(PDAOADDR);
ksxVault.setEpochDuration(MIN_EPOCH_DURATION);
Expand Down
6 changes: 4 additions & 2 deletions test/utils/Constants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ contract Constants {

uint256 internal constant TEST_VALUE = 100 ether;

uint256 internal constant DEFAULT_START_TIME = 1 weeks;
/// @dev DEFAULT_START_TIME has to be > MAX_EPOCH_DURATION
/// to avoid issues with the tests (underflow)
uint256 internal constant DEFAULT_START_TIME = 6 weeks;

uint256 internal constant DEFAULT_EPOCH_DURATION = 1 weeks;

uint256 internal constant MIN_EPOCH_DURATION = 1 days;

uint256 internal constant MAX_EPOCH_DURATION = 4 weeks;

uint256 internal constant STARTING_BID = 10 ether;
Expand Down

0 comments on commit a281e34

Please sign in to comment.