From a281e34d77de165795753dc99b4ed73bdfefb65b Mon Sep 17 00:00:00 2001 From: Andrew Chiaramonte Date: Mon, 28 Oct 2024 10:49:53 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20test=5FisAuctionReady?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/KSXVault.t.sol | 99 +++++++++++++++++++++++++++++++++------- test/utils/Constants.sol | 6 ++- 2 files changed, 87 insertions(+), 18 deletions(-) diff --git a/test/KSXVault.t.sol b/test/KSXVault.t.sol index 3b773c8..3eb7414 100644 --- a/test/KSXVault.t.sol +++ b/test/KSXVault.t.sol @@ -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 { @@ -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 @@ -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); @@ -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); diff --git a/test/utils/Constants.sol b/test/utils/Constants.sol index 45025f6..3bda0fc 100644 --- a/test/utils/Constants.sol +++ b/test/utils/Constants.sol @@ -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;