Skip to content

Commit

Permalink
✅ basic tess for createAuction and auctionReady
Browse files Browse the repository at this point in the history
  • Loading branch information
cmontecoding committed Oct 17, 2024
1 parent 1e0be95 commit 0ea697e
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 3 deletions.
69 changes: 68 additions & 1 deletion test/KSXVault.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ contract KSXVaultTest is Bootstrap {

depositToken = new MockERC20("Deposit Token", "DT");
stakingRewards = new MockStakingRewards(address(depositToken));
initializeLocal(address(depositToken), address(stakingRewards), DECIMAL_OFFSET);
initializeLocal(address(depositToken), address(stakingRewards), DECIMAL_OFFSET, 0);

depositToken.mint(alice, 10 ether);
depositToken.mint(bob, 10 ether);
Expand Down Expand Up @@ -100,4 +100,71 @@ contract KSXVaultTest is Bootstrap {
vm.stopPrank();
}

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

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

ksxVault.createAuction(address(this), address(0), address(0), 100, 100);

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

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

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

ksxVault.createAuction(address(this), address(0), address(0), 100, 100);

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

function test_createAuction() public {
vm.warp(block.timestamp + 1 weeks);
ksxVault.createAuction(address(this), address(0), address(0), 100, 100);
assertEq(ksxVault.lastAuctionStartTime(), block.timestamp);
}

function test_createAuction_AuctionNotReady() public {
vm.expectRevert(KSXVault.AuctionNotReady.selector);
ksxVault.createAuction(address(this), address(0), address(0), 100, 100);
}

}
4 changes: 2 additions & 2 deletions test/utils/Bootstrap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ contract Bootstrap is Test, Constants {
address constant alice = address(0xAAAA);
address constant bob = address(0xBBBB);

function initializeLocal(address _token, address _stakingRewards, uint8 _decimalsOffset) internal {
function initializeLocal(address _token, address _stakingRewards, uint8 _decimalsOffset, uint256 _daysToOffsetBy) internal {
BootstrapLocal bootstrap = new BootstrapLocal();
(address ksxVaultAddress) = bootstrap.init(_token, _stakingRewards, _decimalsOffset, 0);
(address ksxVaultAddress) = bootstrap.init(_token, _stakingRewards, _decimalsOffset, _daysToOffsetBy);

decimalsOffset = _decimalsOffset;
TOKEN = IERC20(_token);
Expand Down

0 comments on commit 0ea697e

Please sign in to comment.