diff --git a/packages/contracts-bedrock/interfaces/L2/ILiquidityController.sol b/packages/contracts-bedrock/interfaces/L2/ILiquidityController.sol index b20214702abb0..2039de56a67d7 100644 --- a/packages/contracts-bedrock/interfaces/L2/ILiquidityController.sol +++ b/packages/contracts-bedrock/interfaces/L2/ILiquidityController.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.0; import { ISemver } from "interfaces/universal/ISemver.sol"; interface ILiquidityController is ISemver { - error Unauthorized(); + error LiquidityController_Unauthorized(); event Initialized(uint8 version); diff --git a/packages/contracts-bedrock/interfaces/L2/INativeAssetLiquidity.sol b/packages/contracts-bedrock/interfaces/L2/INativeAssetLiquidity.sol index 003ac4d7bddce..fc343f4cba1e6 100644 --- a/packages/contracts-bedrock/interfaces/L2/INativeAssetLiquidity.sol +++ b/packages/contracts-bedrock/interfaces/L2/INativeAssetLiquidity.sol @@ -4,14 +4,12 @@ pragma solidity ^0.8.0; import { ISemver } from "interfaces/universal/ISemver.sol"; interface INativeAssetLiquidity is ISemver { - error Unauthorized(); - error InvalidAmount(); + error NativeAssetLiquidity_Unauthorized(); + error NativeAssetLiquidity_InsufficientBalance(); event LiquidityDeposited(address indexed caller, uint256 value); event LiquidityWithdrawn(address indexed caller, uint256 value); - event LiquidityFunded(address indexed funder, uint256 value); function deposit() external payable; function withdraw(uint256 _amount) external; - function fund() external payable; } diff --git a/packages/contracts-bedrock/scripts/checks/test-validation/exclusions.toml b/packages/contracts-bedrock/scripts/checks/test-validation/exclusions.toml index f6eac54cc3c92..0150b824b7c81 100644 --- a/packages/contracts-bedrock/scripts/checks/test-validation/exclusions.toml +++ b/packages/contracts-bedrock/scripts/checks/test-validation/exclusions.toml @@ -1,4 +1,4 @@ - # Test validation exclusions configuration +# Test validation exclusions configuration # This file contains lists of paths and test names that should be excluded # from various validation checks in the test validation script. @@ -56,7 +56,6 @@ contract_name_validation = [ "test/L2/GasPriceOracle.t.sol", # Contains contracts not matching GasPriceOracle base name "test/universal/StandardBridge.t.sol", # Contains contracts not matching StandardBridge base name "test/L1/OPContractsManagerContractsContainer.t.sol", # Contains contracts not matching OPContractsManagerContractsContainer base name - "test/L1/OptimismPortal2.t.sol", # Contains contracts not matching OptimismPortal2 base name ] # PATHS EXCLUDED FROM FUNCTION NAME VALIDATION: @@ -92,4 +91,5 @@ contracts = [ "OptimismPortal2_MigrateLiquidity_Test", # Interop tests hosted in the OptimismPortal2 test file "OptimismPortal2_MigrateToSuperRoots_Test", # Interop tests hosted in the OptimismPortal2 test file "OptimismPortal2_UpgradeInterop_Test", # Interop tests hosted in the OptimismPortal2 test file + "L1Block_SetCustomGasToken_Test", # Custom gas token tests hosted in the L1Block test file ] diff --git a/packages/contracts-bedrock/scripts/deploy/DeployConfig.s.sol b/packages/contracts-bedrock/scripts/deploy/DeployConfig.s.sol index 51609a693249b..241f202511dd4 100644 --- a/packages/contracts-bedrock/scripts/deploy/DeployConfig.s.sol +++ b/packages/contracts-bedrock/scripts/deploy/DeployConfig.s.sol @@ -238,6 +238,16 @@ contract DeployConfig is Script { useCustomGasToken = _useCustomGasToken; } + /// @notice Allow the `gasPayingTokenName` config to be overridden in testing environments + function setGasPayingTokenName(string memory _gasPayingTokenName) public { + gasPayingTokenName = _gasPayingTokenName; + } + + /// @notice Allow the `gasPayingTokenSymbol` config to be overridden in testing environments + function setGasPayingTokenSymbol(string memory _gasPayingTokenSymbol) public { + gasPayingTokenSymbol = _gasPayingTokenSymbol; + } + /// @notice Allow the `nativeAssetLiquidityAmount` config to be overridden in testing environments function setNativeAssetLiquidityAmount(uint256 _nativeAssetLiquidityAmount) public { nativeAssetLiquidityAmount = _nativeAssetLiquidityAmount; diff --git a/packages/contracts-bedrock/snapshots/abi/LiquidityController.json b/packages/contracts-bedrock/snapshots/abi/LiquidityController.json index e44eeb5b0f2c0..3a61fc231c183 100644 --- a/packages/contracts-bedrock/snapshots/abi/LiquidityController.json +++ b/packages/contracts-bedrock/snapshots/abi/LiquidityController.json @@ -216,7 +216,7 @@ }, { "inputs": [], - "name": "Unauthorized", + "name": "LiquidityController_Unauthorized", "type": "error" } ] \ No newline at end of file diff --git a/packages/contracts-bedrock/snapshots/abi/NativeAssetLiquidity.json b/packages/contracts-bedrock/snapshots/abi/NativeAssetLiquidity.json index 9bbeb8427231b..156ece4cc1361 100644 --- a/packages/contracts-bedrock/snapshots/abi/NativeAssetLiquidity.json +++ b/packages/contracts-bedrock/snapshots/abi/NativeAssetLiquidity.json @@ -6,13 +6,6 @@ "stateMutability": "payable", "type": "function" }, - { - "inputs": [], - "name": "fund", - "outputs": [], - "stateMutability": "payable", - "type": "function" - }, { "inputs": [], "name": "version", @@ -58,25 +51,6 @@ "name": "LiquidityDeposited", "type": "event" }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "funder", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "value", - "type": "uint256" - } - ], - "name": "LiquidityFunded", - "type": "event" - }, { "anonymous": false, "inputs": [ @@ -98,12 +72,12 @@ }, { "inputs": [], - "name": "InvalidAmount", + "name": "NativeAssetLiquidity_InsufficientBalance", "type": "error" }, { "inputs": [], - "name": "Unauthorized", + "name": "NativeAssetLiquidity_Unauthorized", "type": "error" } ] \ No newline at end of file diff --git a/packages/contracts-bedrock/snapshots/semver-lock.json b/packages/contracts-bedrock/snapshots/semver-lock.json index 2d4bd0e88a4f0..c36d9dc2044ee 100644 --- a/packages/contracts-bedrock/snapshots/semver-lock.json +++ b/packages/contracts-bedrock/snapshots/semver-lock.json @@ -96,20 +96,20 @@ "sourceCodeHash": "0xdc7bd63134eeab163a635950f2afd16b59f40f9cf1306f2ed33ad661cc7b4962" }, "src/L2/L2ToL1MessagePasserCGT.sol:L2ToL1MessagePasserCGT": { - "initCodeHash": "0xe09e6219f705bc120b604f25997610f3107daef880f33e380da7ed618b45bb6e", - "sourceCodeHash": "0x1ba0f62d5101f3541fe074a39fd67ab6a06b5b72678a4f08d08366fbe4bef764" + "initCodeHash": "0xf36eab44c41249b4d8ea95a21b70f1eae55b1a555384870c2f4ca306fa9121b6", + "sourceCodeHash": "0xec1736e67134e22ad9ceb0b8b6c116fd169637aa6729c05d9f0f4b02547aaac0" }, "src/L2/L2ToL2CrossDomainMessenger.sol:L2ToL2CrossDomainMessenger": { "initCodeHash": "0x975fd33a3a386310d54dbb01b56f3a6a8350f55a3b6bd7781e5ccc2166ddf2e6", "sourceCodeHash": "0xbea4229c5c6988243dbc7cf5a086ddd412fe1f2903b8e20d56699fec8de0c2c9" }, "src/L2/LiquidityController.sol:LiquidityController": { - "initCodeHash": "0x8a21d16da3377aa61375755d37010c0c37c99817fdce9d16f78f0ab9bc3a84c5", - "sourceCodeHash": "0xb4fca8d4532e88e0dd53d3643aa4022953e37c745753009b3c8f9bcca5806f57" + "initCodeHash": "0x19ce7a691d1f8631bfce9fea002c385c418fc69c2e9a9aa5d44ee0cf348c1026", + "sourceCodeHash": "0x87351013f5bcca917dfdd916b06b8ece6bd447acae146f004a33d88f59ce2487" }, "src/L2/NativeAssetLiquidity.sol:NativeAssetLiquidity": { - "initCodeHash": "0x2c50c7cac8eab6867ffb969a65a8aa3026d415f2e9464726683ff6cd5da0b8f3", - "sourceCodeHash": "0x9432883dd4aa4d5ffc733ad99fa7bcc9cc8c319e654b385b8cd093a37a4c94cb" + "initCodeHash": "0x04b176e5d484e54173a5644c833117c5fd9f055dce8678be9ec4cf07c0f01f00", + "sourceCodeHash": "0x79289174e875ead5a6290df9af1951d6c0ff0dc6809601e1c7a80110ceb8e945" }, "src/L2/OperatorFeeVault.sol:OperatorFeeVault": { "initCodeHash": "0x3d8c0d7736e8767f2f797da1c20c5fe30bd7f48a4cf75f376290481ad7c0f91f", diff --git a/packages/contracts-bedrock/src/L2/L2ToL1MessagePasserCGT.sol b/packages/contracts-bedrock/src/L2/L2ToL1MessagePasserCGT.sol index e23cc30007ab5..efd00314559c2 100644 --- a/packages/contracts-bedrock/src/L2/L2ToL1MessagePasserCGT.sol +++ b/packages/contracts-bedrock/src/L2/L2ToL1MessagePasserCGT.sol @@ -18,9 +18,9 @@ contract L2ToL1MessagePasserCGT is L2ToL1MessagePasser { /// @notice The error thrown when a withdrawal is initiated with value and custom gas token is used. error L2ToL1MessagePasserCGT_NotAllowedOnCGTMode(); - /// @custom:semver +custom-gas-token.1 + /// @custom:semver +custom-gas-token function version() public pure override returns (string memory) { - return string.concat(super.version(), "+custom-gas-token.1"); + return string.concat(super.version(), "+custom-gas-token"); } /// @notice Sends a message from L2 to L1. diff --git a/packages/contracts-bedrock/src/L2/LiquidityController.sol b/packages/contracts-bedrock/src/L2/LiquidityController.sol index fa92db0f984b6..571932d477a52 100644 --- a/packages/contracts-bedrock/src/L2/LiquidityController.sol +++ b/packages/contracts-bedrock/src/L2/LiquidityController.sol @@ -6,7 +6,6 @@ import { Initializable } from "@openzeppelin/contracts/proxy/utils/Initializable import { SafeSend } from "src/universal/SafeSend.sol"; // Libraries -import { Unauthorized } from "src/libraries/errors/CommonErrors.sol"; import { Predeploys } from "src/libraries/Predeploys.sol"; // Interfaces @@ -39,6 +38,9 @@ contract LiquidityController is ISemver, Initializable { /// @param amount The amount of liquidity that was burned event LiquidityBurned(address indexed minter, uint256 amount); + /// @notice Error for when an address is unauthorized to perform liquidity control operations + error LiquidityController_Unauthorized(); + /// @notice Semantic version. /// @custom:semver 1.0.0 string public constant version = "1.0.0"; @@ -67,7 +69,7 @@ contract LiquidityController is ISemver, Initializable { /// @notice Authorizes an address to perform liquidity control operations /// @param _minter The address to authorize as a minter function authorizeMinter(address _minter) external { - if (msg.sender != IProxyAdmin(Predeploys.PROXY_ADMIN).owner()) revert Unauthorized(); + if (msg.sender != IProxyAdmin(Predeploys.PROXY_ADMIN).owner()) revert LiquidityController_Unauthorized(); minters[_minter] = true; emit MinterAuthorized(_minter); } @@ -75,7 +77,7 @@ contract LiquidityController is ISemver, Initializable { /// @notice Deauthorizes an address from performing liquidity control operations /// @param _minter The address to deauthorize as a minter function deauthorizeMinter(address _minter) external { - if (msg.sender != IProxyAdmin(Predeploys.PROXY_ADMIN).owner()) revert Unauthorized(); + if (msg.sender != IProxyAdmin(Predeploys.PROXY_ADMIN).owner()) revert LiquidityController_Unauthorized(); delete minters[_minter]; emit MinterDeauthorized(_minter); } @@ -84,7 +86,7 @@ contract LiquidityController is ISemver, Initializable { /// @param _to The address to receive the minted native asset /// @param _amount The amount of native asset to mint and send function mint(address _to, uint256 _amount) external { - if (!minters[msg.sender]) revert Unauthorized(); + if (!minters[msg.sender]) revert LiquidityController_Unauthorized(); INativeAssetLiquidity(Predeploys.NATIVE_ASSET_LIQUIDITY).withdraw(_amount); // This is a forced ETH send to the recipient, the recipient should NOT expect to be called @@ -95,7 +97,7 @@ contract LiquidityController is ISemver, Initializable { /// @notice Burns native asset liquidity by sending ETH to the contract function burn() external payable { - if (!minters[msg.sender]) revert Unauthorized(); + if (!minters[msg.sender]) revert LiquidityController_Unauthorized(); INativeAssetLiquidity(Predeploys.NATIVE_ASSET_LIQUIDITY).deposit{ value: msg.value }(); emit LiquidityBurned(msg.sender, msg.value); diff --git a/packages/contracts-bedrock/src/L2/NativeAssetLiquidity.sol b/packages/contracts-bedrock/src/L2/NativeAssetLiquidity.sol index 859818ad6cfda..f0ab2bbba95b9 100644 --- a/packages/contracts-bedrock/src/L2/NativeAssetLiquidity.sol +++ b/packages/contracts-bedrock/src/L2/NativeAssetLiquidity.sol @@ -10,9 +10,6 @@ import { Predeploys } from "src/libraries/Predeploys.sol"; // Interfaces import { ISemver } from "interfaces/universal/ISemver.sol"; -// Errors -import { Unauthorized, InvalidAmount } from "src/libraries/errors/CommonErrors.sol"; - /// @custom:predeploy 0x4200000000000000000000000000000000000029 /// @title NativeAssetLiquidity /// @notice The NativeAssetLiquidity contract allows other contracts to access native asset liquidity @@ -23,8 +20,11 @@ contract NativeAssetLiquidity is ISemver { /// @notice Emitted when an address deposits native asset liquidity. event LiquidityDeposited(address indexed caller, uint256 value); - /// @notice Emitted when funds are received. - event LiquidityFunded(address indexed funder, uint256 value); + /// @notice Error for when the contract has insufficient balance. + error NativeAssetLiquidity_InsufficientBalance(); + + /// @notice Error for when an address is unauthorized to perform native asset liquidity operations + error NativeAssetLiquidity_Unauthorized(); /// @notice Semantic version. /// @custom:semver 1.0.0 @@ -32,7 +32,7 @@ contract NativeAssetLiquidity is ISemver { /// @notice Allows an address to lock native asset liquidity into this contract. function deposit() external payable { - if (msg.sender != Predeploys.LIQUIDITY_CONTROLLER) revert Unauthorized(); + if (msg.sender != Predeploys.LIQUIDITY_CONTROLLER) revert NativeAssetLiquidity_Unauthorized(); emit LiquidityDeposited(msg.sender, msg.value); } @@ -40,18 +40,12 @@ contract NativeAssetLiquidity is ISemver { /// @notice Allows an address to unlock native asset liquidity from this contract. /// @param _amount The amount of liquidity to unlock. function withdraw(uint256 _amount) external { - if (msg.sender != Predeploys.LIQUIDITY_CONTROLLER) revert Unauthorized(); + if (msg.sender != Predeploys.LIQUIDITY_CONTROLLER) revert NativeAssetLiquidity_Unauthorized(); + + if (_amount > address(this).balance) revert NativeAssetLiquidity_InsufficientBalance(); new SafeSend{ value: _amount }(payable(msg.sender)); emit LiquidityWithdrawn(msg.sender, _amount); } - - /// @notice Fund the contract by sending native asset. - /// @dev The function is payable to accept native asset. - function fund() external payable { - if (msg.value == 0) revert InvalidAmount(); - - emit LiquidityFunded(msg.sender, msg.value); - } } diff --git a/packages/contracts-bedrock/test/L1/OptimismPortal2.t.sol b/packages/contracts-bedrock/test/L1/OptimismPortal2.t.sol index 221a103760f5a..09fb9797d7547 100644 --- a/packages/contracts-bedrock/test/L1/OptimismPortal2.t.sol +++ b/packages/contracts-bedrock/test/L1/OptimismPortal2.t.sol @@ -49,8 +49,8 @@ contract OptimismPortal2_TestInit is DisputeGameFactory_TestInit { Types.OutputRootProof internal _outputRootProof; GameType internal respectedGameType; - /// @dev Setup the system for a ready-to-use state. - function setUp() public virtual override { + // Use a constructor to set the storage vars above, so as to minimize the number of ffi calls. + constructor() { super.setUp(); _defaultTx = Types.WithdrawalTransaction({ @@ -77,7 +77,10 @@ contract OptimismPortal2_TestInit is DisputeGameFactory_TestInit { messagePasserStorageRoot: _storageRoot, latestBlockhash: bytes32(uint256(0)) }); + } + /// @dev Setup the system for a ready-to-use state. + function setUp() public virtual override { if (isForkTest()) { // Set the proposed block number to be the next block number on the forked network (, _proposedBlockNumber) = anchorStateRegistry.getAnchorRoot(); @@ -716,18 +719,15 @@ contract OptimismPortal2_Receive_Test is OptimismPortal2_TestInit { } /// @notice Tests that `receive` reverts when custom gas token is enabled - function testFuzz_receive_customGasToken_reverts(uint256 _value) external virtual { + function testFuzz_receive_customGasToken_reverts(uint256 _value) external { skipIfDevFeatureDisabled(DevFeatures.CUSTOM_GAS_TOKEN); _value = bound(_value, 1, type(uint128).max); vm.deal(alice, _value); - address portal = address(optimismPortal2); - vm.prank(alice); vm.expectRevert(IOptimismPortal.OptimismPortal_NotAllowedOnCGTMode.selector); - assembly { - pop(call(gas(), portal, _value, 0, 0, 0, 0)) - } + (bool revertsAsExpected,) = address(optimismPortal2).call{ value: _value }(hex""); + assertTrue(revertsAsExpected, "expectRevert: call did not revert"); } } @@ -830,7 +830,7 @@ contract OptimismPortal2_MigrateLiquidity_Test is CommonTest { /// @title OptimismPortal2_MigrateToSuperRoots_Test /// @notice Test contract for OptimismPortal2 `migrateToSuperRoots` function. contract OptimismPortal2_MigrateToSuperRoots_Test is OptimismPortal2_TestInit { - function setUp() public virtual override { + function setUp() public override { super.setUp(); skipIfDevFeatureDisabled(DevFeatures.OPTIMISM_PORTAL_INTEROP); } @@ -1429,7 +1429,7 @@ contract OptimismPortal2_ProveWithdrawalTransaction_Test is OptimismPortal2_Test contract OptimismPortal2_FinalizeWithdrawalTransaction_Test is OptimismPortal2_TestInit { /// @notice Tests that `finalizeWithdrawalTransaction` reverts when the target is the portal /// contract or the lockbox. - function test_finalizeWithdrawalTransaction_badTarget_reverts() external virtual { + function test_finalizeWithdrawalTransaction_badTarget_reverts() external { _defaultTx.target = address(optimismPortal2); vm.expectRevert(IOptimismPortal.OptimismPortal_BadTarget.selector); optimismPortal2.finalizeWithdrawalTransaction(_defaultTx); @@ -1932,7 +1932,6 @@ contract OptimismPortal2_FinalizeWithdrawalTransaction_Test is OptimismPortal2_T bytes memory _data ) external - virtual { skipIfForkTest("Skipping on forked tests because of the L2ToL1MessageParser call below"); if (isUsingCustomGasToken()) { @@ -2017,7 +2016,6 @@ contract OptimismPortal2_FinalizeWithdrawalTransaction_Test is OptimismPortal2_T GameType _newGameType ) external - virtual { skipIfForkTest("Skipping on forked tests because of the L2ToL1MessageParser call below"); if (isUsingCustomGasToken()) { @@ -2565,7 +2563,6 @@ contract OptimismPortal2_DepositTransaction_Test is OptimismPortal2_TestInit { bytes memory _data ) external - virtual { // Prevent overflow on an upgrade context if (isUsingLockbox()) { @@ -2636,7 +2633,6 @@ contract OptimismPortal2_DepositTransaction_Test is OptimismPortal2_TestInit { address _7702Target ) external - virtual { assumeNotForgeAddress(_7702Target); @@ -2703,7 +2699,6 @@ contract OptimismPortal2_DepositTransaction_Test is OptimismPortal2_TestInit { bytes memory _data ) external - virtual { // Prevent overflow on an upgrade context _mint = bound(_mint, 0, type(uint256).max - address(ethLockbox).balance); diff --git a/packages/contracts-bedrock/test/L2/BaseFeeVault.t.sol b/packages/contracts-bedrock/test/L2/BaseFeeVault.t.sol index ce1a0fe77d35b..1a2019cf061ff 100644 --- a/packages/contracts-bedrock/test/L2/BaseFeeVault.t.sol +++ b/packages/contracts-bedrock/test/L2/BaseFeeVault.t.sol @@ -4,9 +4,6 @@ pragma solidity 0.8.15; // Testing utilities import { CommonTest } from "test/setup/CommonTest.sol"; -// Libraries -import { Types } from "src/libraries/Types.sol"; - /// @title BaseFeeVault_Constructor_Test /// @notice Tests the `constructor` of the `BaseFeeVault` contract. contract BaseFeeVault_Constructor_Test is CommonTest { @@ -16,7 +13,7 @@ contract BaseFeeVault_Constructor_Test is CommonTest { assertEq(baseFeeVault.recipient(), deploy.cfg().baseFeeVaultRecipient()); assertEq(baseFeeVault.MIN_WITHDRAWAL_AMOUNT(), deploy.cfg().baseFeeVaultMinimumWithdrawalAmount()); assertEq(baseFeeVault.minWithdrawalAmount(), deploy.cfg().baseFeeVaultMinimumWithdrawalAmount()); - assertEq(uint8(baseFeeVault.WITHDRAWAL_NETWORK()), uint8(Types.WithdrawalNetwork.L1)); - assertEq(uint8(baseFeeVault.withdrawalNetwork()), uint8(Types.WithdrawalNetwork.L1)); + assertEq(uint8(baseFeeVault.WITHDRAWAL_NETWORK()), deploy.cfg().baseFeeVaultWithdrawalNetwork()); + assertEq(uint8(baseFeeVault.withdrawalNetwork()), deploy.cfg().baseFeeVaultWithdrawalNetwork()); } } diff --git a/packages/contracts-bedrock/test/L2/L1Block.t.sol b/packages/contracts-bedrock/test/L2/L1Block.t.sol index 80c347a9f77f5..b46df4bae4d8d 100644 --- a/packages/contracts-bedrock/test/L2/L1Block.t.sol +++ b/packages/contracts-bedrock/test/L2/L1Block.t.sol @@ -3,11 +3,16 @@ pragma solidity 0.8.15; // Testing import { CommonTest } from "test/setup/CommonTest.sol"; +import { stdStorage, StdStorage } from "forge-std/Test.sol"; // Libraries import { Encoding } from "src/libraries/Encoding.sol"; import { Constants } from "src/libraries/Constants.sol"; import "src/libraries/L1BlockErrors.sol"; +import { DevFeatures } from "src/libraries/DevFeatures.sol"; + +// Interfaces +import { IL1BlockCGT } from "interfaces/L2/IL1BlockCGT.sol"; /// @title L1Block_ TestInit /// @notice Reusable test initialization for `L1Block` tests. @@ -36,29 +41,53 @@ contract L1Block_Version_Test is L1Block_TestInit { contract L1Block_GasPayingToken_Test is L1Block_TestInit { /// @notice Tests that the `gasPayingToken` function returns the correct token address and /// decimals. - function test_gasPayingToken_succeeds() external view { + function test_gasPayingToken_succeeds() external { + skipIfDevFeatureEnabled(DevFeatures.CUSTOM_GAS_TOKEN); (address token, uint8 decimals) = l1Block.gasPayingToken(); assertEq(token, Constants.ETHER); assertEq(uint256(decimals), uint256(18)); } + + /// @notice Tests that the `gasPayingToken` function reverts when custom gas token is enabled. + function test_gasPayingToken_customGasToken_reverts() external { + skipIfDevFeatureDisabled(DevFeatures.CUSTOM_GAS_TOKEN); + vm.expectRevert("L1BlockCGT: deprecated"); + l1Block.gasPayingToken(); + } } /// @title L1Block_GasPayingTokenName_Test /// @notice Tests the `gasPayingTokenName` function of the `L1Block` contract. contract L1Block_GasPayingTokenName_Test is L1Block_TestInit { /// @notice Tests that the `gasPayingTokenName` function returns the correct token name. - function test_gasPayingTokenName_succeeds() external view { + function test_gasPayingTokenName_succeeds() external { + skipIfDevFeatureEnabled(DevFeatures.CUSTOM_GAS_TOKEN); assertEq("Ether", l1Block.gasPayingTokenName()); } + + /// @notice Tests that the `gasPayingTokenName` function returns the correct token name when custom gas token is + /// enabled. + function test_gasPayingTokenName_customGasToken_succeeds() external { + skipIfDevFeatureDisabled(DevFeatures.CUSTOM_GAS_TOKEN); + assertEq(liquidityController.gasPayingTokenName(), l1Block.gasPayingTokenName()); + } } /// @title L1Block_GasPayingTokenSymbol_Test /// @notice Tests the `gasPayingTokenSymbol` function of the `L1Block` contract. contract L1Block_GasPayingTokenSymbol_Test is L1Block_TestInit { /// @notice Tests that the `gasPayingTokenSymbol` function returns the correct token symbol. - function test_gasPayingTokenSymbol_succeeds() external view { + function test_gasPayingTokenSymbol_succeeds() external { + skipIfDevFeatureEnabled(DevFeatures.CUSTOM_GAS_TOKEN); assertEq("ETH", l1Block.gasPayingTokenSymbol()); } + + /// @notice Tests that the `gasPayingTokenSymbol` function returns the correct token symbol when custom gas token is + /// enabled. + function test_gasPayingTokenSymbol_customGasToken_succeeds() external { + skipIfDevFeatureDisabled(DevFeatures.CUSTOM_GAS_TOKEN); + assertEq(liquidityController.gasPayingTokenSymbol(), l1Block.gasPayingTokenSymbol()); + } } /// @title L1Block_IsCustomGasToken_Test @@ -66,9 +95,17 @@ contract L1Block_GasPayingTokenSymbol_Test is L1Block_TestInit { contract L1Block_IsCustomGasToken_Test is L1Block_TestInit { /// @notice Tests that the `isCustomGasToken` function returns false when no custom gas token /// is used. - function test_isCustomGasToken_succeeds() external view { + function test_isCustomGasToken_succeeds() external { + skipIfDevFeatureEnabled(DevFeatures.CUSTOM_GAS_TOKEN); assertFalse(l1Block.isCustomGasToken()); } + + /// @notice Tests that the `isCustomGasToken` function returns true when custom gas token + /// is used. + function test_isCustomGasToken_customGasToken_succeeds() external { + skipIfDevFeatureDisabled(DevFeatures.CUSTOM_GAS_TOKEN); + assertTrue(l1Block.isCustomGasToken()); + } } /// @title L1Block_SetL1BlockValues_Test @@ -325,3 +362,48 @@ contract L1Block_SetL1BlockValuesIsthmus_Test is L1Block_TestInit { assertEq(data, expReturn); } } + +/// @title L1Block_SetCustomGasToken_Test +/// @notice Tests the `setCustomGasToken` function of the `L1Block` contract. +contract L1Block_SetCustomGasToken_Test is L1Block_TestInit { + using stdStorage for StdStorage; + + IL1BlockCGT l1BlockCGT; + + function setUp() public override { + super.setUp(); + skipIfDevFeatureDisabled(DevFeatures.CUSTOM_GAS_TOKEN); + l1BlockCGT = IL1BlockCGT(address(l1Block)); + } + + /// @notice Tests that `setCustomGasToken` reverts if called twice. + function test_setCustomGasToken_alreadyActive_reverts() external { + // This test uses the setUp that already activates custom gas token + assertTrue(l1BlockCGT.isCustomGasToken()); + + vm.expectRevert("L1Block: CustomGasToken already active"); + vm.prank(depositor); + IL1BlockCGT(address(l1BlockCGT)).setCustomGasToken(); + } + + /// @notice Tests that `setCustomGasToken` updates the flag correctly when called by depositor. + function test_setCustomGasToken_succeeds() external { + stdstore.target(address(l1BlockCGT)).sig("isCustomGasToken()").checked_write(false); + // This test uses the setUp that already activates custom gas token + assertFalse(l1BlockCGT.isCustomGasToken()); + + vm.prank(depositor); + l1BlockCGT.setCustomGasToken(); + + assertTrue(l1BlockCGT.isCustomGasToken()); + } + + /// @notice Tests that `setCustomGasToken` reverts if sender address is not the depositor. + function test_setCustomGasToken_notDepositor_reverts(address nonDepositor) external { + stdstore.target(address(l1BlockCGT)).sig("isCustomGasToken()").checked_write(false); + vm.assume(nonDepositor != depositor); + vm.expectRevert("L1Block: only the depositor account can set isCustomGasToken flag"); + vm.prank(nonDepositor); + l1BlockCGT.setCustomGasToken(); + } +} diff --git a/packages/contracts-bedrock/test/L2/L1BlockCGT.t.sol b/packages/contracts-bedrock/test/L2/L1BlockCGT.t.sol deleted file mode 100644 index cd9e3e6185380..0000000000000 --- a/packages/contracts-bedrock/test/L2/L1BlockCGT.t.sol +++ /dev/null @@ -1,156 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity 0.8.15; - -// Testing -import { CommonTest } from "test/setup/CommonTest.sol"; -import { - L1Block_SetL1BlockValues_Test, - L1Block_SetL1BlockValuesEcotone_Test, - L1Block_SetL1BlockValuesIsthmus_Test -} from "test/L2/L1Block.t.sol"; -import { stdStorage, StdStorage } from "forge-std/Test.sol"; - -// Libraries -import "src/libraries/L1BlockErrors.sol"; - -// Interfaces -import { IL1BlockCGT } from "interfaces/L2/IL1BlockCGT.sol"; - -/// @title L1BlockCGT_TestInit -/// @notice Reusable test initialization for `L1Block` tests with custom gas token enabled. -contract L1BlockCGT_TestInit is CommonTest { - address depositor; - IL1BlockCGT l1BlockCGT; - - /// @notice Sets up the test suite. - function setUp() public virtual override { - super.enableCustomGasToken(); - super.setUp(); - l1BlockCGT = IL1BlockCGT(address(l1Block)); - depositor = l1BlockCGT.DEPOSITOR_ACCOUNT(); - } -} - -/// @title L1BlockCGT_Version_Test -/// @notice Test contract for L1BlockCGT `version` function. -contract L1BlockCGT_Version_Test is L1BlockCGT_TestInit { - /// @notice Tests that the version function returns a valid string. We avoid testing the - /// specific value of the string as it changes frequently. - function test_version_succeeds() external view { - assert(bytes(l1BlockCGT.version()).length > 0); - } -} - -/// @title L1BlockCGT_GasPayingToken_Test -/// @notice Tests the `gasPayingToken` function of the `L1BlockCGT` contract. -contract L1BlockCGT_GasPayingToken_Test is L1BlockCGT_TestInit { - /// @notice Tests that the `gasPayingToken` function reverts. - function test_gasPayingToken_deprecated_reverts() external { - vm.expectRevert("L1BlockCGT: deprecated"); - l1BlockCGT.gasPayingToken(); - } -} - -/// @title L1BlockCGT_GasPayingTokenName_Test -/// @notice Tests the `gasPayingTokenName` function of the `L1Block` contract with custom gas -/// token enabled. -contract L1BlockCGT_GasPayingTokenName_Test is L1BlockCGT_TestInit { - /// @notice Tests that the `gasPayingTokenName` function returns the correct token name. - function test_gasPayingTokenName_succeeds() external view { - assertEq(liquidityController.gasPayingTokenName(), l1BlockCGT.gasPayingTokenName()); - } -} - -/// @title L1BlockCGT_GasPayingTokenSymbol_Test -/// @notice Tests the `gasPayingTokenSymbol` function of the `L1Block` contract with custom gas -/// token enabled. -contract L1BlockCGT_GasPayingTokenSymbol_Test is L1BlockCGT_TestInit { - /// @notice Tests that the `gasPayingTokenSymbol` function returns the correct token symbol. - function test_gasPayingTokenSymbol_succeeds() external view { - assertEq(liquidityController.gasPayingTokenSymbol(), l1BlockCGT.gasPayingTokenSymbol()); - } -} - -/// @title L1BlockCGT_IsCustomGasToken_Test -/// @notice Tests the `isCustomGasToken` function of the `L1Block` contract with custom gas token -/// enabled. -contract L1BlockCGT_IsCustomGasToken_Test is L1BlockCGT_TestInit { - /// @notice Tests that the `isCustomGasToken` function returns false when no custom gas token - /// is used. - function test_isCustomGasToken_succeeds() external view { - assertTrue(l1BlockCGT.isCustomGasToken()); - } -} - -/// @title L1BlockCGT_SetL1BlockValues_Test -/// @notice Tests the `setL1BlockValues` function of the `L1Block` contract with custom gas token -/// enabled. -contract L1BlockCGT_SetL1BlockValues_Test is L1Block_SetL1BlockValues_Test { - // Override setUp to enable custom gas token - // Re-use the test from L1Block.t.sol - function setUp() public override { - super.enableCustomGasToken(); - super.setUp(); - } -} - -/// @title L1BlockCGT_SetL1BlockValuesEcotone_Test -/// @notice Tests the `setL1BlockValuesEcotone` function of the `L1Block` contract with custom gas -/// token enabled. -contract L1BlockCGT_SetL1BlockValuesEcotone_Test is L1Block_SetL1BlockValuesEcotone_Test { - // Override setUp to enable custom gas token - // Re-use the test from L1Block.t.sol - function setUp() public override { - super.enableCustomGasToken(); - super.setUp(); - } -} - -/// @title L1BlockCGTSetL1BlockValuesIsthmus_Test -/// @notice Tests the `setL1BlockValuesIsthmus` function of the `L1Block` contract with custom gas -/// token enabled. -contract L1BlockCGT_SetL1BlockValuesIsthmus_Test is L1Block_SetL1BlockValuesIsthmus_Test { - // Override setUp to enable custom gas token - // Re-use the test from L1Block.t.sol - function setUp() public override { - super.enableCustomGasToken(); - super.setUp(); - } -} - -/// @title L1BlockCGT_SetCustomGasToken_Test -/// @notice Tests the `setCustomGasToken` function of the `L1Block` contract. -contract L1BlockCGT_SetCustomGasToken_Test is L1BlockCGT_TestInit { - using stdStorage for StdStorage; - - /// @notice Tests that `setCustomGasToken` reverts if called twice. - function test_setCustomGasToken_alreadyActive_reverts() external { - // This test uses the setUp that already activates custom gas token - assertTrue(l1BlockCGT.isCustomGasToken()); - - vm.expectRevert("L1Block: CustomGasToken already active"); - vm.prank(depositor); - IL1BlockCGT(address(l1BlockCGT)).setCustomGasToken(); - } - - /// @notice Tests that `setCustomGasToken` updates the flag correctly when called by depositor. - function test_setCustomGasToken_succeeds() external { - stdstore.target(address(l1BlockCGT)).sig("isCustomGasToken()").checked_write(false); - // This test uses the setUp that already activates custom gas token - assertFalse(l1BlockCGT.isCustomGasToken()); - - vm.prank(depositor); - l1BlockCGT.setCustomGasToken(); - - assertTrue(l1BlockCGT.isCustomGasToken()); - } - - /// @notice Tests that `setCustomGasToken` reverts if sender address is not the depositor. - function test_setCustomGasToken_notDepositor_reverts(address nonDepositor) external { - stdstore.target(address(l1BlockCGT)).sig("isCustomGasToken()").checked_write(false); - vm.assume(nonDepositor != depositor); - vm.expectRevert("L1Block: only the depositor account can set isCustomGasToken flag"); - vm.prank(nonDepositor); - l1BlockCGT.setCustomGasToken(); - } -} diff --git a/packages/contracts-bedrock/test/L2/L1FeeVault.t.sol b/packages/contracts-bedrock/test/L2/L1FeeVault.t.sol index f61eb99927db7..b98774339d615 100644 --- a/packages/contracts-bedrock/test/L2/L1FeeVault.t.sol +++ b/packages/contracts-bedrock/test/L2/L1FeeVault.t.sol @@ -4,9 +4,6 @@ pragma solidity 0.8.15; // Testing utilities import { CommonTest } from "test/setup/CommonTest.sol"; -// Libraries -import { Types } from "src/libraries/Types.sol"; - /// @title L1FeeVault_Constructor_Test /// @notice Tests the `constructor` of the `L1FeeVault` contract. contract L1FeeVault_Constructor_Test is CommonTest { @@ -16,7 +13,7 @@ contract L1FeeVault_Constructor_Test is CommonTest { assertEq(l1FeeVault.recipient(), deploy.cfg().l1FeeVaultRecipient()); assertEq(l1FeeVault.MIN_WITHDRAWAL_AMOUNT(), deploy.cfg().l1FeeVaultMinimumWithdrawalAmount()); assertEq(l1FeeVault.minWithdrawalAmount(), deploy.cfg().l1FeeVaultMinimumWithdrawalAmount()); - assertEq(uint8(l1FeeVault.WITHDRAWAL_NETWORK()), uint8(Types.WithdrawalNetwork.L1)); - assertEq(uint8(l1FeeVault.withdrawalNetwork()), uint8(Types.WithdrawalNetwork.L1)); + assertEq(uint8(l1FeeVault.WITHDRAWAL_NETWORK()), deploy.cfg().l1FeeVaultWithdrawalNetwork()); + assertEq(uint8(l1FeeVault.withdrawalNetwork()), deploy.cfg().l1FeeVaultWithdrawalNetwork()); } } diff --git a/packages/contracts-bedrock/test/L2/L2StandardBridge.t.sol b/packages/contracts-bedrock/test/L2/L2StandardBridge.t.sol index b7aedc1ac6713..51bdd1227f21f 100644 --- a/packages/contracts-bedrock/test/L2/L2StandardBridge.t.sol +++ b/packages/contracts-bedrock/test/L2/L2StandardBridge.t.sol @@ -14,6 +14,7 @@ import { OptimismMintableERC20 } from "src/universal/OptimismMintableERC20.sol"; import { Predeploys } from "src/libraries/Predeploys.sol"; import { Hashing } from "src/libraries/Hashing.sol"; import { Types } from "src/libraries/Types.sol"; +import { DevFeatures } from "src/libraries/DevFeatures.sol"; // Interfaces import { ICrossDomainMessenger } from "interfaces/universal/ICrossDomainMessenger.sol"; @@ -231,6 +232,7 @@ contract L2StandardBridge_Initialize_Test is L2StandardBridge_TestInit { contract L2StandardBridge_Receive_Test is L2StandardBridge_TestInit { /// @notice Tests that the bridge receives ETH and successfully initiates a withdrawal. function test_receive_succeeds() external { + skipIfDevFeatureEnabled(DevFeatures.CUSTOM_GAS_TOKEN); assertEq(address(l2ToL1MessagePasser).balance, 0); uint256 nonce = l2CrossDomainMessenger.messageNonce(); @@ -323,6 +325,7 @@ contract L2StandardBridge_Withdraw_Test is L2StandardBridge_TestInit { /// @notice Tests that the legacy `withdraw` interface on the L2StandardBridge sucessfully /// initiates a withdrawal. function test_withdraw_ether_succeeds() external { + skipIfDevFeatureEnabled(DevFeatures.CUSTOM_GAS_TOKEN); assertTrue(alice.balance >= 100); assertEq(Predeploys.L2_TO_L1_MESSAGE_PASSER.balance, 0); @@ -465,6 +468,7 @@ contract L2StandardBridge_Unclassified_Test is L2StandardBridge_TestInit { /// @notice Tests that bridging ETH succeeds. function testFuzz_bridgeETH_succeeds(uint256 _value, uint32 _minGasLimit, bytes calldata _extraData) external { + skipIfDevFeatureEnabled(DevFeatures.CUSTOM_GAS_TOKEN); uint256 nonce = l2CrossDomainMessenger.messageNonce(); bytes memory message = abi.encodeCall(IStandardBridge.finalizeBridgeETH, (alice, alice, _value, _extraData)); @@ -498,6 +502,7 @@ contract L2StandardBridge_Unclassified_Test is L2StandardBridge_TestInit { /// @notice Tests that bridging ETH to a different address succeeds. function testFuzz_bridgeETHTo_succeeds(uint256 _value, uint32 _minGasLimit, bytes calldata _extraData) external { + skipIfDevFeatureEnabled(DevFeatures.CUSTOM_GAS_TOKEN); uint256 nonce = l2CrossDomainMessenger.messageNonce(); vm.expectCall( diff --git a/packages/contracts-bedrock/test/L2/L2ToL1MessagePasser.t.sol b/packages/contracts-bedrock/test/L2/L2ToL1MessagePasser.t.sol index b96c031661981..c4c911a4937b3 100644 --- a/packages/contracts-bedrock/test/L2/L2ToL1MessagePasser.t.sol +++ b/packages/contracts-bedrock/test/L2/L2ToL1MessagePasser.t.sol @@ -7,6 +7,10 @@ import { CommonTest } from "test/setup/CommonTest.sol"; // Libraries import { Types } from "src/libraries/Types.sol"; import { Hashing } from "src/libraries/Hashing.sol"; +import { DevFeatures } from "src/libraries/DevFeatures.sol"; + +// Interfaces +import { IL2ToL1MessagePasserCGT } from "interfaces/L2/IL2ToL1MessagePasserCGT.sol"; /// @title L2ToL1MessagePasser_Version_Test /// @notice Tests the `version` function of the `L2ToL1MessagePasser` contract. @@ -32,6 +36,9 @@ contract L2ToL1MessagePasser_InitiateWithdrawal_Test is CommonTest { ) external { + if (isDevFeatureEnabled(DevFeatures.CUSTOM_GAS_TOKEN)) { + _value = 0; + } uint256 nonce = l2ToL1MessagePasser.messageNonce(); bytes32 withdrawalHash = Hashing.hashWithdrawal( @@ -69,6 +76,7 @@ contract L2ToL1MessagePasser_InitiateWithdrawal_Test is CommonTest { ) external { + skipIfDevFeatureEnabled(DevFeatures.CUSTOM_GAS_TOKEN); bytes32 withdrawalHash = Hashing.hashWithdrawal( Types.WithdrawalTransaction({ nonce: l2ToL1MessagePasser.messageNonce(), @@ -99,6 +107,7 @@ contract L2ToL1MessagePasser_InitiateWithdrawal_Test is CommonTest { ) external { + skipIfDevFeatureEnabled(DevFeatures.CUSTOM_GAS_TOKEN); uint256 nonce = l2ToL1MessagePasser.messageNonce(); // EOA emulation @@ -117,6 +126,25 @@ contract L2ToL1MessagePasser_InitiateWithdrawal_Test is CommonTest { // the nonce increments assertEq(nonce + 1, l2ToL1MessagePasser.messageNonce()); } + + /// @notice Tests that `initiateWithdrawal` fails when called with value and custom gas token + /// is enabled. + function testFuzz_initiateWithdrawal_withValueAndCustomGasToken_fails( + address _randomAddress, + uint256 _value + ) + external + { + skipIfDevFeatureDisabled(DevFeatures.CUSTOM_GAS_TOKEN); + // Set initial state + _value = bound(_value, 1, type(uint256).max); + vm.deal(_randomAddress, _value); + + // Expect revert with NotAllowedOnCGTMode + vm.prank(_randomAddress); + vm.expectRevert(IL2ToL1MessagePasserCGT.L2ToL1MessagePasserCGT_NotAllowedOnCGTMode.selector); + l2ToL1MessagePasser.initiateWithdrawal{ value: _value }({ _target: address(0), _gasLimit: 1, _data: "" }); + } } /// @title L2ToL1MessagePasser_Burn_Test @@ -124,6 +152,7 @@ contract L2ToL1MessagePasser_InitiateWithdrawal_Test is CommonTest { contract L2ToL1MessagePasser_Burn_Test is CommonTest { /// @notice Tests that `burn` succeeds and destroys the ETH held in the contract. function testFuzz_burn_succeeds(uint256 _value, address _target, uint256 _gasLimit, bytes memory _data) external { + skipIfDevFeatureEnabled(DevFeatures.CUSTOM_GAS_TOKEN); vm.deal(address(this), _value); l2ToL1MessagePasser.initiateWithdrawal{ value: _value }({ _target: _target, _gasLimit: _gasLimit, _data: _data }); diff --git a/packages/contracts-bedrock/test/L2/L2ToL1MessagePasserCGT.t.sol b/packages/contracts-bedrock/test/L2/L2ToL1MessagePasserCGT.t.sol deleted file mode 100644 index 4b52ce85760bc..0000000000000 --- a/packages/contracts-bedrock/test/L2/L2ToL1MessagePasserCGT.t.sol +++ /dev/null @@ -1,87 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity 0.8.15; - -// Testing utilities -import { CommonTest } from "test/setup/CommonTest.sol"; - -// Libraries -import { Types } from "src/libraries/Types.sol"; -import { Hashing } from "src/libraries/Hashing.sol"; - -// Interfaces -import { IL2ToL1MessagePasserCGT } from "interfaces/L2/IL2ToL1MessagePasserCGT.sol"; - -/// @title L2ToL1MessagePasserCGT_TestInit -/// @notice Tests the `L2ToL1MessagePasser` contract with a custom gas token enabled. -contract L2ToL1MessagePasserCGT_TestInit is CommonTest { - /// @notice Sets up the test suite with custom gas token enabled. - function setUp() public override { - super.enableCustomGasToken(); - super.setUp(); - } -} - -/// @title L2ToL1MessagePasserCGT_Version_Test -/// @notice Tests the `version` function of the `L2ToL1MessagePasser` contract with custom gas token -/// enabled. -contract L2ToL1MessagePasserCGT_Version_Test is L2ToL1MessagePasserCGT_TestInit { - /// @notice Tests that the `version` function returns the correct string. We avoid testing the - /// specific value of the string as it changes frequently. - function test_version_succeeds() external view { - assert(bytes(l2ToL1MessagePasser.version()).length > 0); - } -} - -/// @title L2ToL1MessagePasserCGT_InitiateWithdrawal_Test -/// @notice Tests the `initiateWithdrawal` function of the `L2ToL1MessagePasser` contract with -/// custom gas token enabled. -contract L2ToL1MessagePasserCGT_InitiateWithdrawal_Test is L2ToL1MessagePasserCGT_TestInit { - /// @notice Tests that `initiateWithdrawal` succeeds and correctly sets the state of the - /// message passer for the withdrawal hash. - function testFuzz_initiateWithdrawal_withZeroValue_succeeds( - address _sender, - address _target, - uint256 _gasLimit, - bytes memory _data - ) - external - { - uint256 nonce = l2ToL1MessagePasser.messageNonce(); - - bytes32 withdrawalHash = Hashing.hashWithdrawal( - Types.WithdrawalTransaction({ - nonce: nonce, - sender: _sender, - target: _target, - value: 0, - gasLimit: _gasLimit, - data: _data - }) - ); - - vm.expectEmit(address(l2ToL1MessagePasser)); - emit MessagePassed(nonce, _sender, _target, 0, _gasLimit, _data, withdrawalHash); - - vm.prank(_sender); - l2ToL1MessagePasser.initiateWithdrawal{ value: 0 }(_target, _gasLimit, _data); - - assertEq(l2ToL1MessagePasser.sentMessages(withdrawalHash), true); - - bytes32 slot = keccak256(bytes.concat(withdrawalHash, bytes32(0))); - - assertEq(vm.load(address(l2ToL1MessagePasser), slot), bytes32(uint256(1))); - } - - /// @notice Tests that `initiateWithdrawal` fails when called with value and custom gas token - /// is enabled. - function testFuzz_initiateWithdrawal_withValue_fails(address _randomAddress, uint256 _value) external { - // Set initial state - _value = bound(_value, 1, type(uint256).max); - vm.deal(_randomAddress, _value); - - // Expect revert with NotAllowedOnCGTMode - vm.prank(_randomAddress); - vm.expectRevert(IL2ToL1MessagePasserCGT.L2ToL1MessagePasserCGT_NotAllowedOnCGTMode.selector); - l2ToL1MessagePasser.initiateWithdrawal{ value: _value }({ _target: address(0), _gasLimit: 1, _data: "" }); - } -} diff --git a/packages/contracts-bedrock/test/L2/LiquidityController.t.sol b/packages/contracts-bedrock/test/L2/LiquidityController.t.sol index 77cec8b5e3c11..43704367d04bb 100644 --- a/packages/contracts-bedrock/test/L2/LiquidityController.t.sol +++ b/packages/contracts-bedrock/test/L2/LiquidityController.t.sol @@ -5,14 +5,13 @@ pragma solidity 0.8.15; import { CommonTest } from "test/setup/CommonTest.sol"; import { stdStorage, StdStorage } from "forge-std/Test.sol"; -// Error imports -import { Unauthorized } from "src/libraries/errors/CommonErrors.sol"; - // Libraries import { Predeploys } from "src/libraries/Predeploys.sol"; +import { DevFeatures } from "src/libraries/DevFeatures.sol"; // Contracts import { LiquidityController } from "src/L2/LiquidityController.sol"; +import { NativeAssetLiquidity } from "src/L2/NativeAssetLiquidity.sol"; // Interfaces import { IProxyAdmin } from "interfaces/universal/IProxyAdmin.sol"; @@ -42,23 +41,43 @@ contract LiquidityController_TestInit is CommonTest { /// @notice Test setup. function setUp() public virtual override { - enableCustomGasToken(); super.setUp(); + skipIfDevFeatureDisabled(DevFeatures.CUSTOM_GAS_TOKEN); } - /// @notice Tests that contract is set up correctly. - function test_setup_succeeds() public view { - assertEq(liquidityController.version(), "1.0.0"); - assertEq(liquidityController.gasPayingTokenName(), "Custom Gas Token"); - assertEq(liquidityController.gasPayingTokenSymbol(), "CGT"); - } - - /// @notice Shared modifier to authorize a minter. - modifier isAuthorizedMinter(address _minter) { + /// @notice Helper function to authorize a minter. + function _authorizeMinter(address _minter) internal { // Authorize the minter stdstore.target(address(liquidityController)).sig(liquidityController.minters.selector).with_key(_minter) .checked_write(true); - _; + } +} + +/// @title LiquidityController_Version_Test +/// @notice Tests the `version` function of the `LiquidityController` contract. +contract LiquidityController_Version_Test is LiquidityController_TestInit { + /// @notice Tests that the version function returns a valid string. + function test_version_succeeds() public view { + assert(bytes(liquidityController.version()).length > 0); + } +} + +/// @title LiquidityController_GasPayingTokenName_Test +/// @notice Tests the `gasPayingTokenName` function of the `LiquidityController` contract. +contract LiquidityController_GasPayingTokenName_Test is LiquidityController_TestInit { + /// @notice Tests that the `version` function returns the correct string. We avoid testing the + /// specific value of the string as it changes frequently. + function test_gasPayingTokenName_succeeds() public view { + assertTrue(bytes(liquidityController.gasPayingTokenName()).length > 0); + } +} + +/// @title LiquidityController_GasPayingTokenSymbol_Test +/// @notice Tests the `gasPayingTokenSymbol` function of the `LiquidityController` contract. +contract LiquidityController_GasPayingTokenSymbol_Test is LiquidityController_TestInit { + /// @notice Tests that the gasPayingTokenSymbol function returns a valid string. + function test_gasPayingTokenSymbol_succeeds() public view { + assertTrue(bytes(liquidityController.gasPayingTokenSymbol()).length > 0); } } @@ -84,7 +103,7 @@ contract LiquidityController_AuthorizeMinter_Test is LiquidityController_TestIni // Call the authorizeMinter function with non-owner as the caller vm.prank(_caller); - vm.expectRevert(Unauthorized.selector); + vm.expectRevert(LiquidityController.LiquidityController_Unauthorized.selector); liquidityController.authorizeMinter(_minter); // Assert minter is not authorized @@ -124,7 +143,7 @@ contract LiquidityController_DeauthorizeMinter_Test is LiquidityController_TestI // Call the deauthorizeMinter function with non-owner as the caller vm.prank(_caller); - vm.expectRevert(Unauthorized.selector); + vm.expectRevert(LiquidityController.LiquidityController_Unauthorized.selector); liquidityController.deauthorizeMinter(_minter); // Assert minter is still authorized @@ -138,13 +157,8 @@ contract LiquidityController_Mint_Test is LiquidityController_TestInit { address authorizedMinter = makeAddr("authorizedMinter"); /// @notice Tests that the mint function can be called by an authorized minter. - function testFuzz_mint_fromAuthorizedMinter_succeeds( - address _to, - uint256 _amount - ) - public - isAuthorizedMinter(authorizedMinter) - { + function testFuzz_mint_fromAuthorizedMinter_succeeds(address _to, uint256 _amount) public { + _authorizeMinter(authorizedMinter); vm.assume(_to != address(nativeAssetLiquidity)); _amount = bound(_amount, 1, address(nativeAssetLiquidity).balance); @@ -175,7 +189,7 @@ contract LiquidityController_Mint_Test is LiquidityController_TestInit { // Call the mint function with unauthorized caller vm.prank(_caller); - vm.expectRevert(Unauthorized.selector); + vm.expectRevert(LiquidityController.LiquidityController_Unauthorized.selector); liquidityController.mint(_to, _amount); // Assert recipient and NativeAssetLiquidity balances remain unchanged @@ -184,7 +198,8 @@ contract LiquidityController_Mint_Test is LiquidityController_TestInit { } /// @notice Tests that the mint function reverts when contract has insufficient balance. - function test_mint_insufficientBalance_fails() public isAuthorizedMinter(authorizedMinter) { + function test_mint_insufficientBalance_fails() public { + _authorizeMinter(authorizedMinter); // Try to mint more than available balance uint256 contractBalance = address(nativeAssetLiquidity).balance; uint256 amount = bound(contractBalance, contractBalance + 1, type(uint256).max); @@ -192,7 +207,9 @@ contract LiquidityController_Mint_Test is LiquidityController_TestInit { // Call the mint function with insufficient balance vm.prank(authorizedMinter); - vm.expectRevert(bytes("")); // Should revert due to insufficient balance in NativeAssetLiquidity + // Should revert due to insufficient balance in NativeAssetLiquidity + vm.expectRevert(NativeAssetLiquidity.NativeAssetLiquidity_InsufficientBalance.selector); + liquidityController.mint(to, amount); // Assert recipient and NativeAssetLiquidity balances remain unchanged @@ -207,7 +224,8 @@ contract LiquidityController_Burn_Test is LiquidityController_TestInit { address authorizedMinter = makeAddr("authorizedMinter"); /// @notice Tests that the burn function can be called by an authorized minter. - function testFuzz_burn_fromAuthorizedMinter_succeeds(uint256 _amount) public isAuthorizedMinter(authorizedMinter) { + function testFuzz_burn_fromAuthorizedMinter_succeeds(uint256 _amount) public { + _authorizeMinter(authorizedMinter); _amount = bound(_amount, 0, address(nativeAssetLiquidity).balance); // Deal the authorized minter with the amount to burn @@ -230,13 +248,8 @@ contract LiquidityController_Burn_Test is LiquidityController_TestInit { } /// @notice Tests that the burn function reverts when called by unauthorized address. - function testFuzz_burn_fromUnauthorizedCaller_fails( - address _caller, - uint256 _amount - ) - public - isAuthorizedMinter(authorizedMinter) - { + function testFuzz_burn_fromUnauthorizedCaller_fails(address _caller, uint256 _amount) public { + _authorizeMinter(authorizedMinter); vm.assume(_caller != authorizedMinter); _amount = bound(_amount, 0, address(nativeAssetLiquidity).balance); @@ -247,7 +260,7 @@ contract LiquidityController_Burn_Test is LiquidityController_TestInit { // Call the burn function with unauthorized caller vm.prank(_caller); - vm.expectRevert(Unauthorized.selector); + vm.expectRevert(LiquidityController.LiquidityController_Unauthorized.selector); liquidityController.burn{ value: _amount }(); // Assert caller and NativeAssetLiquidity balances remain unchanged diff --git a/packages/contracts-bedrock/test/L2/NativeAssetLiquidity.t.sol b/packages/contracts-bedrock/test/L2/NativeAssetLiquidity.t.sol index 44a9b756e0008..2b5869b556596 100644 --- a/packages/contracts-bedrock/test/L2/NativeAssetLiquidity.t.sol +++ b/packages/contracts-bedrock/test/L2/NativeAssetLiquidity.t.sol @@ -4,8 +4,9 @@ pragma solidity 0.8.15; // Testing utilities import { CommonTest } from "test/setup/CommonTest.sol"; -// Error imports -import { Unauthorized, InvalidAmount } from "src/libraries/errors/CommonErrors.sol"; +// Libraries +import { DevFeatures } from "src/libraries/DevFeatures.sol"; +import { NativeAssetLiquidity } from "src/L2/NativeAssetLiquidity.sol"; /// @title NativeAssetLiquidity_TestInit /// @notice Reusable test initialization for `NativeAssetLiquidity` tests. @@ -21,14 +22,18 @@ contract NativeAssetLiquidity_TestInit is CommonTest { /// @notice Test setup. function setUp() public virtual override { - enableCustomGasToken(); super.setUp(); + skipIfDevFeatureDisabled(DevFeatures.CUSTOM_GAS_TOKEN); } +} - /// @notice Tests that contract is set up correctly. - function test_setup_succeeds() public view { - // Assert - assertEq(nativeAssetLiquidity.version(), "1.0.0"); +/// @title NativeAssetLiquidity_Version_Test +/// @notice Tests the `version` function of the `NativeAssetLiquidity` contract. +contract NativeAssetLiquidity_Version_Test is NativeAssetLiquidity_TestInit { + /// @notice Tests that the `version` function returns the correct string. We avoid testing the + /// specific value of the string as it changes frequently. + function test_version_succeeds() public view { + assert(bytes(nativeAssetLiquidity.version()).length > 0); } } @@ -71,7 +76,7 @@ contract NativeAssetLiquidity_Deposit_Test is NativeAssetLiquidity_TestInit { // Call the deposit function with unauthorized caller vm.prank(_caller); // Expect revert with Unauthorized - vm.expectRevert(Unauthorized.selector); + vm.expectRevert(NativeAssetLiquidity.NativeAssetLiquidity_Unauthorized.selector); nativeAssetLiquidity.deposit{ value: _amount }(); // Assert caller and NativeAssetLiquidity balances remain unchanged @@ -119,7 +124,7 @@ contract NativeAssetLiquidity_Withdraw_Test is NativeAssetLiquidity_TestInit { // Call the withdraw function with unauthorized caller vm.prank(_caller); // Expect revert with Unauthorized - vm.expectRevert(Unauthorized.selector); + vm.expectRevert(NativeAssetLiquidity.NativeAssetLiquidity_Unauthorized.selector); nativeAssetLiquidity.withdraw(_amount); // Assert caller and NativeAssetLiquidity balances remain unchanged @@ -135,8 +140,8 @@ contract NativeAssetLiquidity_Withdraw_Test is NativeAssetLiquidity_TestInit { // Call the withdraw function with insufficient balance vm.prank(address(liquidityController)); - // Expect revert with OutOfFunds - vm.expectRevert(bytes("")); + // Expect revert with NativeAssetLiquidity_InsufficientBalance + vm.expectRevert(NativeAssetLiquidity.NativeAssetLiquidity_InsufficientBalance.selector); nativeAssetLiquidity.withdraw(amount); // Assert contract and controller balances remain unchanged @@ -144,41 +149,3 @@ contract NativeAssetLiquidity_Withdraw_Test is NativeAssetLiquidity_TestInit { assertEq(address(liquidityController).balance, 0); } } - -/// @title NativeAssetLiquidity_Fund_Test -/// @notice Tests the `fund` function of the `NativeAssetLiquidity` contract. -contract NativeAssetLiquidity_Fund_Test is NativeAssetLiquidity_TestInit { - /// @notice Tests that the fund function succeeds when called with a non-zero value. - /// @param _amount Amount of native asset (in wei) to call the fund function with. - /// @param _caller Address of the caller to call the fund function with. - function testFuzz_fund_succeeds(uint256 _amount, address _caller) public { - _amount = bound(_amount, 1, 1000 ether); - vm.assume(_caller != address(0)); - vm.assume(_caller != address(nativeAssetLiquidity)); // Prevent contract from calling itself - - // Deal caller with the amount to fund - vm.deal(_caller, _amount); - uint256 initialContractBalance = address(nativeAssetLiquidity).balance; - - // Expect emit LiquidityFunded event - vm.expectEmit(address(nativeAssetLiquidity)); - emit LiquidityFunded(_caller, _amount); - vm.prank(_caller); - nativeAssetLiquidity.fund{ value: _amount }(); - - // Assert caller and contract balances are updated correctly - assertEq(_caller.balance, 0); - assertEq(address(nativeAssetLiquidity).balance, initialContractBalance + _amount); - } - - /// @notice Tests that the fund function reverts when called with zero value. - function test_fund_zeroAmount_reverts() public { - uint256 initialContractBalance = address(nativeAssetLiquidity).balance; - // Expect revert with InvalidAmount - vm.expectRevert(InvalidAmount.selector); - nativeAssetLiquidity.fund{ value: 0 }(); - - // Assert contract balance does not change - assertEq(address(nativeAssetLiquidity).balance, initialContractBalance); - } -} diff --git a/packages/contracts-bedrock/test/L2/SequencerFeeVault.t.sol b/packages/contracts-bedrock/test/L2/SequencerFeeVault.t.sol index 55c5a7eb72991..ab808f1bac122 100644 --- a/packages/contracts-bedrock/test/L2/SequencerFeeVault.t.sol +++ b/packages/contracts-bedrock/test/L2/SequencerFeeVault.t.sol @@ -14,6 +14,7 @@ import { Hashing } from "src/libraries/Hashing.sol"; import { Types } from "src/libraries/Types.sol"; import { Predeploys } from "src/libraries/Predeploys.sol"; import { DeployUtils } from "scripts/libraries/DeployUtils.sol"; +import { DevFeatures } from "src/libraries/DevFeatures.sol"; /// @title SequencerFeeVault_TestInit /// @notice Reusable test initialization for `SequencerFeeVault` tests. @@ -37,8 +38,8 @@ contract SequencerFeeVault_Constructor_Test is SequencerFeeVault_TestInit { assertEq(sequencerFeeVault.recipient(), recipient); assertEq(sequencerFeeVault.MIN_WITHDRAWAL_AMOUNT(), deploy.cfg().sequencerFeeVaultMinimumWithdrawalAmount()); assertEq(sequencerFeeVault.minWithdrawalAmount(), deploy.cfg().sequencerFeeVaultMinimumWithdrawalAmount()); - assertEq(uint8(sequencerFeeVault.WITHDRAWAL_NETWORK()), uint8(Types.WithdrawalNetwork.L1)); - assertEq(uint8(sequencerFeeVault.withdrawalNetwork()), uint8(Types.WithdrawalNetwork.L1)); + assertEq(uint8(sequencerFeeVault.WITHDRAWAL_NETWORK()), deploy.cfg().sequencerFeeVaultWithdrawalNetwork()); + assertEq(uint8(sequencerFeeVault.withdrawalNetwork()), deploy.cfg().sequencerFeeVaultWithdrawalNetwork()); } } @@ -96,6 +97,7 @@ contract SequencerFeeVault_Withdraw_Test is SequencerFeeVault_TestInit { /// @notice Tests that `withdraw` successfully initiates a withdrawal to L1. function test_withdraw_toL1_succeeds() external { + skipIfDevFeatureEnabled(DevFeatures.CUSTOM_GAS_TOKEN); uint256 amount = sequencerFeeVault.MIN_WITHDRAWAL_AMOUNT() + 1; vm.deal(address(sequencerFeeVault), amount); @@ -105,7 +107,12 @@ contract SequencerFeeVault_Withdraw_Test is SequencerFeeVault_TestInit { vm.expectEmit(address(Predeploys.SEQUENCER_FEE_WALLET)); emit Withdrawal(address(sequencerFeeVault).balance, recipient, address(this)); vm.expectEmit(address(Predeploys.SEQUENCER_FEE_WALLET)); - emit Withdrawal(address(sequencerFeeVault).balance, recipient, address(this), Types.WithdrawalNetwork.L1); + emit Withdrawal( + address(sequencerFeeVault).balance, + recipient, + address(this), + Types.WithdrawalNetwork(deploy.cfg().sequencerFeeVaultWithdrawalNetwork()) + ); // The entire vault's balance is withdrawn vm.expectCall(Predeploys.L2_TO_L1_MESSAGE_PASSER, address(sequencerFeeVault).balance, hex""); diff --git a/packages/contracts-bedrock/test/L2/WETH.t.sol b/packages/contracts-bedrock/test/L2/WETH.t.sol index 4b1cfa1751d13..694183115e0a0 100644 --- a/packages/contracts-bedrock/test/L2/WETH.t.sol +++ b/packages/contracts-bedrock/test/L2/WETH.t.sol @@ -16,7 +16,7 @@ contract WETH_Name_Test is CommonTest { /// @notice Tests that the `name` function returns 'Wrapped Ether' by default. function test_name_ether_succeeds() external view { - assertEq("Wrapped Ether", weth.name()); + assertEq(string.concat("Wrapped ", l1Block.gasPayingTokenName()), weth.name()); } } @@ -34,6 +34,6 @@ contract WETH_Symbol_Test is CommonTest { /// @notice Tests that the `symbol` function returns 'WETH' by default. function test_symbol_ether_succeeds() external view { - assertEq("WETH", weth.symbol()); + assertEq(string.concat("W", l1Block.gasPayingTokenSymbol()), weth.symbol()); } } diff --git a/packages/contracts-bedrock/test/libraries/Predeploys.t.sol b/packages/contracts-bedrock/test/libraries/Predeploys.t.sol index ee08344350426..e4ba647172b01 100644 --- a/packages/contracts-bedrock/test/libraries/Predeploys.t.sol +++ b/packages/contracts-bedrock/test/libraries/Predeploys.t.sol @@ -9,6 +9,7 @@ import { EIP1967Helper } from "test/mocks/EIP1967Helper.sol"; import { Predeploys } from "src/libraries/Predeploys.sol"; import { ForgeArtifacts } from "scripts/libraries/ForgeArtifacts.sol"; import { Fork } from "scripts/libraries/Config.sol"; +import { DevFeatures } from "src/libraries/DevFeatures.sol"; /// @title Predeploys_TestInit /// @notice Reusable test initialization for `Predeploys` tests. @@ -172,8 +173,8 @@ contract Predeploys_UnclassifiedInterop_Test is Predeploys_TestInit { contract Predeploys_CustomGasToken_Test is Predeploys_TestInit { /// @notice Test setup. Enabling custom gas token. function setUp() public virtual override { - super.enableCustomGasToken(); super.setUp(); + skipIfDevFeatureDisabled(DevFeatures.CUSTOM_GAS_TOKEN); } /// @notice Tests that the predeploy addresses are set correctly. They have code and the diff --git a/packages/contracts-bedrock/test/scripts/L2Genesis.t.sol b/packages/contracts-bedrock/test/scripts/L2Genesis.t.sol index dbdadf3f8208d..843706aa3888a 100644 --- a/packages/contracts-bedrock/test/scripts/L2Genesis.t.sol +++ b/packages/contracts-bedrock/test/scripts/L2Genesis.t.sol @@ -25,7 +25,7 @@ contract L2Genesis_TestInit is Test { L2Genesis internal genesis; - function setUp() public { + function setUp() public virtual { genesis = new L2Genesis(); } @@ -141,7 +141,9 @@ contract L2Genesis_TestInit is Test { /// @title L2Genesis_Run_Test /// @notice Tests the `run` function of the `L2Genesis` contract. contract L2Genesis_Run_Test is L2Genesis_TestInit { - function test_run_succeeds() external { + function setUp() public override { + super.setUp(); + // Set up default input configuration input = L2Genesis.Input({ l1ChainID: 1, l2ChainID: 2, @@ -168,6 +170,9 @@ contract L2Genesis_Run_Test is L2Genesis_TestInit { gasPayingTokenSymbol: "", nativeAssetLiquidityAmount: type(uint248).max }); + } + + function test_run_succeeds() external { genesis.run(input); testProxyAdmin(); @@ -178,40 +183,17 @@ contract L2Genesis_Run_Test is L2Genesis_TestInit { testForks(); } - /// @dev Modifier to set up the input for L2Genesis with CGT enabled. - modifier setInputCGTEnabled() { - input = L2Genesis.Input({ - l1ChainID: 1, - l2ChainID: 2, - l1CrossDomainMessengerProxy: payable(address(0x0000000000000000000000000000000000000001)), - l1StandardBridgeProxy: payable(address(0x0000000000000000000000000000000000000002)), - l1ERC721BridgeProxy: payable(address(0x0000000000000000000000000000000000000003)), - opChainProxyAdminOwner: address(0x0000000000000000000000000000000000000004), - sequencerFeeVaultRecipient: address(0x0000000000000000000000000000000000000005), - sequencerFeeVaultMinimumWithdrawalAmount: 1, - sequencerFeeVaultWithdrawalNetwork: 1, - baseFeeVaultRecipient: address(0x0000000000000000000000000000000000000006), - baseFeeVaultMinimumWithdrawalAmount: 1, - baseFeeVaultWithdrawalNetwork: 1, - l1FeeVaultRecipient: address(0x0000000000000000000000000000000000000007), - l1FeeVaultMinimumWithdrawalAmount: 1, - l1FeeVaultWithdrawalNetwork: 1, - governanceTokenOwner: address(0x0000000000000000000000000000000000000008), - fork: uint256(LATEST_FORK), - deployCrossL2Inbox: true, - enableGovernance: true, - fundDevAccounts: true, - useCustomGasToken: true, - gasPayingTokenName: "Custom Gas Token", - gasPayingTokenSymbol: "CGT", - nativeAssetLiquidityAmount: type(uint248).max - }); - _; + /// @notice Helper function to configure input for CGT enabled tests. + function _setInputCGTEnabled() internal { + input.useCustomGasToken = true; + input.gasPayingTokenName = "Custom Gas Token"; + input.gasPayingTokenSymbol = "CGT"; } /// @notice Tests that the run function succeeds when CGT is enabled. /// @dev Tests that LiquidityController and NativeAssetLiquidity are deployed. - function test_run_cgt_succeeds() external setInputCGTEnabled { + function test_run_cgt_succeeds() external { + _setInputCGTEnabled(); genesis.run(input); testProxyAdmin(); @@ -223,35 +205,35 @@ contract L2Genesis_Run_Test is L2Genesis_TestInit { testCGT(); } - /// @notice Tests that the run function reverts when CGT is enabled and the withdrawal network type of the FeeVaults - /// is L1. - function test_run_cgt_reverts() external setInputCGTEnabled { - // Expect revert when sequencerFeeVaultWithdrawalNetwork is L1 + /// @notice Tests that the run function reverts when CGT is enabled and sequencerFeeVault withdrawal network is L1. + function test_cgt_sequencerVault_reverts() external { + _setInputCGTEnabled(); input.sequencerFeeVaultWithdrawalNetwork = 0; vm.expectRevert("SequencerFeeVault: withdrawalNetwork type cannot be L1 when custom gas token is enabled"); genesis.run(input); - // Reset sequencerFeeVaultWithdrawalNetwork input to L2 - input.sequencerFeeVaultWithdrawalNetwork = 1; + } - // Expect revert when baseFeeVaultWithdrawalNetwork is L1 + /// @notice Tests that the run function reverts when CGT is enabled and baseFeeVault withdrawal network is L1. + function test_cgt_baseFeeVault_reverts() external { + _setInputCGTEnabled(); input.baseFeeVaultWithdrawalNetwork = 0; vm.expectRevert("BaseFeeVault: withdrawalNetwork type cannot be L1 when custom gas token is enabled"); genesis.run(input); - // Reset baseFeeVaultWithdrawalNetwork input to L2 - input.baseFeeVaultWithdrawalNetwork = 1; + } - // Expect revert when l1FeeVaultWithdrawalNetwork is L1 + /// @notice Tests that the run function reverts when CGT is enabled and l1FeeVault withdrawal network is L1. + function test_cgt_l1FeeVault_reverts() external { + _setInputCGTEnabled(); input.l1FeeVaultWithdrawalNetwork = 0; vm.expectRevert("L1FeeVault: withdrawalNetwork type cannot be L1 when custom gas token is enabled"); genesis.run(input); - // Reset l1FeeVaultWithdrawalNetwork input to L2 - input.l1FeeVaultWithdrawalNetwork = 1; + } - // Expect revert when nativeAssetLiquidityAmount is greater than type(uint248).max - input.nativeAssetLiquidityAmount += 1; + /// @notice Tests that the run function reverts when nativeAssetLiquidityAmount exceeds type(uint248).max. + function test_cgt_liquidityAmount_reverts() external { + _setInputCGTEnabled(); + input.nativeAssetLiquidityAmount = uint256(type(uint248).max) + 1; vm.expectRevert("L2Genesis: native asset liquidity amount must be less than or equal to type(uint248).max"); genesis.run(input); - // Reset nativeAssetLiquidityAmount input to type(uint248).max - input.nativeAssetLiquidityAmount = type(uint248).max; } } diff --git a/packages/contracts-bedrock/test/setup/CommonTest.sol b/packages/contracts-bedrock/test/setup/CommonTest.sol index 1a09ae741f7a3..280a7326d1c25 100644 --- a/packages/contracts-bedrock/test/setup/CommonTest.sol +++ b/packages/contracts-bedrock/test/setup/CommonTest.sol @@ -14,6 +14,7 @@ import { DeployUtils } from "scripts/libraries/DeployUtils.sol"; // Contracts import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; +import { DevFeatures } from "src/libraries/DevFeatures.sol"; // Libraries import { console } from "forge-std/console.sol"; @@ -75,8 +76,11 @@ contract CommonTest is Test, Setup, Events { if (useUpgradedFork) { deploy.cfg().setUseUpgradedFork(true); } - if (useCustomGasToken) { + if (isDevFeatureEnabled(DevFeatures.CUSTOM_GAS_TOKEN)) { + console.log("CommonTest: enabling custom gas token"); deploy.cfg().setUseCustomGasToken(true); + deploy.cfg().setGasPayingTokenName("Custom Gas Token"); + deploy.cfg().setGasPayingTokenSymbol("CGT"); deploy.cfg().setNativeAssetLiquidityAmount(type(uint248).max); deploy.cfg().setBaseFeeVaultWithdrawalNetwork(1); deploy.cfg().setL1FeeVaultWithdrawalNetwork(1); @@ -216,9 +220,4 @@ contract CommonTest is Test, Setup, Events { useUpgradedFork = false; } - - function enableCustomGasToken() public { - _checkNotDeployed("custom gas token"); - useCustomGasToken = true; - } } diff --git a/packages/contracts-bedrock/test/setup/Setup.sol b/packages/contracts-bedrock/test/setup/Setup.sol index 9d95dc5680256..b80c45e597e40 100644 --- a/packages/contracts-bedrock/test/setup/Setup.sol +++ b/packages/contracts-bedrock/test/setup/Setup.sol @@ -340,8 +340,8 @@ contract Setup is FeatureFlags { enableGovernance: deploy.cfg().enableGovernance(), fundDevAccounts: deploy.cfg().fundDevAccounts(), useCustomGasToken: deploy.cfg().useCustomGasToken(), - gasPayingTokenName: "Custom Gas Token", - gasPayingTokenSymbol: "CGT", + gasPayingTokenName: deploy.cfg().gasPayingTokenName(), + gasPayingTokenSymbol: deploy.cfg().gasPayingTokenSymbol(), nativeAssetLiquidityAmount: deploy.cfg().nativeAssetLiquidityAmount() }) );