Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EpochManager FinishNextEpochProcessing unit tests #11233

Merged
merged 6 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,4 @@ contract EpochManager_WithMocks is EpochManager(true) {
function _setPaymentAllocation(address validator, uint256 amount) external {
validatorPendingPayments[validator] = amount;
}

// mocks finishNextEpochProcess to increment the epoch number.
function finishNextEpochProcess(
address[] calldata groups,
address[] calldata lessers,
address[] calldata greaters
) external override nonReentrant {
require(isOnEpochProcess(), "Epoch process is not started");

epochs[currentEpochNumber].lastBlock = block.number - 1;

currentEpochNumber++;
epochs[currentEpochNumber].firstBlock = block.number;
epochs[currentEpochNumber].startTimestamp = block.timestamp;

EpochProcessState storage _epochProcessing = epochProcessing;
_epochProcessing.status = EpochProcessStatus.NotStarted;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ contract EpochRewardsMock08 is IEpochRewards {
uint256 private numValidatorsInCurrentSet;
address public carbonOffsettingPartner;

uint256 public perValidatorReward = 5;
uint256 public totalRewardsVoter = 6;
uint256 public totalRewardsCommunity = 7;
uint256 public totalRewardsCarbonFund = 8;

function setNumberValidatorsInCurrentSet(uint256 value) external {
numValidatorsInCurrentSet = value;
}
Expand All @@ -32,7 +37,7 @@ contract EpochRewardsMock08 is IEpochRewards {
view
returns (uint256, uint256, uint256, uint256)
{
return (5, 5, 5, 5);
return (perValidatorReward, totalRewardsVoter, totalRewardsCommunity, totalRewardsCarbonFund);
}
function getTargetVotingYieldParameters() external view returns (uint256, uint256, uint256) {
return (0, 0, 0);
Expand All @@ -57,4 +62,8 @@ contract EpochRewardsMock08 is IEpochRewards {
function numberValidatorsInCurrentSet() public view returns (uint256) {
return numValidatorsInCurrentSet;
}

function setCarbonOffsettingPartner(address partner) external {
carbonOffsettingPartner = partner;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,8 @@ interface IMockValidators {
function groupMembershipInEpoch(address addr, uint256, uint256) external view returns (address);

function getGroupNumMembers(address group) external view returns (uint256);

function setEpochRewards(address account, uint256 reward) external;

function mintedStable() external view returns (uint256);
}
29 changes: 28 additions & 1 deletion packages/protocol/contracts/governance/test/MockElection.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.13;
pragma solidity >=0.5.13 <0.8.20;

import "../../../contracts-0.8/common/IsL2Check.sol";

Expand All @@ -9,6 +9,8 @@ contract MockElection is IsL2Check {
mapping(address => bool) public isIneligible;
mapping(address => bool) public isEligible;
mapping(address => bool) public allowedToVoteOverMaxNumberOfGroups;
mapping(address => uint256) public groupRewardsBasedOnScore;
mapping(address => uint256) public distributedEpochRewards;
address[] public electedValidators;
uint256 active;
uint256 total;
Expand Down Expand Up @@ -86,4 +88,29 @@ contract MockElection is IsL2Check {
function setAllowedToVoteOverMaxNumberOfGroups(address account, bool flag) public {
allowedToVoteOverMaxNumberOfGroups[account] = flag;
}

function getGroupEpochRewardsBasedOnScore(
address group,
uint256 totalEpochRewards,
uint256 groupScore
) external view returns (uint256) {
return groupRewardsBasedOnScore[group];
}

function setGroupEpochRewardsBasedOnScore(address group, uint256 groupRewards) external {
groupRewardsBasedOnScore[group] = groupRewards;
}

function distributeEpochRewards(
address group,
uint256 value,
address lesser,
address greater
) external {
distributedEpochRewards[group] = value;
}

function electValidatorAccounts() external view returns (address[] memory) {
return electedValidators;
}
}
10 changes: 8 additions & 2 deletions packages/protocol/contracts/governance/test/MockValidators.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ contract MockValidators is IValidators, IsL2Check {
mapping(address => address) private affiliations;
mapping(address => uint256) private commissions;
uint256 private numRegisteredValidators;
mapping(address => uint256) private epochRewards;
uint256 public mintedStable;

function updateEcdsaPublicKey(address, address, bytes calldata) external returns (bool) {
return true;
Expand Down Expand Up @@ -224,7 +226,7 @@ contract MockValidators is IValidators, IsL2Check {
}

function mintStableToEpochManager(uint256 amount) external {
revert("Method not implemented in mock");
mintedStable = mintedStable.add(amount);
}

function maxGroupSize() external view returns (uint256) {
Expand Down Expand Up @@ -304,7 +306,11 @@ contract MockValidators is IValidators, IsL2Check {
uint256 score,
uint256 maxPayment
) external view returns (uint256) {
revert("Method not implemented in mock");
return epochRewards[account];
}

function setEpochRewards(address account, uint256 reward) external {
epochRewards[account] = reward;
}

function registerValidator(
Expand Down
Loading
Loading