diff --git a/.circleci/config.yml b/.circleci/config.yml index 12fd931fcd8..347b0fb34d1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2546,7 +2546,6 @@ workflows: - main - OPTIMISM_PORTAL_INTEROP - CANNON_KONA,DEPLOY_V2_DISPUTE_GAMES - - CUSTOM_GAS_TOKEN - OPCM_V2 context: - circleci-repo-readonly-authenticated-github-token diff --git a/op-deployer/pkg/deployer/devfeatures.go b/op-deployer/pkg/deployer/devfeatures.go index 6a8867d43a2..fefd390e06b 100644 --- a/op-deployer/pkg/deployer/devfeatures.go +++ b/op-deployer/pkg/deployer/devfeatures.go @@ -17,9 +17,6 @@ var ( // DeployV2DisputeGamesDevFlag enables deployment of V2 dispute game contracts. DeployV2DisputeGamesDevFlag = common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000100") - - // CustomGasTokenDevFlag enables the custom gas token. - CustomGasTokenDevFlag = common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000001000") ) // IsDevFeatureEnabled checks if a specific development feature is enabled in a feature bitmap. diff --git a/op-deployer/pkg/deployer/integration_test/apply_test.go b/op-deployer/pkg/deployer/integration_test/apply_test.go index bd5dc5c88af..b028b09f82e 100644 --- a/op-deployer/pkg/deployer/integration_test/apply_test.go +++ b/op-deployer/pkg/deployer/integration_test/apply_test.go @@ -321,10 +321,6 @@ func TestEndToEndApply(t *testing.T) { Symbol: "CGT", InitialLiquidity: (*hexutil.Big)(amount), } - // CGT config for OPCM - intent.GlobalDeployOverrides = map[string]interface{}{ - "devFeatureBitmap": deployer.CustomGasTokenDevFlag, - } require.NoError(t, deployer.ApplyPipeline(ctx, deployer.ApplyPipelineOpts{ DeploymentTarget: deployer.DeploymentTargetLive, diff --git a/packages/contracts-bedrock/scripts/checks/test-validation/exclusions.toml b/packages/contracts-bedrock/scripts/checks/test-validation/exclusions.toml index eb7d2bd537f..2edee183316 100644 --- a/packages/contracts-bedrock/scripts/checks/test-validation/exclusions.toml +++ b/packages/contracts-bedrock/scripts/checks/test-validation/exclusions.toml @@ -98,5 +98,12 @@ contracts = [ "TransactionBuilder", # Transaction builder helper library in TimelockGuard test file "Constants_Test", # Invalid naming pattern - doesn't specify function or Uncategorized "LivenessModule2_TestUtils", # Test utils library in LivenessModule2 test file - "L1Block_SetCustomGasToken_Test", # Custom gas token tests hosted in the L1Block test file + "L1BlockCGT_TestInit", # Test initialization contract for L1BlockCGT tests + "L1BlockCGT_GasPayingToken_Test", # Custom gas token tests hosted in the L1Block test file + "L1BlockCGT_GasPayingTokenName_Test", # Custom gas token tests hosted in the L1Block test file + "L1BlockCGT_GasPayingTokenSymbol_Test", # Custom gas token tests hosted in the L1Block test file + "L1BlockCGT_IsCustomGasToken_Test", # Custom gas token tests hosted in the L1Block test file + "L1BlockCGT_SetCustomGasToken_Test", # Custom gas token tests hosted in the L1Block test file + "L2ToL1MessagePasserCGT_TestInit", # Test initialization contract for L2ToL1MessagePasserCGT tests + "L2ToL1MessagePasserCGT_InitiateWithdrawal_Test", # Custom gas token tests hosted in the L2ToL1MessagePasser test file ] diff --git a/packages/contracts-bedrock/scripts/libraries/Config.sol b/packages/contracts-bedrock/scripts/libraries/Config.sol index 60653866f7c..cc88b827168 100644 --- a/packages/contracts-bedrock/scripts/libraries/Config.sol +++ b/packages/contracts-bedrock/scripts/libraries/Config.sol @@ -286,11 +286,6 @@ library Config { return vm.envOr("DEV_FEATURE__DEPLOY_V2_DISPUTE_GAMES", false); } - /// @notice Returns true if the development feature custom gas token is enabled. - function devFeatureCustomGasToken() internal view returns (bool) { - return vm.envOr("DEV_FEATURE__CUSTOM_GAS_TOKEN", false); - } - /// @notice Returns true if the development feature opcm_v2 is enabled. function devFeatureOpcmV2() internal view returns (bool) { return vm.envOr("DEV_FEATURE__OPCM_V2", false); diff --git a/packages/contracts-bedrock/src/libraries/DevFeatures.sol b/packages/contracts-bedrock/src/libraries/DevFeatures.sol index 33a372c63b0..ed46b8c8d2b 100644 --- a/packages/contracts-bedrock/src/libraries/DevFeatures.sol +++ b/packages/contracts-bedrock/src/libraries/DevFeatures.sol @@ -22,10 +22,6 @@ library DevFeatures { bytes32 public constant DEPLOY_V2_DISPUTE_GAMES = bytes32(0x0000000000000000000000000000000000000000000000000000000000000100); - /// @notice The feature that enables the custom gas token. - bytes32 public constant CUSTOM_GAS_TOKEN = - bytes32(0x0000000000000000000000000000000000000000000000000000000000001000); - /// @notice The feature that enables the OPContractsManagerV2 contract. bytes32 public constant OPCM_V2 = bytes32(0x0000000000000000000000000000000000000000000000000000000000010000); diff --git a/packages/contracts-bedrock/test/L1/FeesDepositor.t.sol b/packages/contracts-bedrock/test/L1/FeesDepositor.t.sol index 43b28d21150..5c253b4a7cd 100644 --- a/packages/contracts-bedrock/test/L1/FeesDepositor.t.sol +++ b/packages/contracts-bedrock/test/L1/FeesDepositor.t.sol @@ -9,7 +9,6 @@ import { FeesDepositor } from "src/L1/FeesDepositor.sol"; import { IProxyAdminOwnedBase } from "interfaces/L1/IProxyAdminOwnedBase.sol"; import { Proxy } from "src/universal/Proxy.sol"; import { Features } from "src/libraries/Features.sol"; -import { DevFeatures } from "src/libraries/DevFeatures.sol"; /// @title FeesDepositor_TestInit /// @notice Base test contract with initialization for `FeesDepositor` tests. @@ -98,8 +97,6 @@ contract FeesDepositor_Receive_Test is FeesDepositor_TestInit { } function testFuzz_receive_atOrAboveThreshold_succeeds(uint256 _sendAmount) external { - skipIfDevFeatureEnabled(DevFeatures.CUSTOM_GAS_TOKEN); - // Handling the fork tests scenario case for the fork tests uint256 depositFeesRecipientBalanceBefore = depositFeesRecipient.balance; _sendAmount = bound(_sendAmount, minDepositAmount, type(uint256).max - depositFeesRecipientBalanceBefore); @@ -126,8 +123,6 @@ contract FeesDepositor_Receive_Test is FeesDepositor_TestInit { } function testFuzz_receive_multipleDeposits_succeeds(uint256 _firstAmount, uint256 _secondAmount) external { - skipIfDevFeatureEnabled(DevFeatures.CUSTOM_GAS_TOKEN); - // Handling the fork tests scenario uint256 depositFeesRecipientBalanceBefore = depositFeesRecipient.balance; // First amount should not exceed minDepositAmount (so it doesn't trigger deposit) diff --git a/packages/contracts-bedrock/test/L1/L1StandardBridge.t.sol b/packages/contracts-bedrock/test/L1/L1StandardBridge.t.sol index e26b938a9c2..b14ea0874d2 100644 --- a/packages/contracts-bedrock/test/L1/L1StandardBridge.t.sol +++ b/packages/contracts-bedrock/test/L1/L1StandardBridge.t.sol @@ -15,7 +15,6 @@ import { Predeploys } from "src/libraries/Predeploys.sol"; import { AddressAliasHelper } from "src/vendor/AddressAliasHelper.sol"; import { EIP1967Helper } from "test/mocks/EIP1967Helper.sol"; import { Features } from "src/libraries/Features.sol"; -import { DevFeatures } from "src/libraries/DevFeatures.sol"; // Interfaces import { ICrossDomainMessenger } from "interfaces/universal/ICrossDomainMessenger.sol"; @@ -333,7 +332,6 @@ contract L1StandardBridge_Paused_Test is CommonTest { contract L1StandardBridge_Receive_Test is CommonTest { /// @notice Tests receive bridges ETH successfully. function test_receive_succeeds() external { - skipIfDevFeatureEnabled(DevFeatures.CUSTOM_GAS_TOKEN); uint256 portalBalanceBefore = address(optimismPortal2).balance; uint256 ethLockboxBalanceBefore = address(ethLockbox).balance; @@ -388,7 +386,6 @@ contract L1StandardBridge_DepositETH_Test is L1StandardBridge_TestInit { /// Only EOA can call depositETH. /// ETH ends up in the optimismPortal. function test_depositETH_fromEOA_succeeds() external { - skipIfDevFeatureEnabled(DevFeatures.CUSTOM_GAS_TOKEN); _preBridgeETH({ isLegacy: true, value: 500 }); uint256 portalBalanceBefore = address(optimismPortal2).balance; uint256 ethLockboxBalanceBefore = address(ethLockbox).balance; @@ -404,7 +401,6 @@ contract L1StandardBridge_DepositETH_Test is L1StandardBridge_TestInit { /// @notice Tests that depositing ETH succeeds for an EOA using 7702 delegation. function test_depositETH_fromEOA7702_succeeds() external { - skipIfDevFeatureEnabled(DevFeatures.CUSTOM_GAS_TOKEN); // Set alice to have 7702 code. vm.etch(alice, abi.encodePacked(hex"EF0100", address(0))); @@ -439,7 +435,6 @@ contract L1StandardBridge_DepositETHTo_Test is L1StandardBridge_TestInit { /// EOA or contract can call depositETHTo. /// ETH ends up in the optimismPortal. function test_depositETHTo_succeeds() external { - skipIfDevFeatureEnabled(DevFeatures.CUSTOM_GAS_TOKEN); _preBridgeETHTo({ isLegacy: true, value: 600 }); uint256 portalBalanceBefore = address(optimismPortal2).balance; uint256 ethLockboxBalanceBefore = address(ethLockbox).balance; @@ -457,7 +452,6 @@ contract L1StandardBridge_DepositETHTo_Test is L1StandardBridge_TestInit { /// @param _to Random recipient address /// @param _amount Random ETH amount to deposit function testFuzz_depositETHTo_randomRecipient_succeeds(address _to, uint256 _amount) external { - skipIfDevFeatureEnabled(DevFeatures.CUSTOM_GAS_TOKEN); vm.assume(_to != address(0)); _amount = bound(_amount, 1, 10 ether); @@ -786,7 +780,6 @@ contract L1StandardBridge_Uncategorized_Test is L1StandardBridge_TestInit { /// Only EOA can call bridgeETH. /// ETH ends up in the optimismPortal. function test_bridgeETH_succeeds() external { - skipIfDevFeatureEnabled(DevFeatures.CUSTOM_GAS_TOKEN); _preBridgeETH({ isLegacy: false, value: 500 }); uint256 portalBalanceBefore = address(optimismPortal2).balance; uint256 ethLockboxBalanceBefore = address(ethLockbox).balance; @@ -806,7 +799,6 @@ contract L1StandardBridge_Uncategorized_Test is L1StandardBridge_TestInit { /// Only EOA can call bridgeETHTo. /// ETH ends up in the optimismPortal. function test_bridgeETHTo_succeeds() external { - skipIfDevFeatureEnabled(DevFeatures.CUSTOM_GAS_TOKEN); _preBridgeETHTo({ isLegacy: false, value: 600 }); uint256 portalBalanceBefore = address(optimismPortal2).balance; uint256 ethLockboxBalanceBefore = address(ethLockbox).balance; diff --git a/packages/contracts-bedrock/test/L1/OptimismPortal2.t.sol b/packages/contracts-bedrock/test/L1/OptimismPortal2.t.sol index 0ba370bb66b..8a9f835dffd 100644 --- a/packages/contracts-bedrock/test/L1/OptimismPortal2.t.sol +++ b/packages/contracts-bedrock/test/L1/OptimismPortal2.t.sol @@ -242,12 +242,6 @@ contract OptimismPortal2_Initialize_Test is OptimismPortal2_TestInit { assertEq(address(optimismPortal2.ethLockbox()), address(0)); } - if (isUsingCustomGasToken()) { - assertTrue(optimismPortal2.systemConfig().isFeatureEnabled(Features.CUSTOM_GAS_TOKEN)); - } else if (!isUsingLockbox()) { - assertFalse(optimismPortal2.systemConfig().isFeatureEnabled(Features.CUSTOM_GAS_TOKEN)); - } - returnIfForkTest( "OptimismPortal2_Initialize_Test: Do not check guardian and respectedGameType on forked networks" ); @@ -721,7 +715,8 @@ 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 { - skipIfSysFeatureDisabled(Features.CUSTOM_GAS_TOKEN); + skipIfDevFeatureEnabled(DevFeatures.OPTIMISM_PORTAL_INTEROP); + setUseCustomGasToken(true); _value = bound(_value, 1, type(uint128).max); vm.deal(alice, _value); @@ -1408,7 +1403,9 @@ contract OptimismPortal2_ProveWithdrawalTransaction_Test is OptimismPortal2_Test /// @notice Tests that `proveWithdrawalTransaction` reverts when the custom gas token mode /// is enabled and the withdrawal transaction has a value. function test_proveWithdrawalTransaction_withValueAndCustomGasToken_reverts() external { - skipIfSysFeatureDisabled(Features.CUSTOM_GAS_TOKEN); + skipIfDevFeatureEnabled(DevFeatures.OPTIMISM_PORTAL_INTEROP); + setUseCustomGasToken(true); + // Set the withdrawal transaction value to a non-zero value. _defaultTx.value = bound(uint256(1), 1, type(uint256).max); @@ -1910,7 +1907,9 @@ contract OptimismPortal2_FinalizeWithdrawalTransaction_Test is OptimismPortal2_T /// @notice Tests that `finalizeWithdrawalTransaction` reverts when the custom gas token mode /// is enabled and the withdrawal transaction has a value. function test_finalizeWithdrawalTransaction_withValueAndCustomGasToken_reverts() external { - skipIfSysFeatureDisabled(Features.CUSTOM_GAS_TOKEN); + skipIfDevFeatureEnabled(DevFeatures.OPTIMISM_PORTAL_INTEROP); + setUseCustomGasToken(true); + // Set the withdrawal transaction value to a non-zero value. _defaultTx.value = bound(uint256(1), 1, type(uint256).max); @@ -1930,9 +1929,6 @@ contract OptimismPortal2_FinalizeWithdrawalTransaction_Test is OptimismPortal2_T external { skipIfForkTest("Skipping on forked tests because of the L2ToL1MessageParser call below"); - if (isUsingCustomGasToken()) { - _value = 0; - } vm.assume( _target != address(optimismPortal2) // Cannot call the optimism portal or a contract @@ -2001,6 +1997,78 @@ contract OptimismPortal2_FinalizeWithdrawalTransaction_Test is OptimismPortal2_T assertTrue(optimismPortal2.finalizedWithdrawals(withdrawalHash)); } + /// @notice Differential test for `finalizeWithdrawalTransaction` when custom gas token mode is enabled. + function testDiff_finalizeWithdrawalTransaction_withCustomGasToken_succeeds( + address _sender, + address _target, + uint256 _gasLimit, + bytes memory _data + ) + external + { + skipIfForkTest("Skipping on forked tests because of the L2ToL1MessageParser call below"); + setUseCustomGasToken(true); + + vm.assume( + _target != address(optimismPortal2) // Cannot call the optimism portal or a contract + && _target.code.length == 0 // No accounts with code + && _target != CONSOLE // The console has no code but behaves like a contract + && uint160(_target) > 9 // No precompiles (or zero address) + ); + + uint256 gasLimit = bound(_gasLimit, 0, 50_000_000); + uint256 nonce = l2ToL1MessagePasser.messageNonce(); + + // Get a withdrawal transaction and mock proof from the differential testing script. + Types.WithdrawalTransaction memory _tx = Types.WithdrawalTransaction({ + nonce: nonce, + sender: _sender, + target: _target, + value: 0, + gasLimit: gasLimit, + data: _data + }); + ( + bytes32 stateRoot, + bytes32 storageRoot, + bytes32 outputRoot, + bytes32 withdrawalHash, + bytes[] memory withdrawalProof + ) = ffi.getProveWithdrawalTransactionInputs(_tx); + + // Create the output root proof + Types.OutputRootProof memory proof = Types.OutputRootProof({ + version: bytes32(uint256(0)), + stateRoot: stateRoot, + messagePasserStorageRoot: storageRoot, + latestBlockhash: bytes32(uint256(0)) + }); + + // Ensure the values returned from ffi are correct + assertEq(outputRoot, Hashing.hashOutputRootProof(proof)); + assertEq(withdrawalHash, Hashing.hashWithdrawal(_tx)); + + // Setup the dispute game to return the output root + vm.mockCall(address(game), abi.encodeCall(game.rootClaim, ()), abi.encode(outputRoot)); + + // Prove the withdrawal transaction + optimismPortal2.proveWithdrawalTransaction(_tx, _proposedGameIndex, proof, withdrawalProof); + (IDisputeGame _game,) = optimismPortal2.provenWithdrawals(withdrawalHash, address(this)); + assertTrue(_game.rootClaim().raw() != bytes32(0)); + + // Resolve the dispute game + game.resolveClaim(0, 0); + game.resolve(); + + // Warp past the finalization period + vm.warp(block.timestamp + optimismPortal2.proofMaturityDelaySeconds() + 1); + + // Finalize the withdrawal transaction + vm.expectCallMinGas(_tx.target, _tx.value, uint64(_tx.gasLimit), _tx.data); + optimismPortal2.finalizeWithdrawalTransaction(_tx); + assertTrue(optimismPortal2.finalizedWithdrawals(withdrawalHash)); + } + /// @notice Tests that `finalizeWithdrawalTransaction` succeeds even if the respected game type /// is changed. function test_finalizeWithdrawalTransaction_wasRespectedGameType_succeeds( @@ -2014,9 +2082,6 @@ contract OptimismPortal2_FinalizeWithdrawalTransaction_Test is OptimismPortal2_T external { skipIfForkTest("Skipping on forked tests because of the L2ToL1MessageParser call below"); - if (isUsingCustomGasToken()) { - _value = 0; - } vm.assume( _target != address(optimismPortal2) // Cannot call the optimism portal or a contract @@ -2513,7 +2578,8 @@ contract OptimismPortal2_DepositTransaction_Test is OptimismPortal2_TestInit { /// @notice Tests that `depositTransaction` reverts when the value is greater than 0 and the /// custom gas token is active. function test_depositTransaction_withCustomGasTokenAndValue_reverts(bytes memory _data, uint256 _value) external { - skipIfSysFeatureDisabled(Features.CUSTOM_GAS_TOKEN); + skipIfDevFeatureEnabled(DevFeatures.OPTIMISM_PORTAL_INTEROP); + setUseCustomGasToken(true); // Prevent overflow on an upgrade context _value = bound(_value, 1, type(uint256).max - address(optimismPortal2).balance); @@ -2567,10 +2633,6 @@ contract OptimismPortal2_DepositTransaction_Test is OptimismPortal2_TestInit { _mint = bound(_mint, 0, type(uint256).max - address(ethLockbox).balance); } - if (isUsingCustomGasToken()) { - _mint = 0; - } - _gasLimit = uint64( bound( _gasLimit, @@ -2618,6 +2680,59 @@ contract OptimismPortal2_DepositTransaction_Test is OptimismPortal2_TestInit { } } + /// @notice Tests that `depositTransaction` succeeds for an EOA with custom gas token. + function testFuzz_depositTransaction_eoaWithCustomGasToken_succeeds( + address _to, + uint64 _gasLimit, + uint256 _value, + bool _isCreation, + bytes memory _data + ) + external + { + setUseCustomGasToken(true); + + _gasLimit = uint64( + bound( + _gasLimit, + optimismPortal2.minimumGasLimit(uint64(_data.length)), + systemConfig.resourceConfig().maxResourceLimit + ) + ); + if (_isCreation) _to = address(0); + + uint256 balanceBefore = address(optimismPortal2).balance; + uint256 lockboxBalanceBefore = address(ethLockbox).balance; + + // EOA emulation + vm.expectEmit(address(optimismPortal2)); + emitTransactionDeposited({ + _from: depositor, + _to: _to, + _value: _value, + _mint: 0, + _gasLimit: _gasLimit, + _isCreation: _isCreation, + _data: _data + }); + + vm.prank(depositor, depositor); + optimismPortal2.depositTransaction({ + _to: _to, + _value: _value, + _gasLimit: _gasLimit, + _isCreation: _isCreation, + _data: _data + }); + + if (isSysFeatureEnabled(Features.ETH_LOCKBOX)) { + assertEq(address(optimismPortal2).balance, balanceBefore); + assertEq(address(ethLockbox).balance, lockboxBalanceBefore); + } else { + assertEq(address(optimismPortal2).balance, balanceBefore); + } + } + /// @notice Tests that `depositTransaction` succeeds for an EOA using 7702 delegation. function testFuzz_depositTransaction_eoa7702_succeeds( address _to, @@ -2635,10 +2750,6 @@ contract OptimismPortal2_DepositTransaction_Test is OptimismPortal2_TestInit { // Prevent overflow on an upgrade context _mint = bound(_mint, 0, type(uint256).max - address(ethLockbox).balance); - if (isUsingCustomGasToken()) { - _mint = 0; - } - _gasLimit = uint64( bound( _gasLimit, @@ -2685,6 +2796,58 @@ contract OptimismPortal2_DepositTransaction_Test is OptimismPortal2_TestInit { } } + /// @notice Tests that `depositTransaction` succeeds for an EOA using 7702 delegation with custom gas token. + function testFuzz_depositTransaction_eoa7702WithCustomGasToken_succeeds( + address _to, + uint64 _gasLimit, + uint256 _value, + bool _isCreation, + bytes memory _data, + address _7702Target + ) + external + { + setUseCustomGasToken(true); + assumeNotForgeAddress(_7702Target); + + _gasLimit = uint64( + bound( + _gasLimit, + optimismPortal2.minimumGasLimit(uint64(_data.length)), + systemConfig.resourceConfig().maxResourceLimit + ) + ); + if (_isCreation) _to = address(0); + + uint256 portalBalanceBefore = address(optimismPortal2).balance; + + // EOA emulation + vm.expectEmit(address(optimismPortal2)); + emitTransactionDeposited({ + _from: depositor, + _to: _to, + _value: _value, + _mint: 0, + _gasLimit: _gasLimit, + _isCreation: _isCreation, + _data: _data + }); + + // 7702 delegation using the 7702 prefix + vm.etch(depositor, abi.encodePacked(hex"EF0100", _7702Target)); + + vm.prank(depositor, address(0x0420)); + optimismPortal2.depositTransaction({ + _to: _to, + _value: _value, + _gasLimit: _gasLimit, + _isCreation: _isCreation, + _data: _data + }); + + assertEq(address(optimismPortal2).balance, portalBalanceBefore); + } + /// @notice Tests that `depositTransaction` succeeds for a contract. function testFuzz_depositTransaction_contract_succeeds( address _to, @@ -2698,9 +2861,6 @@ contract OptimismPortal2_DepositTransaction_Test is OptimismPortal2_TestInit { { // Prevent overflow on an upgrade context _mint = bound(_mint, 0, type(uint256).max - address(ethLockbox).balance); - if (isUsingCustomGasToken()) { - _mint = 0; - } _gasLimit = uint64( bound( _gasLimit, @@ -2747,6 +2907,52 @@ contract OptimismPortal2_DepositTransaction_Test is OptimismPortal2_TestInit { assertEq(address(optimismPortal2).balance, balanceBefore + _mint); } } + + /// @notice Tests that `depositTransaction` succeeds for a contract with custom gas token. + function testFuzz_depositTransaction_contractWithCustomGasToken_succeeds( + address _to, + uint64 _gasLimit, + uint256 _value, + bool _isCreation, + bytes memory _data + ) + external + { + setUseCustomGasToken(true); + + _gasLimit = uint64( + bound( + _gasLimit, + optimismPortal2.minimumGasLimit(uint64(_data.length)), + systemConfig.resourceConfig().maxResourceLimit + ) + ); + if (_isCreation) _to = address(0); + + uint256 balanceBefore = address(optimismPortal2).balance; + + vm.expectEmit(address(optimismPortal2)); + emitTransactionDeposited({ + _from: AddressAliasHelper.applyL1ToL2Alias(address(this)), + _to: _to, + _value: _value, + _mint: 0, + _gasLimit: _gasLimit, + _isCreation: _isCreation, + _data: _data + }); + + vm.prank(address(this)); + optimismPortal2.depositTransaction({ + _to: _to, + _value: _value, + _gasLimit: _gasLimit, + _isCreation: _isCreation, + _data: _data + }); + + assertEq(address(optimismPortal2).balance, balanceBefore); + } } /// @title OptimismPortal2_Params_Test diff --git a/packages/contracts-bedrock/test/L2/FeeSplitter.t.sol b/packages/contracts-bedrock/test/L2/FeeSplitter.t.sol index 0ed14418f63..35edca9a278 100644 --- a/packages/contracts-bedrock/test/L2/FeeSplitter.t.sol +++ b/packages/contracts-bedrock/test/L2/FeeSplitter.t.sol @@ -13,7 +13,6 @@ import { ReentrantMockFeeVault } from "test/mocks/ReentrantMockFeeVault.sol"; // Libraries import { Predeploys } from "src/libraries/Predeploys.sol"; import { Types } from "src/libraries/Types.sol"; -import { DevFeatures } from "src/libraries/DevFeatures.sol"; // Interfaces import { IFeeSplitter } from "interfaces/L2/IFeeSplitter.sol"; @@ -42,10 +41,6 @@ contract FeeSplitter_TestInit is CommonTest { /// @notice Test setup. function setUp() public virtual override { - // Resolve features and skip whole test suite if custom gas token is enabled - resolveFeaturesFromEnv(); - skipIfDevFeatureEnabled(DevFeatures.CUSTOM_GAS_TOKEN); - // Enable revenue sharing before calling parent setUp super.enableRevenueShare(); super.setUp(); diff --git a/packages/contracts-bedrock/test/L2/FeeVault.t.sol b/packages/contracts-bedrock/test/L2/FeeVault.t.sol index 9cdaf4a31d2..edbd1c0064d 100644 --- a/packages/contracts-bedrock/test/L2/FeeVault.t.sol +++ b/packages/contracts-bedrock/test/L2/FeeVault.t.sol @@ -14,7 +14,6 @@ import { IL2ToL1MessagePasser } from "interfaces/L2/IL2ToL1MessagePasser.sol"; import { Hashing } from "src/libraries/Hashing.sol"; import { Types } from "src/libraries/Types.sol"; import { Predeploys } from "src/libraries/Predeploys.sol"; -import { DevFeatures } from "src/libraries/DevFeatures.sol"; /// @title FeeVault_Uncategorized_Test /// @notice Abstract test contract for fee feeVault testing. @@ -84,8 +83,6 @@ abstract contract FeeVault_Uncategorized_Test is CommonTest { /// @notice Tests that `withdraw` successfully initiates a withdrawal to L1. function test_withdraw_toL1_succeeds() external { - skipIfDevFeatureEnabled(DevFeatures.CUSTOM_GAS_TOKEN); - // Setup L1 withdrawal vm.prank(IProxyAdmin(Predeploys.PROXY_ADMIN).owner()); feeVault.setWithdrawalNetwork(Types.WithdrawalNetwork.L1); diff --git a/packages/contracts-bedrock/test/L2/L1Block.t.sol b/packages/contracts-bedrock/test/L2/L1Block.t.sol index 444587bb120..0d7cc2e6202 100644 --- a/packages/contracts-bedrock/test/L2/L1Block.t.sol +++ b/packages/contracts-bedrock/test/L2/L1Block.t.sol @@ -9,7 +9,6 @@ import { stdStorage, StdStorage } from "forge-std/Test.sol"; 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"; @@ -38,6 +37,13 @@ abstract contract L1Block_TestInit is CommonTest { } } +abstract contract L1BlockCGT_TestInit is L1Block_TestInit { + function setUp() public virtual override { + super.enableCustomGasToken(); + super.setUp(); + } +} + /// @title L1Block_Version_Test /// @notice Test contract for L1Block `version` function. contract L1Block_Version_Test is L1Block_TestInit { @@ -53,16 +59,18 @@ 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 { - skipIfDevFeatureEnabled(DevFeatures.CUSTOM_GAS_TOKEN); + function test_gasPayingToken_succeeds() external view { (address token, uint8 decimals) = l1Block.gasPayingToken(); assertEq(token, Constants.ETHER); assertEq(uint256(decimals), uint256(18)); } +} +/// @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 when custom gas token is enabled. function test_gasPayingToken_customGasToken_reverts() external { - skipIfDevFeatureDisabled(DevFeatures.CUSTOM_GAS_TOKEN); vm.expectRevert("L1BlockCGT: deprecated"); l1Block.gasPayingToken(); } @@ -72,15 +80,17 @@ contract L1Block_GasPayingToken_Test is L1Block_TestInit { /// @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 { - skipIfDevFeatureEnabled(DevFeatures.CUSTOM_GAS_TOKEN); + function test_gasPayingTokenName_succeeds() external view { assertEq("Ether", l1Block.gasPayingTokenName()); } +} +/// @title L1BlockCGT_GasPayingTokenName_Test +/// @notice Tests the `gasPayingTokenName` function of the `L1BlockCGT` contract. +contract L1BlockCGT_GasPayingTokenName_Test is L1BlockCGT_TestInit { /// @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); + function test_gasPayingTokenName_customGasToken_succeeds() external view { assertEq(liquidityController.gasPayingTokenName(), l1Block.gasPayingTokenName()); } } @@ -89,15 +99,17 @@ contract L1Block_GasPayingTokenName_Test is L1Block_TestInit { /// @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 { - skipIfDevFeatureEnabled(DevFeatures.CUSTOM_GAS_TOKEN); + function test_gasPayingTokenSymbol_succeeds() external view { assertEq("ETH", l1Block.gasPayingTokenSymbol()); } +} +/// @title L1BlockCGT_GasPayingTokenSymbol_Test +/// @notice Tests the `gasPayingTokenSymbol` function of the `L1BlockCGT` contract. +contract L1BlockCGT_GasPayingTokenSymbol_Test is L1BlockCGT_TestInit { /// @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); + function test_gasPayingTokenSymbol_customGasToken_succeeds() external view { assertEq(liquidityController.gasPayingTokenSymbol(), l1Block.gasPayingTokenSymbol()); } } @@ -107,15 +119,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 { - skipIfDevFeatureEnabled(DevFeatures.CUSTOM_GAS_TOKEN); + function test_isCustomGasToken_succeeds() external view { assertFalse(l1Block.isCustomGasToken()); } +} +/// @title L1BlockCGT_IsCustomGasToken_Test +/// @notice Tests the `isCustomGasToken` function of the `L1BlockCGT` contract. +contract L1BlockCGT_IsCustomGasToken_Test is L1BlockCGT_TestInit { /// @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); + function test_isCustomGasToken_customGasToken_succeeds() external view { assertTrue(l1Block.isCustomGasToken()); } } @@ -458,16 +472,15 @@ contract L1Block_SetL1BlockValuesJovian_Test is L1Block_TestInit { } } -/// @title L1Block_SetCustomGasToken_Test -/// @notice Tests the `setCustomGasToken` function of the `L1Block` contract. -contract L1Block_SetCustomGasToken_Test is L1Block_TestInit { +/// @title L1BlockCGT_SetCustomGasToken_Test +/// @notice Tests the `setCustomGasToken` function of the `L1BlockCGT` contract. +contract L1BlockCGT_SetCustomGasToken_Test is L1BlockCGT_TestInit { using stdStorage for StdStorage; IL1BlockCGT l1BlockCGT; function setUp() public override { super.setUp(); - skipIfDevFeatureDisabled(DevFeatures.CUSTOM_GAS_TOKEN); l1BlockCGT = IL1BlockCGT(address(l1Block)); } diff --git a/packages/contracts-bedrock/test/L2/L1Withdrawer.t.sol b/packages/contracts-bedrock/test/L2/L1Withdrawer.t.sol index 277959e30be..865e7177f23 100644 --- a/packages/contracts-bedrock/test/L2/L1Withdrawer.t.sol +++ b/packages/contracts-bedrock/test/L2/L1Withdrawer.t.sol @@ -6,7 +6,6 @@ import { ICrossDomainMessenger } from "interfaces/universal/ICrossDomainMessenge import { Predeploys } from "src/libraries/Predeploys.sol"; import { IL1Withdrawer } from "interfaces/L2/IL1Withdrawer.sol"; import { DeployUtils } from "scripts/libraries/DeployUtils.sol"; -import { DevFeatures } from "src/libraries/DevFeatures.sol"; /// @title L1Withdrawer_TestInit /// @notice Base test contract with initialization for `L1Withdrawer` tests. @@ -26,10 +25,6 @@ contract L1Withdrawer_TestInit is CommonTest { /// @notice Test setup. function setUp() public virtual override { - // Resolve features and skip whole test suite if custom gas token is enabled - resolveFeaturesFromEnv(); - skipIfDevFeatureEnabled(DevFeatures.CUSTOM_GAS_TOKEN); - // Enable revenue sharing before calling parent setUp super.enableRevenueShare(); super.setUp(); diff --git a/packages/contracts-bedrock/test/L2/L2StandardBridge.t.sol b/packages/contracts-bedrock/test/L2/L2StandardBridge.t.sol index 0f25b19caaa..365a8730452 100644 --- a/packages/contracts-bedrock/test/L2/L2StandardBridge.t.sol +++ b/packages/contracts-bedrock/test/L2/L2StandardBridge.t.sol @@ -14,7 +14,6 @@ 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"; @@ -232,7 +231,6 @@ 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(); @@ -325,7 +323,6 @@ 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); @@ -468,7 +465,6 @@ contract L2StandardBridge_Uncategorized_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)); @@ -502,7 +498,6 @@ contract L2StandardBridge_Uncategorized_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 c79f3af797e..05b61536336 100644 --- a/packages/contracts-bedrock/test/L2/L2ToL1MessagePasser.t.sol +++ b/packages/contracts-bedrock/test/L2/L2ToL1MessagePasser.t.sol @@ -7,7 +7,6 @@ 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"; import { SemverComp } from "src/libraries/SemverComp.sol"; // Interfaces @@ -27,8 +26,6 @@ contract L2ToL1MessagePasser_Version_Test is CommonTest { contract L2ToL1MessagePasser_Receive_Test is CommonTest { /// @notice Tests that receive() initiates withdrawal with default gas limit. function testFuzz_receive_initiatesWithdrawal_succeeds(uint256 _value) external { - skipIfDevFeatureEnabled(DevFeatures.CUSTOM_GAS_TOKEN); - uint256 nonce = l2ToL1MessagePasser.messageNonce(); bytes32 withdrawalHash = Hashing.hashWithdrawal( @@ -59,7 +56,6 @@ contract L2ToL1MessagePasser_Receive_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 }); @@ -89,9 +85,6 @@ contract L2ToL1MessagePasser_InitiateWithdrawal_Test is CommonTest { ) external { - if (isDevFeatureEnabled(DevFeatures.CUSTOM_GAS_TOKEN)) { - _value = 0; - } uint256 nonce = l2ToL1MessagePasser.messageNonce(); bytes32 withdrawalHash = Hashing.hashWithdrawal( @@ -129,7 +122,6 @@ contract L2ToL1MessagePasser_InitiateWithdrawal_Test is CommonTest { ) external { - skipIfDevFeatureEnabled(DevFeatures.CUSTOM_GAS_TOKEN); bytes32 withdrawalHash = Hashing.hashWithdrawal( Types.WithdrawalTransaction({ nonce: l2ToL1MessagePasser.messageNonce(), @@ -161,7 +153,6 @@ contract L2ToL1MessagePasser_InitiateWithdrawal_Test is CommonTest { ) external { - skipIfDevFeatureEnabled(DevFeatures.CUSTOM_GAS_TOKEN); uint256 nonce = l2ToL1MessagePasser.messageNonce(); // Verify caller is an EOA (alice has no code) @@ -183,6 +174,52 @@ contract L2ToL1MessagePasser_InitiateWithdrawal_Test is CommonTest { // the nonce increments assertEq(nonce + 1, l2ToL1MessagePasser.messageNonce()); } +} + +/// @title L2ToL1MessagePasserCGT_InitiateWithdrawal_Test +/// @notice Tests the `initiateWithdrawal` function of the `L2ToL1MessagePasserCGT` contract. +contract L2ToL1MessagePasserCGT_InitiateWithdrawal_Test is CommonTest { + function setUp() public override { + super.enableCustomGasToken(); + super.setUp(); + } + + /// @notice Tests that `initiateWithdrawal` succeeds and correctly sets the state of the + /// message passer for the withdrawal hash. + function testFuzz_initiateWithdrawal_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(_target, _gasLimit, _data); + + assertEq(l2ToL1MessagePasser.sentMessages(withdrawalHash), true); + assertEq(l2ToL1MessagePasser.messageNonce(), nonce + 1); + + 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. @@ -192,7 +229,6 @@ contract L2ToL1MessagePasser_InitiateWithdrawal_Test is CommonTest { ) external { - skipIfDevFeatureDisabled(DevFeatures.CUSTOM_GAS_TOKEN); // Set initial state _value = bound(_value, 1, type(uint256).max); vm.deal(_randomAddress, _value); diff --git a/packages/contracts-bedrock/test/L2/LiquidityController.t.sol b/packages/contracts-bedrock/test/L2/LiquidityController.t.sol index 45375ce66ca..91fb873dc77 100644 --- a/packages/contracts-bedrock/test/L2/LiquidityController.t.sol +++ b/packages/contracts-bedrock/test/L2/LiquidityController.t.sol @@ -5,13 +5,13 @@ pragma solidity 0.8.15; import { CommonTest } from "test/setup/CommonTest.sol"; import { stdStorage, StdStorage } from "forge-std/Test.sol"; -// Libraries -import { DevFeatures } from "src/libraries/DevFeatures.sol"; - // Contracts import { LiquidityController } from "src/L2/LiquidityController.sol"; import { NativeAssetLiquidity } from "src/L2/NativeAssetLiquidity.sol"; +// Libraries +import { Predeploys } from "src/libraries/Predeploys.sol"; + /// @title LiquidityController_TestInit /// @notice Reusable test initialization for `LiquidityController` tests. contract LiquidityController_TestInit is CommonTest { @@ -37,8 +37,8 @@ contract LiquidityController_TestInit is CommonTest { /// @notice Test setup. function setUp() public virtual override { + super.enableCustomGasToken(); super.setUp(); - skipIfDevFeatureDisabled(DevFeatures.CUSTOM_GAS_TOKEN); } /// @notice Helper function to authorize a minter. @@ -215,6 +215,8 @@ contract LiquidityController_Mint_Test is LiquidityController_TestInit { contract LiquidityController_Burn_Test is LiquidityController_TestInit { /// @notice Tests that the burn function can be called by an authorized minter. function testFuzz_burn_fromAuthorizedMinter_succeeds(uint256 _amount, address _minter) public { + vm.assume(_minter != Predeploys.NATIVE_ASSET_LIQUIDITY); + _authorizeMinter(_minter); _amount = bound(_amount, 0, address(nativeAssetLiquidity).balance); diff --git a/packages/contracts-bedrock/test/L2/NativeAssetLiquidity.t.sol b/packages/contracts-bedrock/test/L2/NativeAssetLiquidity.t.sol index 2b5869b5565..6b6076527e6 100644 --- a/packages/contracts-bedrock/test/L2/NativeAssetLiquidity.t.sol +++ b/packages/contracts-bedrock/test/L2/NativeAssetLiquidity.t.sol @@ -5,7 +5,6 @@ pragma solidity 0.8.15; import { CommonTest } from "test/setup/CommonTest.sol"; // Libraries -import { DevFeatures } from "src/libraries/DevFeatures.sol"; import { NativeAssetLiquidity } from "src/L2/NativeAssetLiquidity.sol"; /// @title NativeAssetLiquidity_TestInit @@ -22,8 +21,8 @@ contract NativeAssetLiquidity_TestInit is CommonTest { /// @notice Test setup. function setUp() public virtual override { + super.enableCustomGasToken(); super.setUp(); - skipIfDevFeatureDisabled(DevFeatures.CUSTOM_GAS_TOKEN); } } diff --git a/packages/contracts-bedrock/test/L2/RevenueSharingIntegration.t.sol b/packages/contracts-bedrock/test/L2/RevenueSharingIntegration.t.sol index 5484029d752..777b0ffa942 100644 --- a/packages/contracts-bedrock/test/L2/RevenueSharingIntegration.t.sol +++ b/packages/contracts-bedrock/test/L2/RevenueSharingIntegration.t.sol @@ -8,7 +8,6 @@ import { IFeeVault } from "interfaces/L2/IFeeVault.sol"; import { Predeploys } from "src/libraries/Predeploys.sol"; import { Types } from "src/libraries/Types.sol"; import { ICrossDomainMessenger } from "interfaces/universal/ICrossDomainMessenger.sol"; -import { DevFeatures } from "src/libraries/DevFeatures.sol"; /// @title RevenueSharingIntegration_Test /// @notice Integration tests for the complete revenue sharing system including @@ -26,10 +25,6 @@ contract RevenueSharingIntegration_Test is CommonTest { event FundsReceived(address indexed sender, uint256 amount, uint256 newBalance); function setUp() public override { - // Resolve features and skip whole test suite if custom gas token is enabled - resolveFeaturesFromEnv(); - skipIfDevFeatureEnabled(DevFeatures.CUSTOM_GAS_TOKEN); - // Enable revenue sharing before calling parent setUp super.enableRevenueShare(); super.setUp(); diff --git a/packages/contracts-bedrock/test/L2/SuperchainRevSharesCalculator.t.sol b/packages/contracts-bedrock/test/L2/SuperchainRevSharesCalculator.t.sol index c801ae37308..9f08bdc33ac 100644 --- a/packages/contracts-bedrock/test/L2/SuperchainRevSharesCalculator.t.sol +++ b/packages/contracts-bedrock/test/L2/SuperchainRevSharesCalculator.t.sol @@ -8,9 +8,6 @@ import { CommonTest } from "test/setup/CommonTest.sol"; import { ISharesCalculator } from "interfaces/L2/ISharesCalculator.sol"; import { ISuperchainRevSharesCalculator } from "interfaces/L2/ISuperchainRevSharesCalculator.sol"; -// Libraries -import { DevFeatures } from "src/libraries/DevFeatures.sol"; - /// @notice Base setup contract for SuperchainRevSharesCalculator tests. contract SuperchainRevSharesCalculator_TestInit is CommonTest { uint256 internal constant BASIS_POINT_SCALE = 10_000; @@ -24,10 +21,6 @@ contract SuperchainRevSharesCalculator_TestInit is CommonTest { event RemainderRecipientUpdated(address indexed oldRemainderRecipient, address indexed newRemainderRecipient); function setUp() public virtual override { - // Resolve features and skip whole test suite if custom gas token is enabled - resolveFeaturesFromEnv(); - skipIfDevFeatureEnabled(DevFeatures.CUSTOM_GAS_TOKEN); - // Enable revenue sharing before calling parent setUp super.enableRevenueShare(); super.setUp(); diff --git a/packages/contracts-bedrock/test/invariants/CustomGasToken.t.sol b/packages/contracts-bedrock/test/invariants/CustomGasToken.t.sol index fe96f009e30..2e60710b478 100644 --- a/packages/contracts-bedrock/test/invariants/CustomGasToken.t.sol +++ b/packages/contracts-bedrock/test/invariants/CustomGasToken.t.sol @@ -8,7 +8,7 @@ import { CommonTest } from "test/setup/CommonTest.sol"; // Libraries import { Predeploys } from "src/libraries/Predeploys.sol"; -import { DevFeatures } from "src/libraries/DevFeatures.sol"; +import { SafeSend } from "src/universal/SafeSend.sol"; // Contracts import { ILiquidityController } from "interfaces/L2/ILiquidityController.sol"; @@ -103,7 +103,7 @@ contract NativeAssetLiquidity_Fundooor is StdUtils { _amount = bound(_amount, 0, address(this).balance); // action: fund _amount - vm.deal(address(nativeAssetLiquidity), _amount); + new SafeSend{ value: _amount }(payable(address(nativeAssetLiquidity))); // postcondition: nil here (in the invariant tests) // update ghost variables @@ -190,7 +190,7 @@ contract CustomGasToken_Invariants_Test is CommonTest { /// @notice Test setup. function setUp() public override { - skipIfDevFeatureDisabled(DevFeatures.CUSTOM_GAS_TOKEN); + super.enableCustomGasToken(); super.setUp(); randomActor = new RandomActor(); diff --git a/packages/contracts-bedrock/test/invariants/FeeSplit.t.sol b/packages/contracts-bedrock/test/invariants/FeeSplit.t.sol index 0ddacddd82b..f8d36eb6b19 100644 --- a/packages/contracts-bedrock/test/invariants/FeeSplit.t.sol +++ b/packages/contracts-bedrock/test/invariants/FeeSplit.t.sol @@ -10,7 +10,6 @@ import { Predeploys } from "src/libraries/Predeploys.sol"; import { IFeeSplitter } from "interfaces/L2/IFeeSplitter.sol"; import { IL1Withdrawer } from "interfaces/L2/IL1Withdrawer.sol"; import { ISuperchainRevSharesCalculator } from "interfaces/L2/ISuperchainRevSharesCalculator.sol"; -import { DevFeatures } from "src/libraries/DevFeatures.sol"; /// @notice A struct to keep track of the state when a disburse call fails struct DisburseFailureState { @@ -215,10 +214,6 @@ contract FeeSplitter_Invariant is CommonTest { /// @notice Setup: enable the revenue share, deploy handlers and target them. function setUp() public override { - // Resolve features and skip whole test suite if custom gas token is enabled - resolveFeaturesFromEnv(); - skipIfDevFeatureEnabled(DevFeatures.CUSTOM_GAS_TOKEN); - super.enableRevenueShare(); super.setUp(); diff --git a/packages/contracts-bedrock/test/libraries/Predeploys.t.sol b/packages/contracts-bedrock/test/libraries/Predeploys.t.sol index 590c10395cb..5d7318721ae 100644 --- a/packages/contracts-bedrock/test/libraries/Predeploys.t.sol +++ b/packages/contracts-bedrock/test/libraries/Predeploys.t.sol @@ -9,7 +9,6 @@ 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. @@ -161,13 +160,28 @@ contract Predeploys_Uncategorized_Test is Predeploys_TestInit { function test_predeploys_succeeds() external { _test_predeploys(Fork.ISTHMUS, false, false); } +} + +/// @title Predeploys_UncategorizedCustomGasToken_Test +/// @notice Tests for predeploys using custom gas token. +contract Predeploys_UncategorizedCustomGasToken_Test is Predeploys_TestInit { + /// @notice Test setup. Enabling custom gas token to get all predeploys. + function setUp() public virtual override { + super.enableCustomGasToken(); + super.setUp(); + } /// @notice Tests that the predeploy addresses are set correctly. They have code /// and the proxied accounts have the correct admin. Using custom gas token. - function test_predeploys_customGasToken_succeeds() external { - skipIfDevFeatureDisabled(DevFeatures.CUSTOM_GAS_TOKEN); + function test_predeploysWithCGT_succeeds() external { _test_predeploys(Fork.ISTHMUS, false, true); } + + /// @notice Tests that the predeploy addresses are set correctly. They have code and the + /// proxied accounts have the correct admin. Without CGT. + function test_predeploysWithoutCGT_succeeds() external { + _test_predeploys(Fork.ISTHMUS, false, false); + } } /// @title Predeploys_Interop_Uncategorized_Test diff --git a/packages/contracts-bedrock/test/setup/CommonTest.sol b/packages/contracts-bedrock/test/setup/CommonTest.sol index 3c663b0e83d..0de3edfa2a2 100644 --- a/packages/contracts-bedrock/test/setup/CommonTest.sol +++ b/packages/contracts-bedrock/test/setup/CommonTest.sol @@ -14,7 +14,6 @@ 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"; @@ -36,7 +35,7 @@ abstract contract CommonTest is Test, Setup, Events { bool useAltDAOverride; bool useInteropOverride; bool useRevenueShareOverride; - bool useCustomGasToken; + bool useCustomGasTokenOverride; /// @dev This value is only used in forked tests. During forked tests, the default is to perform the upgrade before /// running the tests. @@ -86,7 +85,7 @@ abstract contract CommonTest is Test, Setup, Events { if (useUpgradedFork) { deploy.cfg().setUseUpgradedFork(true); } - if (isDevFeatureEnabled(DevFeatures.CUSTOM_GAS_TOKEN)) { + if (useCustomGasTokenOverride) { console.log("CommonTest: enabling custom gas token"); deploy.cfg().setUseCustomGasToken(true); deploy.cfg().setGasPayingTokenName("Custom Gas Token"); @@ -229,6 +228,12 @@ abstract contract CommonTest is Test, Setup, Events { useRevenueShareOverride = true; } + /// @dev Enables custom gas token mode for testing + function enableCustomGasToken() public { + _checkNotDeployed("custom gas token"); + useCustomGasTokenOverride = true; + } + /// @dev Disables upgrade mode for testing. By default the fork testing env will be upgraded to the latest /// implementation. This can be used to disable the upgrade which, is useful for tests targeting the upgrade /// process itself. diff --git a/packages/contracts-bedrock/test/setup/FeatureFlags.sol b/packages/contracts-bedrock/test/setup/FeatureFlags.sol index 2f71edac4f7..10f2d20ffa6 100644 --- a/packages/contracts-bedrock/test/setup/FeatureFlags.sol +++ b/packages/contracts-bedrock/test/setup/FeatureFlags.sol @@ -44,10 +44,6 @@ abstract contract FeatureFlags { console.log("Setup: DEV_FEATURE__DEPLOY_V2_DISPUTE_GAMES is enabled"); devFeatureBitmap |= DevFeatures.DEPLOY_V2_DISPUTE_GAMES; } - if (Config.devFeatureCustomGasToken()) { - console.log("Setup: DEV_FEATURE__CUSTOM_GAS_TOKEN is enabled"); - devFeatureBitmap |= DevFeatures.CUSTOM_GAS_TOKEN; - } if (Config.devFeatureOpcmV2()) { // WARNING: OPCMv2 also automatically implies DEPLOY_V2_DISPUTE_GAMES and CANNON_KONA. console.log("Setup: DEV_FEATURE__OPCM_V2 is enabled");