diff --git a/test/KSXVault.t.sol b/test/KSXVault.t.sol index 510e71b..4212e4c 100644 --- a/test/KSXVault.t.sol +++ b/test/KSXVault.t.sol @@ -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); @@ -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); } diff --git a/test/utils/Constants.sol b/test/utils/Constants.sol index 5ae932d..b30020d 100644 --- a/test/utils/Constants.sol +++ b/test/utils/Constants.sol @@ -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;