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

startNextEpochProcess unit & integration test #11191

Merged
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
f9979ce
unit test with mocks
soloseng Aug 19, 2024
75bf938
++ integration tests
soloseng Aug 20, 2024
cb47ec9
clean up
soloseng Aug 20, 2024
fbdc5fd
Merge branch 'feat/l2-epoch-system' into soloseng/startNextEpochProce…
soloseng Aug 20, 2024
b8f5584
-- logging
soloseng Aug 20, 2024
282ef91
removed duplicate interface
soloseng Aug 20, 2024
40711cb
using `MockCeloToken` to get test to pass.
soloseng Aug 20, 2024
654b279
removed endEpochTimestamp
soloseng Aug 20, 2024
2072107
moved IEpochManager to 0.5 folder
soloseng Aug 20, 2024
9a6c01f
added L2 conditions for EpochRewards functions using precompiles
soloseng Aug 20, 2024
c48b8e5
renamed EpochManagerInitializer due to name conflict
soloseng Aug 21, 2024
47f93af
++ more unit test
soloseng Aug 21, 2024
d3b1db4
setup anvil migration
soloseng Aug 22, 2024
a6e2844
Merge branch 'feat/l2-epoch-system' into soloseng/startNextEpochProce…
soloseng Aug 26, 2024
2ba9360
compiles
soloseng Aug 26, 2024
35b637a
++ require fund in unreleased treasury
soloseng Aug 27, 2024
c02c0a4
Updated regex
soloseng Aug 27, 2024
92ac7cf
++ registry 0.8 for testing only
soloseng Aug 27, 2024
f50ac8b
clean up
soloseng Aug 27, 2024
3aa816c
++ unit test
soloseng Aug 27, 2024
180162b
initial integration test using L1 devchain
soloseng Aug 27, 2024
22946ff
++ comment
soloseng Aug 27, 2024
0ed7e93
-- forge based integration test
soloseng Aug 27, 2024
7fcc9a8
Merge branch 'feat/l2-epoch-system' into soloseng/startNextEpochProce…
soloseng Aug 27, 2024
8f0ea64
++ to const
soloseng Aug 27, 2024
cfa7cdb
happy linter
soloseng Aug 28, 2024
cdf7aea
update contract name
soloseng Aug 28, 2024
b49f929
++ PR feedback
soloseng Aug 29, 2024
1b616ca
++ checks
soloseng Sep 10, 2024
b47dba3
updated carbon address
soloseng Sep 10, 2024
48db871
proxy stableToken mint call via Validators contract
soloseng Sep 11, 2024
8a8f4d9
Merge branch 'feat/l2-epoch-system' into soloseng/startNextEpochProce…
soloseng Sep 11, 2024
bbb239f
-- duplicate imports
soloseng Sep 11, 2024
2ffeed2
removed registry08. replaced with vm call
soloseng Sep 11, 2024
b195ebb
PR feedback
soloseng Sep 11, 2024
3c2ebfc
-- coment
soloseng Sep 12, 2024
83bd5aa
passing unit tests
soloseng Sep 12, 2024
1d4eaa4
clean up
soloseng Sep 12, 2024
43ae993
++ mintStable test
soloseng Sep 12, 2024
de06b4e
-- TODO; compiles test when filtering
soloseng Sep 12, 2024
0dc7c92
PR feedback
soloseng Sep 16, 2024
4d5360d
updated migration script to add more validators
soloseng Sep 16, 2024
729008f
passing integration test
soloseng Sep 16, 2024
20f8ae4
removed test for zero amount
soloseng Sep 16, 2024
6f986bd
yarn build fix
soloseng Sep 16, 2024
b09a3bb
clean up comments && TODO
soloseng Sep 16, 2024
60e3e70
revert change as out of scope
soloseng Sep 16, 2024
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
Prev Previous commit
Next Next commit
renamed EpochManagerInitializer due to name conflict
  • Loading branch information
soloseng committed Aug 21, 2024
commit c48b8e547bb02646807ef1f3c364a44dfae560ec
18 changes: 9 additions & 9 deletions packages/protocol/contracts-0.8/common/EpochManager.sol
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@ contract EpochManager is
mapping(address => uint256) public validatorPendingPayments;

address public carbonOffsettingPartner;
address public epochManagerInitializer;
address public EpochManagerSystemInitializer;

/**
* @notice Event emited when epochProcessing has begun.
@@ -72,8 +72,8 @@ contract EpochManager is
*/
event EpochProcessingEnded(uint256 indexed epochNumber);

modifier onlyEpochManagerInitializer() {
require(msg.sender == epochManagerInitializer, "msg.sender is not Initializer");
modifier onlyEpochManagerSystemInitializer() {
require(msg.sender == epochManagerSystemInitializer, "msg.sender is not Initializer");
_;
}

@@ -92,14 +92,14 @@ contract EpochManager is
address registryAddress,
uint256 newEpochDuration,
address _carbonOffsettingPartner,
address _epochManagerInitializer
address _epochManagerSystemInitializer
) external initializer {
require(_epochManagerInitializer != address(0), "EpochManagerInitializer address is required");
require(_epochManagerSystemInitializer != address(0), "EpochManagerSystemInitializer address is required");
_transferOwnership(msg.sender);
setRegistry(registryAddress);
setEpochDuration(newEpochDuration);
carbonOffsettingPartner = _carbonOffsettingPartner;
epochManagerInitializer = _epochManagerInitializer;
epochManagerSystemInitializer = _epochManagerSystemInitializer;
}

// DESIGNDESICION(XXX): we assume that the first epoch on the L2 starts as soon as the system is initialized
@@ -109,7 +109,7 @@ contract EpochManager is
uint256 firstEpochNumber,
uint256 firstEpochBlock,
address[] memory firstElected
) external onlyEpochManagerInitializer {
) external onlyEpochManagerSystemInitializer {
require(!systemAlreadyInitialized(), "Epoch system already initialized");
require(firstEpochNumber > 0, "First epoch number must be greater than 0");
require(firstEpochBlock > 0, "First epoch block must be greater than 0");
@@ -126,7 +126,7 @@ contract EpochManager is
_currentEpoch.startTimestamp = block.timestamp;

elected = firstElected;
epochManagerInitializer = address(0);
epochManagerSystemInitializer = address(0);
}

// TODO maybe "freezeEpochRewards" "prepareForNextEpoch"
@@ -290,7 +290,7 @@ contract EpochManager is
}

function systemAlreadyInitialized() public view returns (bool) {
return initialized && epochManagerInitializer == address(0);
return initialized && epochManagerSystemInitializer == address(0);
}

function allocateValidatorsRewards() internal {
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ import "../../contracts/common/Initializable.sol";
import "../../contracts/common/interfaces/ICeloVersionedContract.sol";
import "../../contracts/governance/interfaces/IEpochRewards.sol";

contract EpochManagerInitializer is Initializable, UsingPrecompiles, UsingRegistry {
contract EpochManagerSystemInitializer is Initializable, UsingPrecompiles, UsingRegistry {
/**
* @notice Sets initialized == true on implementation contracts
* @param test Set to true to skip implementation initialization
1 change: 0 additions & 1 deletion packages/protocol/test-sol/constants.sol
Original file line number Diff line number Diff line change
@@ -25,7 +25,6 @@ contract TestConstants {
string constant GovernanceContract = "Governance";
string constant EpochRewardsContract = "EpochRewards";
string constant EpochManagerContract = "EpochManager";
string constant EpochManagerInitializerContract = "EpochManagerInitializer";
string constant ScoreManagerContract = "ScoreManager";
string constant ReserveContract = "Reserve";
string constant CeloUnreleasedTreasureContract = "CeloUnreleasedTreasure";
19 changes: 10 additions & 9 deletions packages/protocol/test-sol/integration/EpochManagerIntegration.sol
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ contract EpochManagerIntegrationTest is Test, TestConstants, Utils08 {
ValidatorsMock08 validators;
MockElection08 election;

address epochManagerInitializer;
address epochManagerSystemInitializer;
address carbonOffsettingPartner;
address communityRewardFund;

@@ -100,7 +100,7 @@ contract EpochManagerIntegrationTest is Test, TestConstants, Utils08 {
address epochRewardsAddress = actor("epochRewardsAddress");
address freezerAddress = actor("freezerAddress");

epochManagerInitializer = actor("initializer");
epochManagerSystemInitializer = actor("epochManagerSystemInitializer");
carbonOffsettingPartner = actor("carbonOffsettingPartner");
communityRewardFund = actor("communityRewardFund");

@@ -131,8 +131,9 @@ contract EpochManagerIntegrationTest is Test, TestConstants, Utils08 {
registry.setAddressFor(FreezerContract, address(freezer));

celoToken.setTotalSupply(CELO_SUPPLY_CAP);
// election.setTotalVotes(5);
vm.deal(address(celoUnreleasedTreasure), L2_INITIAL_STASH_BALANCE);
vm.deal(address(reserve), L1_MINTED_CELO_SUPPLY);
// vm.deal(address(reserve), 69411663406170917420347916); // current as of 08/20/24

bool res1 = sortedOracles.setMedianRate(address(stableToken), stableAmountForRate);
(uint256 res0, uint256 res00) = sortedOracles.medianRate(address(stableToken));
@@ -163,7 +164,7 @@ contract EpochManagerIntegrationTest is Test, TestConstants, Utils08 {
REGISTRY_ADDRESS,
DAY,
carbonOffsettingPartner,
epochManagerInitializer
epochManagerSystemInitializer
);

blockTravel(vm, firstEpochBlock);
@@ -185,19 +186,19 @@ contract EpochManagerIntegrationTest_initialize is EpochManagerIntegrationTest {
REGISTRY_ADDRESS,
DAY,
carbonOffsettingPartner,
epochManagerInitializer
epochManagerSystemInitializer
);
}
}

contract EpochManagerIntegrationTest_initializeSystem is EpochManagerIntegrationTest {
function test_processCanBeStarted() public virtual {
vm.prank(epochManagerInitializer);
vm.prank(epochManagerSystemInitializer);
epochManager.initializeSystem(firstEpochNumber, firstEpochBlock, firstElected);
}

function test_Reverts_processCannotBeStartedAgain() public virtual {
vm.prank(epochManagerInitializer);
vm.prank(epochManagerSystemInitializer);
epochManager.initializeSystem(firstEpochNumber, firstEpochBlock, firstElected);
vm.prank(address(0));
vm.expectRevert("Epoch system already initialized");
@@ -217,15 +218,15 @@ contract EpochManagerIntegrationTest_startNextEpochProcess is EpochManagerIntegr
}

function test_Reverts_WhenEndOfEpochHasNotBeenReached() public {
vm.prank(epochManagerInitializer);
vm.prank(epochManagerSystemInitializer);
epochManager.initializeSystem(firstEpochNumber, firstEpochBlock, firstElected);

vm.expectRevert("Epoch is not ready to start");
epochManager.startNextEpochProcess();
}

function test_Succeeds() public {
vm.prank(epochManagerInitializer);
vm.prank(epochManagerSystemInitializer);
epochManager.initializeSystem(firstEpochNumber, firstEpochBlock, firstElected);

blockTravel(vm, 43200);
24 changes: 12 additions & 12 deletions packages/protocol/test-sol/unit/common/EpochManager.t.sol
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ contract EpochManagerTest is Test, TestConstants, Utils08 {
EpochRewardsMock08 epochRewards;
ValidatorsMock08 validators;

address epochManagerInitializer;
address epochManagerSystemInitializer;
address carbonOffsettingPartner;
address communityRewardFund;

@@ -73,7 +73,7 @@ contract EpochManagerTest is Test, TestConstants, Utils08 {
address scoreManagerAddress = actor("scoreManagerAddress");
address reserveAddress = actor("reserve");

epochManagerInitializer = actor("initializer");
epochManagerSystemInitializer = actor("epochManagerSystemInitializer");
carbonOffsettingPartner = actor("carbonOffsettingPartner");
communityRewardFund = actor("communityRewardFund");

@@ -107,7 +107,7 @@ contract EpochManagerTest is Test, TestConstants, Utils08 {
REGISTRY_ADDRESS,
epochDuration,
carbonOffsettingPartner,
epochManagerInitializer
epochManagerSystemInitializer
);

blockTravel(vm, firstEpochBlock);
@@ -119,26 +119,26 @@ contract EpochManagerTest_initialize is EpochManagerTest {
assertEq(address(epochManager.registry()), REGISTRY_ADDRESS);
assertEq(epochManager.epochDuration(), epochDuration);
assertEq(epochManager.carbonOffsettingPartner(), carbonOffsettingPartner);
assertEq(epochManager.epochManagerInitializer(), epochManagerInitializer);
assertEq(epochManager.epochManagerSystemInitializer(), epochManagerSystemInitializer);
}

function test_Reverts_WhenAlreadyInitialized() public virtual {
vm.expectRevert("contract already initialized");
epochManager.initialize(REGISTRY_ADDRESS, 10, carbonOffsettingPartner, epochManagerInitializer);
epochManager.initialize(REGISTRY_ADDRESS, 10, carbonOffsettingPartner, epochManagerSystemInitializer);
}
}

contract EpochManagerTest_initializeSystem is EpochManagerTest {
function test_processCanBeStarted() public virtual {
vm.prank(epochManagerInitializer);
vm.prank(epochManagerSystemInitializer);
epochManager.initializeSystem(firstEpochNumber, firstEpochBlock, firstElected);
(
uint256 _firstEpochBlock,
uint256 _lastEpochBlock,
uint256 _startTimestamp,
uint256 _currentRewardsBlock
) = epochManager.getCurrentEpoch();
assertEq(epochManager.epochManagerInitializer(), address(0));
assertEq(epochManager.epochManagerSystemInitializer(), address(0));
assertEq(epochManager.firstKnownEpoch(), firstEpochNumber);
assertEq(_firstEpochBlock, firstEpochBlock);
assertEq(_lastEpochBlock, 0);
@@ -148,7 +148,7 @@ contract EpochManagerTest_initializeSystem is EpochManagerTest {
}

function test_Reverts_processCannotBeStartedAgain() public virtual {
vm.prank(epochManagerInitializer);
vm.prank(epochManagerSystemInitializer);
epochManager.initializeSystem(firstEpochNumber, firstEpochBlock, firstElected);
vm.prank(address(0));
vm.expectRevert("Epoch system already initialized");
@@ -170,7 +170,7 @@ contract EpochManagerTest_startNextEpochProcess is EpochManagerTest {
}

function test_Reverts_WhenEndOfEpochHasNotBeenReached() public {
vm.prank(epochManagerInitializer);
vm.prank(epochManagerSystemInitializer);
epochManager.initializeSystem(firstEpochNumber, firstEpochBlock, firstElected);

uint256 _currentEpoch = epochManager.currentEpochNumber();
@@ -180,7 +180,7 @@ contract EpochManagerTest_startNextEpochProcess is EpochManagerTest {
}

function test_Reverts_WhenEpochProcessingAlreadyStarted() public {
vm.prank(epochManagerInitializer);
vm.prank(epochManagerSystemInitializer);
epochManager.initializeSystem(firstEpochNumber, firstEpochBlock, firstElected);

blockTravel(vm, 43200);
@@ -192,7 +192,7 @@ contract EpochManagerTest_startNextEpochProcess is EpochManagerTest {
}

function test_SetsTheEpochRewardBlock() public {
vm.prank(epochManagerInitializer);
vm.prank(epochManagerSystemInitializer);
epochManager.initializeSystem(firstEpochNumber, firstEpochBlock, firstElected);

blockTravel(vm, 43200);
@@ -204,7 +204,7 @@ contract EpochManagerTest_startNextEpochProcess is EpochManagerTest {
}

function test_SetsTheEpochRewardAmounts() public {
vm.prank(epochManagerInitializer);
vm.prank(epochManagerSystemInitializer);
epochManager.initializeSystem(firstEpochNumber, firstEpochBlock, firstElected);

blockTravel(vm, 43200);