Skip to content

Commit

Permalink
✅ test_setEpochDuration
Browse files Browse the repository at this point in the history
  • Loading branch information
cmontecoding committed Oct 26, 2024
1 parent 08303a3 commit ffd5d35
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
45 changes: 44 additions & 1 deletion test/KSXVault.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ contract KSXVaultTest is Bootstrap {
Auction auctionImplementation;
AuctionFactory auctionFactory;

error OwnableUnauthorizedAccount(address account);

function setUp() public {
depositToken = new MockERC20("Deposit Token", "DT");
mockUSDC = new MockERC20("USDC", "USDC");
Expand All @@ -26,7 +28,7 @@ contract KSXVaultTest is Bootstrap {
new Auction(address(this), address(0), address(0), 100, 100);
auctionFactory =
new AuctionFactory(PDAOADDR, address(auctionImplementation));
vm.prank(address(PDAOADDR));
vm.prank(PDAOADDR);
auctionFactory.updateBidBuffer(BID_BUFFER);
initializeLocal(
address(depositToken),
Expand Down Expand Up @@ -207,4 +209,45 @@ contract KSXVaultAuctionTest is KSXVaultTest {
ksxVault.createAuction(STARTING_BID);
}

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

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

assertEq(ksxVault.epochDuration(), DEFAULT_EPOCH_DURATION);
vm.prank(PDAOADDR);
ksxVault.setEpochDuration(duration);
assertEq(ksxVault.epochDuration(), duration);
}

function test_setEpochDuration_Invalid() public {
assertEq(ksxVault.epochDuration(), DEFAULT_EPOCH_DURATION);
vm.prank(PDAOADDR);
ksxVault.setEpochDuration(MIN_EPOCH_DURATION);
assertEq(ksxVault.epochDuration(), MIN_EPOCH_DURATION);

vm.expectRevert("KSXVault: Invalid Epoch Duration");
vm.prank(PDAOADDR);
ksxVault.setEpochDuration(MIN_EPOCH_DURATION - 1);

vm.prank(PDAOADDR);
ksxVault.setEpochDuration(MAX_EPOCH_DURATION);
assertEq(ksxVault.epochDuration(), MAX_EPOCH_DURATION);

vm.expectRevert("KSXVault: Invalid Epoch Duration");
vm.prank(PDAOADDR);
ksxVault.setEpochDuration(MAX_EPOCH_DURATION + 1);
}

function test_setEpochDuration_onlyOwner() public {
vm.expectRevert(abi.encodeWithSelector(OwnableUnauthorizedAccount.selector, 0x7FA9385bE102ac3EAc297483Dd6233D62b3e1496));
ksxVault.setEpochDuration(2 weeks);
}

}
4 changes: 4 additions & 0 deletions test/utils/Constants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ contract Constants {

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;

uint256 internal constant BID_BUFFER = 1 ether;
Expand Down

0 comments on commit ffd5d35

Please sign in to comment.