From 131c4996dfb9ab9a0564c1ecf9144e2b63a23b5b Mon Sep 17 00:00:00 2001 From: Martin Date: Tue, 15 Oct 2024 20:18:12 +0200 Subject: [PATCH] Deprecate unnecessary public variables in L2 (#11247) --- .../contracts-0.8/common/GasPriceMinimum.sol | 90 +++++++++++++----- .../contracts/common/FeeCurrencyWhitelist.sol | 40 +++++--- .../governance/BlockchainParameters.sol | 32 +++++-- .../protocol/contracts/identity/Random.sol | 38 +++++--- .../unit/common/FeeCurrencyWhitelist.t.sol | 59 +++++++++++- .../unit/common/GasPriceMinimum.t.sol | 93 ++++++++++++++++++- .../network/BlockchainParameters.t.sol | 18 ++++ .../test-sol/unit/identity/Random.t.sol | 83 ++++++++++++----- 8 files changed, 373 insertions(+), 80 deletions(-) diff --git a/packages/protocol/contracts-0.8/common/GasPriceMinimum.sol b/packages/protocol/contracts-0.8/common/GasPriceMinimum.sol index 05d3551a971..4c3941c8f97 100644 --- a/packages/protocol/contracts-0.8/common/GasPriceMinimum.sol +++ b/packages/protocol/contracts-0.8/common/GasPriceMinimum.sol @@ -26,17 +26,17 @@ contract GasPriceMinimum is // TODO add IGasPriceMinimum using FixidityLib for FixidityLib.Fraction; - uint256 public deprecated_gasPriceMinimum; - uint256 public gasPriceMinimumFloor; + uint256 private deprecated_gasPriceMinimum; + uint256 private deprecated_gasPriceMinimumFloor; // Block congestion level targeted by the gas price minimum calculation. - FixidityLib.Fraction public targetDensity; + FixidityLib.Fraction private deprecated_targetDensity; // Speed of gas price minimum adjustment due to congestion. - FixidityLib.Fraction public adjustmentSpeed; + FixidityLib.Fraction private deprecated_adjustmentSpeed; - uint256 public baseFeeOpCodeActivationBlock; - uint256 public constant ABSOLUTE_MINIMAL_GAS_PRICE = 1; + uint256 private deprecated_baseFeeOpCodeActivationBlock; + uint256 private constant ABSOLUTE_MINIMAL_GAS_PRICE = 1; event TargetDensitySet(uint256 targetDensity); event GasPriceMinimumFloorSet(uint256 gasPriceMinimumFloor); @@ -112,7 +112,7 @@ contract GasPriceMinimum is * @param tokenAddress The currency the gas price should be in (defaults to Celo). * @return current gas price minimum in the requested currency */ - function getGasPriceMinimum(address tokenAddress) external view returns (uint256) { + function getGasPriceMinimum(address tokenAddress) external view onlyL1 returns (uint256) { return Math.max(_getGasPriceMinimum(tokenAddress), ABSOLUTE_MINIMAL_GAS_PRICE); } /** @@ -123,7 +123,7 @@ contract GasPriceMinimum is * @return Patch version of the contract. */ function getVersionNumber() external pure returns (uint256, uint256, uint256, uint256) { - return (1, 2, 0, 2); + return (1, 2, 1, 0); } /** @@ -132,8 +132,11 @@ contract GasPriceMinimum is * @dev Value is expected to be < 1. */ function setAdjustmentSpeed(uint256 _adjustmentSpeed) public onlyOwner onlyL1 { - adjustmentSpeed = FixidityLib.wrap(_adjustmentSpeed); - require(adjustmentSpeed.lt(FixidityLib.fixed1()), "adjustment speed must be smaller than 1"); + deprecated_adjustmentSpeed = FixidityLib.wrap(_adjustmentSpeed); + require( + deprecated_adjustmentSpeed.lt(FixidityLib.fixed1()), + "adjustment speed must be smaller than 1" + ); emit AdjustmentSpeedSet(_adjustmentSpeed); } @@ -143,8 +146,11 @@ contract GasPriceMinimum is * @dev Value is expected to be < 1. */ function setTargetDensity(uint256 _targetDensity) public onlyOwner onlyL1 { - targetDensity = FixidityLib.wrap(_targetDensity); - require(targetDensity.lt(FixidityLib.fixed1()), "target density must be smaller than 1"); + deprecated_targetDensity = FixidityLib.wrap(_targetDensity); + require( + deprecated_targetDensity.lt(FixidityLib.fixed1()), + "target density must be smaller than 1" + ); emit TargetDensitySet(_targetDensity); } @@ -155,12 +161,15 @@ contract GasPriceMinimum is */ function setGasPriceMinimumFloor(uint256 _gasPriceMinimumFloor) public onlyOwner onlyL1 { require(_gasPriceMinimumFloor > 0, "gas price minimum floor must be greater than zero"); - gasPriceMinimumFloor = _gasPriceMinimumFloor; + deprecated_gasPriceMinimumFloor = _gasPriceMinimumFloor; emit GasPriceMinimumFloorSet(_gasPriceMinimumFloor); } - function gasPriceMinimum() public view returns (uint256) { - if (baseFeeOpCodeActivationBlock > 0 && block.number >= baseFeeOpCodeActivationBlock) { + function gasPriceMinimum() public view onlyL1 returns (uint256) { + if ( + deprecated_baseFeeOpCodeActivationBlock > 0 && + block.number >= deprecated_baseFeeOpCodeActivationBlock + ) { return block.basefee; } else { return deprecated_gasPriceMinimum; @@ -179,25 +188,60 @@ contract GasPriceMinimum is function getUpdatedGasPriceMinimum( uint256 blockGasTotal, uint256 blockGasLimit - ) public view returns (uint256) { + ) public view onlyL1 returns (uint256) { FixidityLib.Fraction memory blockDensity = FixidityLib.newFixedFraction( blockGasTotal, blockGasLimit ); - bool densityGreaterThanTarget = blockDensity.gt(targetDensity); + bool densityGreaterThanTarget = blockDensity.gt(deprecated_targetDensity); FixidityLib.Fraction memory densityDelta = densityGreaterThanTarget - ? blockDensity.subtract(targetDensity) - : targetDensity.subtract(blockDensity); + ? blockDensity.subtract(deprecated_targetDensity) + : deprecated_targetDensity.subtract(blockDensity); FixidityLib.Fraction memory adjustment = densityGreaterThanTarget - ? FixidityLib.fixed1().add(adjustmentSpeed.multiply(densityDelta)) - : FixidityLib.fixed1().subtract(adjustmentSpeed.multiply(densityDelta)); + ? FixidityLib.fixed1().add(deprecated_adjustmentSpeed.multiply(densityDelta)) + : FixidityLib.fixed1().subtract(deprecated_adjustmentSpeed.multiply(densityDelta)); uint256 newGasPriceMinimum = adjustment .multiply(FixidityLib.newFixed(gasPriceMinimum())) .add(FixidityLib.fixed1()) .fromFixed(); - return newGasPriceMinimum >= gasPriceMinimumFloor ? newGasPriceMinimum : gasPriceMinimumFloor; + return + newGasPriceMinimum >= deprecated_gasPriceMinimumFloor + ? newGasPriceMinimum + : deprecated_gasPriceMinimumFloor; + } + + /** + * @notice Returns the gas price minimum floor. + * @return The gas price minimum floor. + */ + function gasPriceMinimumFloor() external view onlyL1 returns (uint256) { + return deprecated_gasPriceMinimumFloor; + } + + /** + * @notice Returns the target density. + * @return The target density. + */ + function targetDensity() external view onlyL1 returns (uint256) { + return deprecated_targetDensity.unwrap(); + } + + /** + * @notice Returns the adjustment speed. + * @return The adjustment speed. + */ + function adjustmentSpeed() external view onlyL1 returns (uint256) { + return deprecated_adjustmentSpeed.unwrap(); + } + + /** + * @notice Returns the basefee opcode activation block. + * @return The basefee opcode activation block. + */ + function baseFeeOpCodeActivationBlock() external view onlyL1 returns (uint256) { + return deprecated_baseFeeOpCodeActivationBlock; } /** @@ -213,7 +257,7 @@ contract GasPriceMinimum is allowZero || _baseFeeOpCodeActivationBlock > 0, "baseFee opCode activation block must be greater than zero" ); - baseFeeOpCodeActivationBlock = _baseFeeOpCodeActivationBlock; + deprecated_baseFeeOpCodeActivationBlock = _baseFeeOpCodeActivationBlock; emit BaseFeeOpCodeActivationBlockSet(_baseFeeOpCodeActivationBlock); } diff --git a/packages/protocol/contracts/common/FeeCurrencyWhitelist.sol b/packages/protocol/contracts/common/FeeCurrencyWhitelist.sol index b0dc16ef56d..2f2adb88aaa 100644 --- a/packages/protocol/contracts/common/FeeCurrencyWhitelist.sol +++ b/packages/protocol/contracts/common/FeeCurrencyWhitelist.sol @@ -3,10 +3,9 @@ pragma solidity ^0.5.13; import "openzeppelin-solidity/contracts/ownership/Ownable.sol"; import "./interfaces/IFeeCurrencyWhitelist.sol"; - import "../common/Initializable.sol"; - import "../common/interfaces/ICeloVersionedContract.sol"; +import "../../contracts-0.8/common/IsL2Check.sol"; /** * @title Holds a whitelist of the ERC20+ tokens that can be used to pay for gas @@ -16,10 +15,11 @@ contract FeeCurrencyWhitelist is IFeeCurrencyWhitelist, Ownable, Initializable, - ICeloVersionedContract + ICeloVersionedContract, + IsL2Check { // Array of all the tokens enabled - address[] public whitelist; + address[] private deprecated_whitelist; event FeeCurrencyWhitelisted(address token); @@ -42,16 +42,28 @@ contract FeeCurrencyWhitelist is * @dev Add a token to the whitelist * @param tokenAddress The address of the token to add. */ - function addToken(address tokenAddress) external onlyOwner { - whitelist.push(tokenAddress); + function addToken(address tokenAddress) external onlyOwner onlyL1 { + deprecated_whitelist.push(tokenAddress); emit FeeCurrencyWhitelisted(tokenAddress); } /** * @return a list of all tokens enabled as gas fee currency. + * @dev Once Celo becomes an L2, use the FeeCurrencyDirectory contract + * instead. + */ + function getWhitelist() external view onlyL1 returns (address[] memory) { + return deprecated_whitelist; + } + + /** + * @notice Gets the whitelist item at the specified index. + * @return Address of a token in the whitelist. + * @dev Once Celo becomes an L2, use the FeeCurrencyDirectory contract + * instead. */ - function getWhitelist() external view returns (address[] memory) { - return whitelist; + function whitelist(uint256 index) external view onlyL1 returns (address) { + return deprecated_whitelist[index]; } /** @@ -62,7 +74,7 @@ contract FeeCurrencyWhitelist is * @return Patch version of the contract. */ function getVersionNumber() external pure returns (uint256, uint256, uint256, uint256) { - return (1, 1, 1, 0); + return (1, 1, 2, 0); } /** @@ -71,11 +83,11 @@ contract FeeCurrencyWhitelist is * @param tokenAddress The address of the token to remove. * @param index The index of the token in the whitelist array. */ - function removeToken(address tokenAddress, uint256 index) public onlyOwner { - require(whitelist[index] == tokenAddress, "Index does not match"); - uint256 length = whitelist.length; - whitelist[index] = whitelist[length - 1]; - whitelist.pop(); + function removeToken(address tokenAddress, uint256 index) public onlyOwner onlyL1 { + require(deprecated_whitelist[index] == tokenAddress, "Index does not match"); + uint256 length = deprecated_whitelist.length; + deprecated_whitelist[index] = deprecated_whitelist[length - 1]; + deprecated_whitelist.pop(); emit FeeCurrencyWhitelistRemoved(tokenAddress); } } diff --git a/packages/protocol/contracts/governance/BlockchainParameters.sol b/packages/protocol/contracts/governance/BlockchainParameters.sol index 31777090d76..45bebda1704 100644 --- a/packages/protocol/contracts/governance/BlockchainParameters.sol +++ b/packages/protocol/contracts/governance/BlockchainParameters.sol @@ -28,9 +28,9 @@ contract BlockchainParameters is Ownable, Initializable, UsingPrecompiles { } ClientVersion private minimumClientVersion; // obsolete - uint256 public blockGasLimit; - uint256 public intrinsicGasForAlternativeFeeCurrency; - LookbackWindow public uptimeLookbackWindow; + uint256 private deprecated_blockGasLimit; + uint256 private deprecated_intrinsicGasForAlternativeFeeCurrency; + LookbackWindow private uptimeLookbackWindow; event IntrinsicGasForAlternativeFeeCurrencySet(uint256 gas); event BlockGasLimitSet(uint256 limit); @@ -67,7 +67,7 @@ contract BlockchainParameters is Ownable, Initializable, UsingPrecompiles { * @return Patch version of the contract. */ function getVersionNumber() external pure returns (uint256, uint256, uint256, uint256) { - return (1, 3, 0, 1); + return (1, 3, 1, 0); } /** @@ -75,7 +75,7 @@ contract BlockchainParameters is Ownable, Initializable, UsingPrecompiles { * @param gasLimit New block gas limit. */ function setBlockGasLimit(uint256 gasLimit) public onlyOwner onlyL1 { - blockGasLimit = gasLimit; + deprecated_blockGasLimit = gasLimit; emit BlockGasLimitSet(gasLimit); } @@ -84,7 +84,7 @@ contract BlockchainParameters is Ownable, Initializable, UsingPrecompiles { * @param gas Intrinsic gas for non-gold gas currencies. */ function setIntrinsicGasForAlternativeFeeCurrency(uint256 gas) public onlyOwner onlyL1 { - intrinsicGasForAlternativeFeeCurrency = gas; + deprecated_intrinsicGasForAlternativeFeeCurrency = gas; emit IntrinsicGasForAlternativeFeeCurrencySet(gas); } @@ -116,6 +116,26 @@ contract BlockchainParameters is Ownable, Initializable, UsingPrecompiles { require(lookbackWindow != 0, "UptimeLookbackWindow is not initialized"); } + /** + * @notice Gets the Celo L1 block gas limit. + * @return The block gas limit. + * @dev Once Celo becomes an L2, query Optimism's L1 SystemConfig contract + * instead. + */ + function blockGasLimit() public view onlyL1 returns (uint256) { + return deprecated_blockGasLimit; + } + + /** + * @notice Gets the intrinsic gas paid for transactions using alternative fee + * currencies. + * @return The intrinsic gas for alternative fee currencies. + * @dev Once Celo becomes an L2, query the FeeCurrencyDirectory instead. + */ + function intrinsicGasForAlternativeFeeCurrency() public view onlyL1 returns (uint256) { + return deprecated_intrinsicGasForAlternativeFeeCurrency; + } + /** * @notice Gets the uptime lookback window. */ diff --git a/packages/protocol/contracts/identity/Random.sol b/packages/protocol/contracts/identity/Random.sol index 8062d6b9612..41ffdbc1d22 100644 --- a/packages/protocol/contracts/identity/Random.sol +++ b/packages/protocol/contracts/identity/Random.sol @@ -23,9 +23,9 @@ contract Random is using SafeMath for uint256; /* Stores most recent commitment per address */ - mapping(address => bytes32) public commitments; + mapping(address => bytes32) private deprecated_commitments; - uint256 public randomnessBlockRetentionWindow; + uint256 private deprecated_randomnessBlockRetentionWindow; mapping(uint256 => bytes32) private history; uint256 private historyFirst; @@ -77,6 +77,20 @@ contract Random is return _getBlockRandomness(block.number, block.number); } + /** + * @notice Returns the most recent commitment by a validator. + * @param addr Address of the validator. + * @return The validator's most recent commitment. + * @dev The Random system will be deprecated once Celo becomes an L2. + */ + function commitments(address addr) external view onlyL1 returns (bytes32) { + return deprecated_commitments[addr]; + } + + function randomnessBlockRetentionWindow() external view onlyL1 returns (uint256) { + return deprecated_randomnessBlockRetentionWindow; + } + /** * @notice Get randomness values of previous blocks. * @param blockNumber The number of block whose randomness value we want to know. @@ -95,7 +109,7 @@ contract Random is * @return Patch version of the contract. */ function getVersionNumber() external pure returns (uint256, uint256, uint256, uint256) { - return (1, 1, 1, 1); + return (1, 1, 2, 0); } /** @@ -105,7 +119,7 @@ contract Random is */ function setRandomnessBlockRetentionWindow(uint256 value) public onlyL1 onlyOwner { require(value > 0, "randomnessBlockRetetionWindow cannot be zero"); - randomnessBlockRetentionWindow = value; + deprecated_randomnessBlockRetentionWindow = value; emit RandomnessBlockRetentionWindowSet(value); } @@ -133,11 +147,11 @@ contract Random is require(newCommitment != computeCommitment(0), "cannot commit zero randomness"); // ensure revealed randomness matches previous commitment - if (commitments[proposer] != 0) { + if (deprecated_commitments[proposer] != 0) { require(randomness != 0, "randomness cannot be zero if there is a previous commitment"); bytes32 expectedCommitment = computeCommitment(randomness); require( - expectedCommitment == commitments[proposer], + expectedCommitment == deprecated_commitments[proposer], "commitment didn't match the posted randomness" ); } else { @@ -148,7 +162,7 @@ contract Random is uint256 blockNumber = block.number == 0 ? 0 : block.number.sub(1); addRandomness(block.number, keccak256(abi.encodePacked(history[blockNumber], randomness))); - commitments[proposer] = newCommitment; + deprecated_commitments[proposer] = newCommitment; } /** @@ -170,16 +184,16 @@ contract Random is if (historySize == 0) { historyFirst = blockNumber; historySize = 1; - } else if (historySize > randomnessBlockRetentionWindow) { + } else if (historySize > deprecated_randomnessBlockRetentionWindow) { deleteHistoryIfNotLastEpochBlock(historyFirst); deleteHistoryIfNotLastEpochBlock(historyFirst.add(1)); historyFirst = historyFirst.add(2); historySize = historySize.sub(1); - } else if (historySize == randomnessBlockRetentionWindow) { + } else if (historySize == deprecated_randomnessBlockRetentionWindow) { deleteHistoryIfNotLastEpochBlock(historyFirst); historyFirst = historyFirst.add(1); } else { - // historySize < randomnessBlockRetentionWindow + // historySize < deprecated_randomnessBlockRetentionWindow historySize = historySize.add(1); } } @@ -206,8 +220,8 @@ contract Random is require( blockNumber == lastEpochBlock || (blockNumber > cur.sub(historySize) && - (randomnessBlockRetentionWindow >= cur || - blockNumber > cur.sub(randomnessBlockRetentionWindow))), + (deprecated_randomnessBlockRetentionWindow >= cur || + blockNumber > cur.sub(deprecated_randomnessBlockRetentionWindow))), "Cannot query randomness older than the stored history" ); return history[blockNumber]; diff --git a/packages/protocol/test-sol/unit/common/FeeCurrencyWhitelist.t.sol b/packages/protocol/test-sol/unit/common/FeeCurrencyWhitelist.t.sol index 8f5d6a787a0..6dae11cb09f 100644 --- a/packages/protocol/test-sol/unit/common/FeeCurrencyWhitelist.t.sol +++ b/packages/protocol/test-sol/unit/common/FeeCurrencyWhitelist.t.sol @@ -4,7 +4,9 @@ pragma solidity ^0.5.13; import "celo-foundry/Test.sol"; import "@celo-contracts/common/FeeCurrencyWhitelist.sol"; -contract FeeCurrencyWhitelistTest is Test { +import { TestConstants } from "@test-sol/constants.sol"; + +contract FeeCurrencyWhitelistTest is Test, TestConstants { FeeCurrencyWhitelist feeCurrencyWhitelist; address nonOwner; address owner; @@ -16,6 +18,10 @@ contract FeeCurrencyWhitelistTest is Test { feeCurrencyWhitelist = new FeeCurrencyWhitelist(true); feeCurrencyWhitelist.initialize(); } + + function _whenL2() public { + deployCodeTo("Registry.sol", abi.encode(false), PROXY_ADMIN_ADDRESS); + } } contract FeeCurrencyWhitelistInitialize is FeeCurrencyWhitelistTest { @@ -43,6 +49,12 @@ contract FeeCurrencyWhitelistAddToken is FeeCurrencyWhitelistTest { vm.prank(nonOwner); feeCurrencyWhitelist.addToken(address(1)); } + + function test_Reverts_WhenCalledOnL2() public { + _whenL2(); + vm.expectRevert("This method is no longer supported in L2."); + feeCurrencyWhitelist.addToken(address(1)); + } } contract FeeCurrencyWhitelistRemoveToken is FeeCurrencyWhitelistTest { @@ -71,4 +83,49 @@ contract FeeCurrencyWhitelistRemoveToken is FeeCurrencyWhitelistTest { vm.prank(nonOwner); feeCurrencyWhitelist.removeToken(address(2), 1); } + + function test_Reverts_WhenCalledOnL2() public { + _whenL2(); + vm.expectRevert("This method is no longer supported in L2."); + feeCurrencyWhitelist.removeToken(address(2), 1); + } +} + +contract FeeCurrencyWhitelist_whitelist is FeeCurrencyWhitelistTest { + function setUp() public { + super.setUp(); + feeCurrencyWhitelist.addToken(address(1)); + } + + function test_ShouldRetrieveAToken() public { + address token = feeCurrencyWhitelist.whitelist(0); + assertEq(token, address(1)); + } + + function test_Reverts_WhenCalledOnL2() public { + _whenL2(); + vm.expectRevert("This method is no longer supported in L2."); + feeCurrencyWhitelist.whitelist(0); + } +} + +contract FeeCurrencyWhitelist_getWhitelist is FeeCurrencyWhitelistTest { + function setUp() public { + super.setUp(); + feeCurrencyWhitelist.addToken(address(1)); + feeCurrencyWhitelist.addToken(address(2)); + } + + function test_ShouldRetrieveAToken() public { + address[] memory tokens = feeCurrencyWhitelist.getWhitelist(); + assertEq(tokens.length, 2); + assertEq(tokens[0], address(1)); + assertEq(tokens[1], address(2)); + } + + function test_Reverts_WhenCalledOnL2() public { + _whenL2(); + vm.expectRevert("This method is no longer supported in L2."); + feeCurrencyWhitelist.getWhitelist(); + } } diff --git a/packages/protocol/test-sol/unit/common/GasPriceMinimum.t.sol b/packages/protocol/test-sol/unit/common/GasPriceMinimum.t.sol index 1836d170273..8a732e34bd1 100644 --- a/packages/protocol/test-sol/unit/common/GasPriceMinimum.t.sol +++ b/packages/protocol/test-sol/unit/common/GasPriceMinimum.t.sol @@ -199,7 +199,7 @@ contract GasPriceMinimumTest_setGasPriceMinimumFloor is GasPriceMinimumTest { } } -contract GasPriceMinimumTest_setUpdatedGasPriceMinimum is GasPriceMinimumTest { +contract GasPriceMinimumTest_getUpdatedGasPriceMinimum is GasPriceMinimumTest { using FixidityLib for FixidityLib.Fraction; uint256 nonce = 0; @@ -297,4 +297,95 @@ contract GasPriceMinimumTest_setUpdatedGasPriceMinimum is GasPriceMinimumTest { assertEq(actualUpdatedGasPriceMinimum, expectedUpdatedGasPriceMinimum); } } + + function test_shouldRevert_WhenCalledOnL2() public { + _whenL2(); + vm.expectRevert("This method is no longer supported in L2."); + gasPriceMinimum.getUpdatedGasPriceMinimum(0, 1); + } +} + +contract GasPriceMinimumTest_gasPriceMinimumFloor is GasPriceMinimumTest { + function test_shouldReturnTheGasPriceMinimumFloor() public { + uint256 gasPriceMinFloor = gasPriceMinimum.gasPriceMinimumFloor(); + assertEq(gasPriceMinFloor, gasPriceMinimumFloor); + } + + function test_shouldRevert_WhenCalledOnL2() public { + _whenL2(); + vm.expectRevert("This method is no longer supported in L2."); + gasPriceMinimum.gasPriceMinimumFloor(); + } +} + +contract GasPriceMinimumTest_targetDensity is GasPriceMinimumTest { + function test_shouldReturnTheTargetDensity() public { + uint256 realTargetDensity = gasPriceMinimum.targetDensity(); + assertEq(realTargetDensity, targetDensity); + } + + function test_shouldRevert_WhenCalledOnL2() public { + _whenL2(); + vm.expectRevert("This method is no longer supported in L2."); + gasPriceMinimum.targetDensity(); + } +} + +contract GasPriceMinimumTest_adjustmentSpeed is GasPriceMinimumTest { + function test_shouldReturnTheAdjustementSpeed() public { + uint256 realAdjustementSpeed = gasPriceMinimum.adjustmentSpeed(); + assertEq(realAdjustementSpeed, adjustmentSpeed); + } + + function test_shouldRevert_WhenCalledOnL2() public { + _whenL2(); + vm.expectRevert("This method is no longer supported in L2."); + gasPriceMinimum.adjustmentSpeed(); + } +} + +contract GasPriceMinimumTest_baseFeeOpCodeActivationBlock is GasPriceMinimumTest { + uint256 baseFeeOpCodeActivationBlock = 123; + + function setUp() public override { + super.setUp(); + gasPriceMinimum.setBaseFeeOpCodeActivationBlock(baseFeeOpCodeActivationBlock); + } + + function test_shouldReturnTheBaseFeeOpCodeActivationBlock() public { + uint256 realBaseFeeOpCodeActivationBlock = gasPriceMinimum.baseFeeOpCodeActivationBlock(); + assertEq(realBaseFeeOpCodeActivationBlock, baseFeeOpCodeActivationBlock); + } + + function test_shouldRevert_WhenCalledOnL2() public { + _whenL2(); + vm.expectRevert("This method is no longer supported in L2."); + gasPriceMinimum.baseFeeOpCodeActivationBlock(); + } +} + +contract GasPriceMinimumTest_gasPriceMinimum is GasPriceMinimumTest { + function test_shouldReturnTheGasPriceMinimum() public { + uint256 realGasPriceMinimum = gasPriceMinimum.gasPriceMinimum(); + assertEq(realGasPriceMinimum, 100); + } + + function test_shouldRevert_WhenCalledOnL2() public { + _whenL2(); + vm.expectRevert("This method is no longer supported in L2."); + gasPriceMinimum.gasPriceMinimum(); + } +} + +contract GasPriceMinimumTest_getGasPriceMinimum is GasPriceMinimumTest { + function test_shouldReturnTheGasPriceMinimum() public { + uint256 realGasPriceMinimum = gasPriceMinimum.getGasPriceMinimum(address(0)); + assertEq(realGasPriceMinimum, 100); + } + + function test_shouldRevert_WhenCalledOnL2() public { + _whenL2(); + vm.expectRevert("This method is no longer supported in L2."); + gasPriceMinimum.getGasPriceMinimum(address(0)); + } } diff --git a/packages/protocol/test-sol/unit/governance/network/BlockchainParameters.t.sol b/packages/protocol/test-sol/unit/governance/network/BlockchainParameters.t.sol index 45e95e13b5d..b3e507b0e31 100644 --- a/packages/protocol/test-sol/unit/governance/network/BlockchainParameters.t.sol +++ b/packages/protocol/test-sol/unit/governance/network/BlockchainParameters.t.sol @@ -173,3 +173,21 @@ contract BlockchainParametersTest_setUptimeLookbackWindow is BlockchainParameter blockchainParameters.setUptimeLookbackWindow(100); } } + +contract BlockchainParametersTest_blockGasLimit is BlockchainParametersTest { + function test_Reverts_WhenCalledOnL2() public { + _whenL2(); + vm.expectRevert("This method is no longer supported in L2."); + blockchainParameters.blockGasLimit(); + } +} + +contract BlockchainParametersTest_intrinsicGasForAlternativeFeeCurrency is + BlockchainParametersTest +{ + function test_Reverts_WhenCalledOnL2() public { + _whenL2(); + vm.expectRevert("This method is no longer supported in L2."); + blockchainParameters.intrinsicGasForAlternativeFeeCurrency(); + } +} diff --git a/packages/protocol/test-sol/unit/identity/Random.t.sol b/packages/protocol/test-sol/unit/identity/Random.t.sol index 6d72c5cc406..dba2ec9744a 100644 --- a/packages/protocol/test-sol/unit/identity/Random.t.sol +++ b/packages/protocol/test-sol/unit/identity/Random.t.sol @@ -8,16 +8,26 @@ import { TestConstants } from "@test-sol/constants.sol"; import "@celo-contracts/identity/Random.sol"; import "@celo-contracts/identity/test/RandomTest.sol"; -contract RandomnessTest_SetRandomnessRetentionWindow is Test, TestConstants, IsL2Check { - event RandomnessBlockRetentionWindowSet(uint256 value); - +contract RandomTest_ is Test, TestConstants, Utils, IsL2Check { RandomTest random; + event RandomnessBlockRetentionWindowSet(uint256 value); + function setUp() public { random = new RandomTest(); random.initialize(256); } + function commitmentFor(uint256 value) internal pure returns (bytes32) { + return keccak256(abi.encodePacked(bytes32(value))); + } + + function _whenL2() public { + deployCodeTo("Registry.sol", abi.encode(false), PROXY_ADMIN_ADDRESS); + } +} + +contract RandomTest_SetRandomnessRetentionWindow is RandomTest_ { function test_ShouldSetTheVariable() public { random.setRandomnessBlockRetentionWindow(1000); assertEq(random.randomnessBlockRetentionWindow(), 1000); @@ -36,23 +46,16 @@ contract RandomnessTest_SetRandomnessRetentionWindow is Test, TestConstants, IsL } function test_Reverts_WhenCalledOnL2() public { - deployCodeTo("Registry.sol", abi.encode(false), PROXY_ADMIN_ADDRESS); + _whenL2(); vm.expectRevert("This method is no longer supported in L2."); random.setRandomnessBlockRetentionWindow(1000); } } -contract RandomnessTest_AddTestRandomness is Test, TestConstants, Utils, IsL2Check { +contract RandomTest_AddTestRandomness is RandomTest_ { uint256 constant RETENTION_WINDOW = 5; uint256 constant EPOCH_SIZE = 10; - RandomTest random; - - function setUp() public { - random = new RandomTest(); - random.initialize(256); - } - function test_ShouldBeAbleToSimulateAddingRandomness() public { random.addTestRandomness(1, 0x0000000000000000000000000000000000000000000000000000000000000001); random.addTestRandomness(2, 0x0000000000000000000000000000000000000000000000000000000000000002); @@ -217,7 +220,7 @@ contract RandomnessTest_AddTestRandomness is Test, TestConstants, Utils, IsL2Che } function test_Reverts_WhenCalledOnL2() public { - deployCodeTo("Registry.sol", abi.encode(false), PROXY_ADMIN_ADDRESS); + _whenL2(); vm.expectRevert("This method is no longer supported in L2."); random.addTestRandomness(1, 0x0000000000000000000000000000000000000000000000000000000000000001); vm.expectRevert("This method is no longer supported in L2."); @@ -225,22 +228,15 @@ contract RandomnessTest_AddTestRandomness is Test, TestConstants, Utils, IsL2Che } } -contract RandomnessTest_RevealAndCommit is Test, TestConstants, Utils, IsL2Check { +contract RandomTest_RevealAndCommit is RandomTest_ { address constant ACCOUNT = address(0x01); bytes32 constant RANDONMESS = bytes32(uint256(0x00)); - RandomTest random; - function setUp() public { - random = new RandomTest(); - random.initialize(256); + super.setUp(); random.setRandomnessBlockRetentionWindow(256); } - function commitmentFor(uint256 value) private pure returns (bytes32) { - return keccak256(abi.encodePacked(bytes32(value))); - } - function testRevert_CannotAddZeroCommitment() public { vm.expectRevert("cannot commit zero randomness"); random.testRevealAndCommit(RANDONMESS, commitmentFor(0x00), ACCOUNT); @@ -263,9 +259,50 @@ contract RandomnessTest_RevealAndCommit is Test, TestConstants, Utils, IsL2Check } function test_Reverts_WhenCalledOnL2() public { - deployCodeTo("Registry.sol", abi.encode(false), PROXY_ADMIN_ADDRESS); + _whenL2(); vm.expectRevert("This method is no longer supported in L2."); blockTravel(2); random.testRevealAndCommit(RANDONMESS, commitmentFor(0x01), ACCOUNT); } } + +contract RandomTest_Commitments is RandomTest_ { + address constant ACCOUNT = address(0x01); + bytes32 constant RANDONMESS = bytes32(uint256(0x00)); + uint256 randomness2 = 0x01; + bytes32 commitment2 = commitmentFor(randomness2); + + function setUp() public { + super.setUp(); + random.testRevealAndCommit(RANDONMESS, commitment2, ACCOUNT); + } + + function test_returnsACommtiment() public { + bytes32 commitment = random.commitments(ACCOUNT); + assertEq(commitment, commitment2); + } + + function test_Reverts_WhenCalledOnL2() public { + _whenL2(); + vm.expectRevert("This method is no longer supported in L2."); + random.commitments(ACCOUNT); + } +} + +contract RandomTest_RandomnessBlockRetentionWindow is RandomTest_ { + function setUp() public { + super.setUp(); + random.setRandomnessBlockRetentionWindow(256); + } + + function test_getsTheRandomnessBlockRetentionWindow() public { + uint256 randomnessBlockRetentionWindow = random.randomnessBlockRetentionWindow(); + assertEq(randomnessBlockRetentionWindow, 256); + } + + function test_Reverts_WhenCalledOnL2() public { + _whenL2(); + vm.expectRevert("This method is no longer supported in L2."); + random.randomnessBlockRetentionWindow(); + } +}