Skip to content

Commit

Permalink
updated & fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
soloseng committed Dec 3, 2024
1 parent 091fc09 commit 985638b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
5 changes: 3 additions & 2 deletions packages/protocol/contracts-0.8/common/EpochManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,11 @@ contract EpochManager is
delete processedGroups[group];
toProcessGroups--;

emit GroupProcessed(group, currentEpochNumber);

if (toProcessGroups == 0) {
_finishEpochHelper(_epochProcessing, election);
}
emit GroupProcessed(group, currentEpochNumber);
}

/**
Expand Down Expand Up @@ -364,7 +365,7 @@ contract EpochManager is
}

delete processedGroups[groups[i]];
emit GroupProcessed(group, currentEpochNumber);
emit GroupProcessed(groups[i], currentEpochNumber);
}

_finishEpochHelper(_epochProcessing, election);
Expand Down
32 changes: 26 additions & 6 deletions packages/protocol/test-sol/unit/common/EpochManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,11 @@ contract EpochManagerTest is Test, TestConstants, Utils08 {
address indexed beneficiary,
uint256 delegatedPayment
);

event EpochProcessingStarted(uint256 indexed epochNumber);
event EpochDurationSet(uint256 indexed newEpochDuration);
event OracleAddressSet(address indexed newOracleAddress);
event GroupMarkedForProcessing(address indexed group);
event GroupProcessed(address indexed group);
event GroupMarkedForProcessing(address indexed group, uint256 indexed epochNumber);
event GroupProcessed(address indexed group, uint256 indexed epochNumber);

function setUp() public virtual {
epochManager = new EpochManager_WithMocks();
Expand Down Expand Up @@ -642,6 +641,23 @@ contract EpochManagerTest_finishNextEpochProcess is EpochManagerTest {
assertEq(newElected[i], afterElected[i]);
}
}

function test_Emits_GroupProcessedEvent() public {
(
address[] memory groups,
address[] memory lessers,
address[] memory greaters
) = getGroupsWithLessersAndGreaters();

epochManager.startNextEpochProcess();

for (uint i = 0; i < groups.length; i++) {
vm.expectEmit(true, true, true, true);
emit GroupProcessed(groups[i], firstEpochNumber);
}

epochManager.finishNextEpochProcess(groups, lessers, greaters);
}
}

contract EpochManagerTest_setToProcessGroups is EpochManagerTest {
Expand Down Expand Up @@ -714,8 +730,12 @@ contract EpochManagerTest_setToProcessGroups is EpochManagerTest {
(address[] memory groups, , ) = getGroupsWithLessersAndGreaters();

epochManager.startNextEpochProcess();
vm.expectEmit(true, true, true, true);
emit GroupMarkedForProcessing(groups[0]);

for (uint i = 0; i < groups.length; i++) {
vm.expectEmit(true, true, true, true);
emit GroupMarkedForProcessing(groups[i], firstEpochNumber);
}

epochManager.setToProcessGroups();
}
}
Expand Down Expand Up @@ -845,7 +865,7 @@ contract EpochManagerTest_processGroup is EpochManagerTest {
epochManager.startNextEpochProcess();
epochManager.setToProcessGroups();
vm.expectEmit(true, true, true, true);
emit GroupProcessed(group);
emit GroupProcessed(group, firstEpochNumber);
epochManager.processGroup(group, address(0), address(0));
}
}
Expand Down

0 comments on commit 985638b

Please sign in to comment.