Skip to content

Commit

Permalink
Merge branch 'release/core-contracts/12' into martinvol/fixMigration2
Browse files Browse the repository at this point in the history
  • Loading branch information
martinvol authored Dec 5, 2024
2 parents e719453 + 336a600 commit 8725a62
Show file tree
Hide file tree
Showing 8 changed files with 220 additions and 117 deletions.
18 changes: 18 additions & 0 deletions packages/protocol/contracts-0.8/common/EpochManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,20 @@ contract EpochManager is
uint256 delegatedPayment
);

/**
* @notice Emitted when group is marked for processing.
* @param group Address of the group to be processed.
* @param epochNumber The epoch number for which the group gets marked for processing.
*/
event GroupMarkedForProcessing(address indexed group, uint256 indexed epochNumber);

/**
* @notice Emitted when group is processed.
* @param group Address of the processed group.
* @param epochNumber The epoch number for which the group gets processed.
*/
event GroupProcessed(address indexed group, uint256 indexed epochNumber);

/**
* @notice Throws if called by other than EpochManagerEnabler contract.
*/
Expand Down Expand Up @@ -245,6 +259,7 @@ contract EpochManager is
groupScore
);
processedGroups[group] = epochRewards == 0 ? type(uint256).max : epochRewards;
emit GroupMarkedForProcessing(group, currentEpochNumber);
}
}
}
Expand Down Expand Up @@ -291,6 +306,8 @@ contract EpochManager is
delete processedGroups[group];
toProcessGroups--;

emit GroupProcessed(group, currentEpochNumber);

if (toProcessGroups == 0) {
_finishEpochHelper(_epochProcessing, election);
}
Expand Down Expand Up @@ -348,6 +365,7 @@ contract EpochManager is
}

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

_finishEpochHelper(_epochProcessing, election);
Expand Down
16 changes: 16 additions & 0 deletions packages/protocol/contracts-0.8/common/FeeCurrencyDirectory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ contract FeeCurrencyDirectory is
mapping(address => CurrencyConfig) public currencies;
address[] private currencyList;

/**
* @notice Emitted when currency config is set.
* @param token Address of the added currency token.
* @param oracle Address of the currency token oracle.
* @param intrinsicGas The intrinsic gas value for transactions.
*/
event CurrencyConfigSet(address indexed token, address indexed oracle, uint256 intrinsicGas);

/**
* @notice Emitted when currency is removed.
* @param token Address of the removed currency token.
*/
event CurrencyRemoved(address indexed token);

constructor(bool test) Initializable(test) {}

/**
Expand Down Expand Up @@ -43,6 +57,7 @@ contract FeeCurrencyDirectory is

currencies[token] = CurrencyConfig({ oracle: oracle, intrinsicGas: intrinsicGas });
currencyList.push(token);
emit CurrencyConfigSet(token, oracle, intrinsicGas);
}

/**
Expand All @@ -58,6 +73,7 @@ contract FeeCurrencyDirectory is
delete currencies[token];
currencyList[index] = currencyList[currencyList.length - 1];
currencyList.pop();
emit CurrencyRemoved(token);
}

/**
Expand Down
3 changes: 3 additions & 0 deletions packages/protocol/contracts/governance/LockedGold.sol
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,9 @@ contract LockedGold is
_decrementNonvotingAccountBalance(account, maxSlash.sub(difference));
_incrementNonvotingAccountBalance(reporter, reward);
}

_updateDelegatedAmount(account);

address communityFund = registry.getAddressForOrDie(GOVERNANCE_REGISTRY_ID);
address payable communityFundPayable = address(uint160(communityFund));
require(maxSlash.sub(reward) <= address(this).balance, "Inconsistent balance");
Expand Down
41 changes: 40 additions & 1 deletion packages/protocol/test-sol/unit/common/EpochManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +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, uint256 indexed epochNumber);
event GroupProcessed(address indexed group, uint256 indexed epochNumber);

function setUp() public virtual {
epochManager = new EpochManager_WithMocks();
Expand Down Expand Up @@ -640,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 @@ -707,6 +725,19 @@ contract EpochManagerTest_setToProcessGroups is EpochManagerTest {
assertEq(EpochManager(address(epochManager)).processedGroups(group), groupEpochRewards);
}
}

function test_Emits_GroupMarkedForProcessingEvent() public {
(address[] memory groups, , ) = getGroupsWithLessersAndGreaters();

epochManager.startNextEpochProcess();

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

epochManager.setToProcessGroups();
}
}

contract EpochManagerTest_processGroup is EpochManagerTest {
Expand Down Expand Up @@ -829,6 +860,14 @@ contract EpochManagerTest_processGroup is EpochManagerTest {
assertEq(signers[i], afterSigners[i]);
}
}

function test_Emits_GroupProcessed() public {
epochManager.startNextEpochProcess();
epochManager.setToProcessGroups();
vm.expectEmit(true, true, true, true);
emit GroupProcessed(group, firstEpochNumber);
epochManager.processGroup(group, address(0), address(0));
}
}

contract EpochManagerTest_getEpochByNumber is EpochManagerTest {
Expand Down
19 changes: 19 additions & 0 deletions packages/protocol/test-sol/unit/common/FeeCurrencyDirectory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ contract FeeCurrencyDirectoryTestBase is Test {
MockOracle oracle;
address nonOwner;
address owner;
event CurrencyConfigSet(address indexed token, address indexed oracle, uint256 intrinsicGas);
event CurrencyRemoved(address indexed token);

function setUp() public virtual {
owner = address(this);
Expand All @@ -33,6 +35,16 @@ contract TestSetCurrencyConfig is FeeCurrencyDirectoryTestBase {
assertEq(config.intrinsicGas, intrinsicGas);
}

function test_Emits_CurrencyConfigSetEvent() public {
address token = address(1);
uint256 intrinsicGas = 21000;

vm.expectEmit(true, true, true, true);
emit CurrencyConfigSet(token, address(oracle), intrinsicGas);

directory.setCurrencyConfig(token, address(oracle), intrinsicGas);
}

function test_Reverts_WhenNonOwnerSetsCurrencyConfig() public {
address token = address(2);
uint256 intrinsicGas = 21000;
Expand Down Expand Up @@ -78,6 +90,13 @@ contract TestRemoveCurrencies is FeeCurrencyDirectoryTestBase {
assertEq(config.oracle, address(0));
}

function test_Emits_CurrencyRemovedEvent() public {
address token = address(4);
vm.expectEmit(true, true, true, true);
emit CurrencyRemoved(token);
directory.removeCurrencies(token, 0);
}

function test_Reverts_WhenNonOwnerRemovesCurrencies() public {
address token = address(4);
vm.prank(nonOwner);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.5.13;

import "celo-foundry/Test.sol";
import { TestConstants } from "@test-sol/constants.sol";
import { TestWithUtils } from "@test-sol/TestWithUtils.sol";
import "@test-sol/utils/WhenL2.sol";

import "@celo-contracts/common/Accounts.sol";
import "@celo-contracts/common/FixidityLib.sol";
import "@celo-contracts/common/interfaces/IRegistry.sol";
import "@celo-contracts/governance/Proposals.sol";
import "@celo-contracts/governance/test/MockLockedGold.sol";
import "@celo-contracts/governance/test/MockValidators.sol";
import { L2MakerAbstract } from "@test-sol/utils/L2MakerAbstract.sol";

import "@celo-contracts/governance/GovernanceSlasher.sol";

contract GovernanceSlasherTest is Test, TestConstants {
contract GovernanceSlasherTest is TestWithUtils {
event SlashingApproved(address indexed account, uint256 amount);
event GovernanceSlashPerformed(address indexed account, uint256 amount);
event GovernanceSlashL2Performed(address indexed account, address indexed group, uint256 amount);
event HavelSlashingMultiplierHalved(address validator);
event ValidatorDeaffiliatedCalled(address validator);

IRegistry registry;
Accounts accounts;
MockLockedGold mockLockedGold;

Expand All @@ -37,6 +33,7 @@ contract GovernanceSlasherTest is Test, TestConstants {
address internal slasherExecuter;

function setUp() public {
super.setUp();
owner = address(this);
nonOwner = actor("nonOwner");
validator = actor("validator");
Expand All @@ -47,8 +44,6 @@ contract GovernanceSlasherTest is Test, TestConstants {
mockLockedGold = new MockLockedGold();
governanceSlasher = new GovernanceSlasher(true);

deployCodeTo("Registry.sol", abi.encode(false), REGISTRY_ADDRESS);
registry = IRegistry(REGISTRY_ADDRESS);
registry.setAddressFor("Accounts", address(accounts));
registry.setAddressFor("LockedGold", address(mockLockedGold));

Expand All @@ -57,6 +52,8 @@ contract GovernanceSlasherTest is Test, TestConstants {
}
}

contract GovernanceSlasherTest_L2 is GovernanceSlasherTest, WhenL2 {}

contract GovernanceSlasherTest_initialize is GovernanceSlasherTest {
function test_shouldHaveSetOwner() public {
assertEq(governanceSlasher.owner(), owner);
Expand All @@ -68,7 +65,7 @@ contract GovernanceSlasherTest_initialize is GovernanceSlasherTest {
}
}

contract GovernanceSlasherTest_approveSlashingTest is GovernanceSlasherTest {
contract GovernanceSlasherTest_approveSlashing is GovernanceSlasherTest {
function test_ShouldSetSlashableAmount() public {
governanceSlasher.approveSlashing(slashedAddress, 1000);
assertEq(governanceSlasher.getApprovedSlashing(slashedAddress), 1000);
Expand Down Expand Up @@ -99,7 +96,12 @@ contract GovernanceSlasherTest_approveSlashingTest is GovernanceSlasherTest {
}
}

contract GovernanceSlasherTest_slash is GovernanceSlasherTest, L2MakerAbstract {
contract GovernanceSlasherTest_approveSlashing_L2 is
GovernanceSlasherTest_L2,
GovernanceSlasherTest_approveSlashing
{}

contract GovernanceSlasherTest_slash is GovernanceSlasherTest {
function test_ShouldFailIfThereIsNothingToSlash() public {
vm.expectRevert("No penalty given by governance");
governanceSlasher.slash(validator, lessers, greaters, indices);
Expand All @@ -123,9 +125,10 @@ contract GovernanceSlasherTest_slash is GovernanceSlasherTest, L2MakerAbstract {
emit GovernanceSlashPerformed(validator, 1000);
governanceSlasher.slash(validator, lessers, greaters, indices);
}
}

contract GovernanceSlasherTest_slash_L2 is GovernanceSlasherTest_L2 {
function test_Reverts_WhenL2() public {
_whenL2();
governanceSlasher.approveSlashing(validator, 1000);
vm.expectRevert("This method is no longer supported in L2.");
governanceSlasher.slash(validator, lessers, greaters, indices);
Expand All @@ -147,17 +150,9 @@ contract GovernanceSlasherTest_slashL2_WhenL1 is GovernanceSlasherTest {
}

// should work just like the deprecated version
contract GovernanceSlasherTest_slashL2_WhenL2_WhenNotGroup is
GovernanceSlasherTest,
L2MakerAbstract
{
contract GovernanceSlasherTest_slashL2_WhenNotGroup_L2 is GovernanceSlasherTest_L2 {
address group = address(0);

function setUp() public {
super.setUp();
_whenL2();
}

// only onwer or multisig can call

function test_ShouldDecrementCelo() public {
Expand All @@ -181,13 +176,12 @@ contract GovernanceSlasherTest_slashL2_WhenL2_WhenNotGroup is
}

// should work just like the deprecated version
contract GovernanceSlasherTest_slashL2_WhenL2_WhenGroup is GovernanceSlasherTest, L2MakerAbstract {
contract GovernanceSlasherTest_slashL2_WhenGroup_L2 is GovernanceSlasherTest_L2 {
address group;
MockValidators validators;

function setUp() public {
super.setUp();
_whenL2();

validators = new MockValidators();
registry.setAddressFor("Validators", address(validators));
Expand Down Expand Up @@ -249,7 +243,7 @@ contract GovernanceSlasherTest_slashL2_WhenL2_WhenGroup is GovernanceSlasherTest
}
}

contract SlasherExecuterTest_setSlasherExecuter is GovernanceSlasherTest {
contract GovernanceSlasherTest_setSlasherExecuter is GovernanceSlasherTest {
function test_onlyOwnwerCanSetSlasherExecuter() public {
vm.prank(nonOwner);
vm.expectRevert("Ownable: caller is not the owner");
Expand All @@ -261,3 +255,8 @@ contract SlasherExecuterTest_setSlasherExecuter is GovernanceSlasherTest {
assertEq(governanceSlasher.getSlasherExecuter(), nonOwner, "Score Manager not set");
}
}

contract GovernanceSlasherTest_setSlasherExecuter_L2 is
GovernanceSlasherTest_L2,
GovernanceSlasherTest_setSlasherExecuter
{}
Loading

0 comments on commit 8725a62

Please sign in to comment.