-
Notifications
You must be signed in to change notification settings - Fork 371
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make captureEpochAndValidators work in constant time (#11210)
- Loading branch information
Showing
6 changed files
with
156 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 12 additions & 2 deletions
14
packages/protocol/test-sol/precompiles/EpochSizePrecompile.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
packages/protocol/test-sol/unit/common/EpochManagerEnabler.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity >=0.8.7 <0.8.20; | ||
|
||
import "celo-foundry-8/Test.sol"; | ||
import "@celo-contracts-8/common/EpochManagerEnabler.sol"; | ||
import "@celo-contracts/stability/test/MockSortedOracles.sol"; | ||
import "@celo-contracts/common/interfaces/IRegistry.sol"; | ||
|
||
import { EPOCH_SIZEPRE_COMPILE_ADDRESS, EpochSizePrecompile } from "@test-sol/precompiles/EpochSizePrecompile.sol"; | ||
|
||
contract EpochManagerEnablerMock is EpochManagerEnabler { | ||
constructor(bool test) public EpochManagerEnabler(test) {} | ||
|
||
function setFirstBlockOfEpoch() external { | ||
return _setFirstBlockOfEpoch(); | ||
} | ||
} | ||
|
||
contract EpochManagerEnablerTest is Test { | ||
EpochManagerEnablerMock epochManagerEnabler; | ||
uint256 EPOCH_SIZE_NEW = 17280; | ||
|
||
function setUp() public virtual { | ||
deployCodeTo("EpochSizePrecompile", EPOCH_SIZEPRE_COMPILE_ADDRESS); | ||
address payable payableAddress = payable(EPOCH_SIZEPRE_COMPILE_ADDRESS); | ||
|
||
EpochSizePrecompile(payableAddress).setEpochSize(EPOCH_SIZE_NEW); | ||
|
||
epochManagerEnabler = new EpochManagerEnablerMock(true); | ||
} | ||
|
||
function test_precompilerWorks() public { | ||
// Make sure epoch size is correct | ||
assertEq(epochManagerEnabler.getEpochSize(), EPOCH_SIZE_NEW); | ||
} | ||
} | ||
|
||
contract EpochManagerEnablerTest_getFirstBlockOfEpoch is EpochManagerEnablerTest { | ||
function test_blockIsEpockBlock() public { | ||
vm.roll(27803520); | ||
epochManagerEnabler.setFirstBlockOfEpoch(); | ||
assertEq(epochManagerEnabler.lastKnownFirstBlockOfEpoch(), 27803520); | ||
} | ||
|
||
function test_blockIsNotEpochBlock() public { | ||
vm.roll(27817229); | ||
epochManagerEnabler.setFirstBlockOfEpoch(); | ||
assertEq(epochManagerEnabler.lastKnownFirstBlockOfEpoch(), 27803520); | ||
} | ||
} |