Skip to content

Commit

Permalink
++ more test
Browse files Browse the repository at this point in the history
  • Loading branch information
soloseng committed Sep 20, 2024
1 parent 88fd997 commit ae0d499
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 15 deletions.
13 changes: 0 additions & 13 deletions packages/protocol/contracts-0.8/common/test/MockCeloToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 4 additions & 0 deletions packages/protocol/test-sol/mocks/EpochManagerEnablerMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
37 changes: 35 additions & 2 deletions packages/protocol/test-sol/unit/common/EpochManagerEnabler.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();

Expand All @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit ae0d499

Please sign in to comment.