Skip to content

Commit

Permalink
fix setEpochDuration bug; ++ event
Browse files Browse the repository at this point in the history
  • Loading branch information
soloseng committed Sep 24, 2024
1 parent 1b37ffd commit 4e4decf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/protocol/contracts-0.8/common/EpochManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ contract EpochManager is
* @param epochNumber The epoch number that is finished being processed.
*/
event EpochProcessingEnded(uint256 indexed epochNumber);
event EpochDurationSet(uint256 indexed newEpochDuration);

/**
* @notice Emitted when an epoch payment is sent.
Expand Down Expand Up @@ -367,7 +368,9 @@ contract EpochManager is
* @dev Can only be set by owner.
*/
function setEpochDuration(uint256 newEpochDuration) public onlyOwner {
require(!isOnEpochProcess(), "Cannot change epoch duration during processing.");
epochDuration = newEpochDuration;
emit EpochDurationSet(newEpochDuration);
}

function isTimeForNextEpoch() public view returns (bool) {
Expand Down
25 changes: 25 additions & 0 deletions packages/protocol/test-sol/unit/common/EpochManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ contract EpochManagerTest is Test, TestConstants, Utils08 {
);

event EpochProcessingStarted(uint256 indexed epochNumber);
event EpochDurationSet(uint256 indexed newEpochDuration);

function setUp() public virtual {
epochManager = new EpochManager_WithMocks();
Expand Down Expand Up @@ -245,6 +246,30 @@ contract EpochManagerTest_startNextEpochProcess is EpochManagerTest {
assertEq(reserveBalanceAfter, reserveBalanceBefore + 4);
}
}
contract EpochManagerTest_setEpochDuration is EpochManagerTest {
uint256 newEpochDuration = 5 * DAY;

function test_setsNewEpochDuration() public {
initializeEpochManagerSystem();
epochManager.setEpochDuration(newEpochDuration);
assertEq(epochManager.epochDuration(), newEpochDuration);
}

function test_Emits_EpochDurationSetEvent() public {
initializeEpochManagerSystem();

vm.expectEmit(true, true, true, true);
emit EpochDurationSet(newEpochDuration);
epochManager.setEpochDuration(newEpochDuration);
}

function test_Reverts_WhenIsOnEpochProcess() public {
initializeEpochManagerSystem();
epochManager.startNextEpochProcess();
vm.expectRevert("Cannot change epoch duration during processing.");
epochManager.setEpochDuration(newEpochDuration);
}
}

contract EpochManagerTest_sendValidatorPayment is EpochManagerTest {
address group = actor("group");
Expand Down

0 comments on commit 4e4decf

Please sign in to comment.