From ffd5d3511de314cabf464d02cb2aca81c0eb3641 Mon Sep 17 00:00:00 2001 From: Andrew Chiaramonte Date: Fri, 25 Oct 2024 21:54:18 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20test=5FsetEpochDuration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/KSXVault.t.sol | 45 +++++++++++++++++++++++++++++++++++++++- test/utils/Constants.sol | 4 ++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/test/KSXVault.t.sol b/test/KSXVault.t.sol index d89865f..3b773c8 100644 --- a/test/KSXVault.t.sol +++ b/test/KSXVault.t.sol @@ -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"); @@ -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), @@ -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); + } + } diff --git a/test/utils/Constants.sol b/test/utils/Constants.sol index b30020d..45025f6 100644 --- a/test/utils/Constants.sol +++ b/test/utils/Constants.sol @@ -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;