From ae0d4991e38a0aa6f8a55da409b71d614453dab0 Mon Sep 17 00:00:00 2001 From: soloseng <102702451+soloseng@users.noreply.github.com> Date: Fri, 20 Sep 2024 13:49:25 -0400 Subject: [PATCH] ++ more test --- .../common/test/MockCeloToken.sol | 13 ------- .../mocks/EpochManagerEnablerMock.sol | 4 ++ .../unit/common/EpochManagerEnabler.t.sol | 37 ++++++++++++++++++- 3 files changed, 39 insertions(+), 15 deletions(-) diff --git a/packages/protocol/contracts-0.8/common/test/MockCeloToken.sol b/packages/protocol/contracts-0.8/common/test/MockCeloToken.sol index 74baea164c6..b412f134a22 100644 --- a/packages/protocol/contracts-0.8/common/test/MockCeloToken.sol +++ b/packages/protocol/contracts-0.8/common/test/MockCeloToken.sol @@ -9,19 +9,6 @@ contract MockCeloToken08 { uint8 public constant decimals = 18; mapping(address => uint256) balances; - uint256 constant L1_MINTED_CELO_SUPPLY = 692702432463315819704447326; // as of May 15 2024 - - uint256 constant CELO_SUPPLY_CAP = 1000000000 ether; // 1 billion Celo - uint256 constant GENESIS_CELO_SUPPLY = 600000000 ether; // 600 million Celo - - uint256 constant FIFTEEN_YEAR_LINEAR_REWARD = (CELO_SUPPLY_CAP - GENESIS_CELO_SUPPLY) / 2; // 200 million Celo - - uint256 constant FIFTEEN_YEAR_CELO_SUPPLY = GENESIS_CELO_SUPPLY + FIFTEEN_YEAR_LINEAR_REWARD; // 800 million Celo (includes GENESIS_CELO_SUPPLY) - - uint256 constant MAX_L2_DISTRIBUTION = FIFTEEN_YEAR_CELO_SUPPLY - L1_MINTED_CELO_SUPPLY; // 107.2 million Celo - - uint256 constant L2_INITIAL_STASH_BALANCE = FIFTEEN_YEAR_LINEAR_REWARD + MAX_L2_DISTRIBUTION; // leftover from L1 target supply plus the 2nd 15 year term. - function setTotalSupply(uint256 value) external { totalSupply_ = value; } diff --git a/packages/protocol/test-sol/mocks/EpochManagerEnablerMock.sol b/packages/protocol/test-sol/mocks/EpochManagerEnablerMock.sol index f696a6c77ee..137d9104522 100644 --- a/packages/protocol/test-sol/mocks/EpochManagerEnablerMock.sol +++ b/packages/protocol/test-sol/mocks/EpochManagerEnablerMock.sol @@ -8,6 +8,10 @@ import "../../contracts-0.8/common/EpochManagerEnabler.sol"; contract EpochManagerEnablerMock is EpochManagerEnabler(true) { address[] validatorSet; + function setFirstBlockOfEpoch() external { + return _setFirstBlockOfEpoch(); + } + function addValidator(address validator) external { validatorSet.push(validator); } diff --git a/packages/protocol/test-sol/unit/common/EpochManagerEnabler.t.sol b/packages/protocol/test-sol/unit/common/EpochManagerEnabler.t.sol index d722e066a01..0bfaccec9a0 100644 --- a/packages/protocol/test-sol/unit/common/EpochManagerEnabler.t.sol +++ b/packages/protocol/test-sol/unit/common/EpochManagerEnabler.t.sol @@ -18,11 +18,13 @@ import "@celo-contracts/common/interfaces/IRegistry.sol"; import { EpochRewardsMock08 } from "@celo-contracts-8/governance/test/EpochRewardsMock.sol"; import { ValidatorsMock } from "@test-sol/unit/governance/validators/mocks/ValidatorsMock.sol"; import { MockCeloUnreleasedTreasure } from "@celo-contracts-8/common/test/MockCeloUnreleasedTreasure.sol"; +import "@celo-contracts-8/common/test/MockCeloToken.sol"; contract EpochManagerEnablerTest is Test, TestConstants, Utils08 { EpochManager epochManager; EpochManagerEnablerMock epochManagerEnabler; MockCeloUnreleasedTreasure celoUnreleasedTreasure; + MockCeloToken08 celoToken; IRegistry registry; IAccounts accounts; @@ -33,9 +35,15 @@ contract EpochManagerEnablerTest is Test, TestConstants, Utils08 { uint256 epochDuration = DAY; uint256 numberValidators = 100; + event LastKnownEpochNumberSet(uint256 lastKnownEpochNumber); + event LastKnownFirstBlockOfEpochSet(uint256 lastKnownFirstBlockOfEpoch); + event LastKnownElectedAccountsSet(); + function setUp() public virtual { + ph.setEpochSize(17280); epochManager = new EpochManager(true); epochManagerEnabler = new EpochManagerEnablerMock(); + celoToken = new MockCeloToken08(); celoUnreleasedTreasure = new MockCeloUnreleasedTreasure(); @@ -52,10 +60,11 @@ contract EpochManagerEnablerTest is Test, TestConstants, Utils08 { registry.setAddressFor(EpochManagerContract, address(epochManager)); registry.setAddressFor(EpochManagerEnablerContract, address(epochManagerEnabler)); registry.setAddressFor(AccountsContract, address(accounts)); - + registry.setAddressFor(CeloTokenContract, address(celoToken)); registry.setAddressFor(CeloUnreleasedTreasureContract, address(celoUnreleasedTreasure)); - vm.deal(address(celoUnreleasedTreasure), L2_INITIAL_STASH_BALANCE); + celoToken.setTotalSupply(CELO_SUPPLY_CAP); + celoToken.setBalanceOf(address(celoUnreleasedTreasure), L2_INITIAL_STASH_BALANCE); epochManagerEnabler.initialize(REGISTRY_ADDRESS); epochManager.initialize(REGISTRY_ADDRESS, epochDuration); @@ -142,6 +151,30 @@ contract EpochManagerEnablerTest_captureEpochAndValidators is EpochManagerEnable assertEq(epochManagerEnabler.lastKnownFirstBlockOfEpoch(), 17280 * 3); } + + function test_Emits_LastKnownEpochNumberSet() public { + vm.expectEmit(true, true, true, true); + emit LastKnownEpochNumberSet(4); + + travelEpochL1(vm); + epochManagerEnabler.captureEpochAndValidators(); + } + + function test_Emits_LastKnownElectedAccountsSet() public { + vm.expectEmit(true, true, true, true); + emit LastKnownElectedAccountsSet(); + + travelEpochL1(vm); + epochManagerEnabler.captureEpochAndValidators(); + } + + function test_Emits_LastKnownFirstBlockOfEpochSet() public { + vm.expectEmit(true, true, true, true); + emit LastKnownFirstBlockOfEpochSet(51840); + + travelEpochL1(vm); + epochManagerEnabler.captureEpochAndValidators(); + } } contract EpochManagerEnablerTest_getFirstBlockOfEpoch is EpochManagerEnablerTest {