Skip to content

Commit

Permalink
general L2 test framework (#11262)
Browse files Browse the repository at this point in the history
* removed L2 duplicated test code

* -- compiltation warning

* Removed duplicated L2 election test code
### Description

Using test contract inheritance to minimize duplicated code during L2 testing

### Other changes

removed unused var

### Tested

unit tested

### Related issues

- Fixes #[issue number here]

### Backwards compatibility

_Brief explanation of why these changes are/are not backwards compatible._

### Documentation

_The set of community facing docs that have been added/modified because of this change_

* Revert "Removed duplicated L2 election test code"

This reverts commit b0058c5.

* basic L2 setup

* -- duplicate

* -- duplicate test

* moved whenL2 to utils

* uncommented validator test

* -- duplicate call

* Remove unnecessary comment

* Add whitespace

* Add missing whitespace

---------

Co-authored-by: Marcin Chrzanowski <[email protected]>
  • Loading branch information
soloseng and m-chrzan authored Oct 30, 2024
1 parent c6994a6 commit 80952d6
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import "@celo-contracts/common/FixidityLib.sol";
import "@celo-contracts/common/Registry.sol";
import "@celo-contracts/common/Accounts.sol";
import "@celo-contracts/common/GoldToken.sol";
import "@celo-contracts-8/common/test/MockEpochManager.sol";
import "@celo-contracts-8/common/interfaces/IPrecompiles.sol";
import "@celo-contracts/governance/interfaces/IValidators.sol";

Expand All @@ -27,13 +26,13 @@ import { Utils } from "@test-sol/utils.sol";
import { Test as ForgeTest } from "forge-std/Test.sol";
import "@test-sol/unit/governance/validators/mocks/ValidatorsMockTunnel.sol";
import "@test-sol/unit/governance/voting/mocks/ReleaseGoldMockTunnel.sol";
import "@test-sol/unit/common/mocks/MockEpochManager.sol";

contract RevokeCeloAfterL2Transition is Test, TestConstants, ECDSAHelper, Utils {
using FixidityLib for FixidityLib.Fraction;

uint256 constant TOTAL_AMOUNT = 1 ether * 1_000_000;

Registry registry;
Accounts accounts;
MockStableToken stableToken;
Election election;
Expand All @@ -43,7 +42,6 @@ contract RevokeCeloAfterL2Transition is Test, TestConstants, ECDSAHelper, Utils
Governance governance;
GoldToken goldToken;
ReleaseGold releaseGold;
MockEpochManager epochManager;

address owner;
address accApprover;
Expand All @@ -55,7 +53,6 @@ contract RevokeCeloAfterL2Transition is Test, TestConstants, ECDSAHelper, Utils
address beneficiary;
address refundAddress;
address releaseOwner;
address epochManagerAddress = actor("epochManagerAddress");

address authorizedValidatorSigner;
uint256 authorizedValidatorSignerPK;
Expand Down Expand Up @@ -171,8 +168,8 @@ contract RevokeCeloAfterL2Transition is Test, TestConstants, ECDSAHelper, Utils
)
.unwrap();

deployCodeTo("Registry.sol", abi.encode(false), REGISTRY_ADDRESS);
registry = Registry(REGISTRY_ADDRESS);
setupRegistry();
setupEpochManager();

accounts = new Accounts(true);
stableToken = new MockStableToken();
Expand All @@ -187,8 +184,6 @@ contract RevokeCeloAfterL2Transition is Test, TestConstants, ECDSAHelper, Utils
goldToken = new GoldToken(true);
releaseGold = new ReleaseGold(true);

epochManager = new MockEpochManager();

registry.setAddressFor(AccountsContract, address(accounts));
registry.setAddressFor(ElectionContract, address(election));
registry.setAddressFor(StableTokenContract, address(stableToken));
Expand Down
4 changes: 2 additions & 2 deletions packages/protocol/test-sol/unit/common/EpochManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ contract EpochManagerTest is Test, TestConstants, Utils08 {
vm.prank(epochManagerEnabler);
epochManager.initializeSystem(firstEpochNumber, firstEpochBlock, firstElected);

travelEpochL2(vm);
travelNL2Epoch(vm, 1);
}

function getGroupsWithLessersAndGreaters()
Expand All @@ -186,7 +186,7 @@ contract EpochManagerTest is Test, TestConstants, Utils08 {

function _travelAndProcess_N_L2Epoch(uint256 n) public {
for (uint256 i = 0; i < n; i++) {
travelEpochL2(vm);
travelNL2Epoch(vm, 1);
epochManager.startNextEpochProcess();

(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
pragma solidity >=0.5.13 <0.9.0;
// solhint-disable no-unused-vars

import "../../../contracts/common/interfaces/IEpochManager.sol";
import "../../../../contracts/common/interfaces/IEpochManager.sol";

/**
* @title A mock EpochManager for testing.
* @title A mock EpochManager for testing with 0.5.
*/

contract MockEpochManager is IEpochManager {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ contract BlockchainParametersTest is Test, TestConstants, Utils {
ph.setEpochSize(DAY / 5);
blockchainParameters = new BlockchainParameters(true);
}
function _whenL2() public {
deployCodeTo("Registry.sol", abi.encode(false), PROXY_ADMIN_ADDRESS);
}
}

contract BlockchainParametersTest_initialize is BlockchainParametersTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ contract EpochRewardsTest is Test, TestConstants, Utils {
);
}

function _whenL2() public {
deployCodeTo("Registry.sol", abi.encode(false), PROXY_ADMIN_ADDRESS);
}
function getExpectedTargetTotalSupply(uint256 timeDelta) internal pure returns (uint256) {
uint256 genesisSupply = 600000000 ether;
uint256 linearRewards = 200000000 ether;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,6 @@ contract GovernanceTest is Test, TestConstants, Utils {
uint256 proposalId;
address constant proxyAdminAddress = 0x4200000000000000000000000000000000000018;

function _whenL2() public {
deployCodeTo("Registry.sol", abi.encode(false), proxyAdminAddress);
}

function setUp() public {
// Define Accounts
accVoter = actor("voter");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,6 @@ contract DowntimeSlasherTest is Test, TestConstants, Utils {
}
return (_epochNumber.sub(1)).mul(epochSize).add(1);
}

function _whenL2() public {
deployCodeTo("Registry.sol", abi.encode(false), PROXY_ADMIN_ADDRESS);
}
}

contract DowntimeSlasherTestInitialize is DowntimeSlasherTest {
Expand Down
Loading

0 comments on commit 80952d6

Please sign in to comment.