Skip to content

Commit

Permalink
merge bridge initializer into common test (#12795)
Browse files Browse the repository at this point in the history
* merge bridge initializer into common test

* gas snapshot

* remove duplicate import
  • Loading branch information
AmadiMichael authored Nov 7, 2024
1 parent 04d7972 commit 6ea4e40
Show file tree
Hide file tree
Showing 25 changed files with 136 additions and 149 deletions.
4 changes: 2 additions & 2 deletions packages/contracts-bedrock/.gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ GasBenchMark_L1BlockInterop_SetValuesInterop_Warm:test_setL1BlockValuesInterop_b
GasBenchMark_L1Block_SetValuesEcotone:test_setL1BlockValuesEcotone_benchmark() (gas: 158531)
GasBenchMark_L1Block_SetValuesEcotone_Warm:test_setL1BlockValuesEcotone_benchmark() (gas: 7597)
GasBenchMark_L1CrossDomainMessenger:test_sendMessage_benchmark_0() (gas: 369280)
GasBenchMark_L1CrossDomainMessenger:test_sendMessage_benchmark_1() (gas: 2967420)
GasBenchMark_L1CrossDomainMessenger:test_sendMessage_benchmark_1() (gas: 2967465)
GasBenchMark_L1StandardBridge_Deposit:test_depositERC20_benchmark_0() (gas: 564398)
GasBenchMark_L1StandardBridge_Deposit:test_depositERC20_benchmark_1() (gas: 4076613)
GasBenchMark_L1StandardBridge_Deposit:test_depositETH_benchmark_0() (gas: 467098)
Expand All @@ -14,4 +14,4 @@ GasBenchMark_L1StandardBridge_Finalize:test_finalizeETHWithdrawal_benchmark() (g
GasBenchMark_L2OutputOracle:test_proposeL2Output_benchmark() (gas: 92973)
GasBenchMark_OptimismPortal:test_depositTransaction_benchmark() (gas: 68422)
GasBenchMark_OptimismPortal:test_depositTransaction_benchmark_1() (gas: 68986)
GasBenchMark_OptimismPortal:test_proveWithdrawalTransaction_benchmark() (gas: 155610)
GasBenchMark_OptimismPortal:test_proveWithdrawalTransaction_benchmark() (gas: 155565)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity 0.8.15;

// Testing utilities
import { Bridge_Initializer } from "test/setup/Bridge_Initializer.sol";
import { CommonTest } from "test/setup/CommonTest.sol";
import { Reverter } from "test/mocks/Callers.sol";

// Libraries
Expand All @@ -17,7 +17,7 @@ import { IOptimismPortal } from "src/L1/interfaces/IOptimismPortal.sol";
import { ISuperchainConfig } from "src/L1/interfaces/ISuperchainConfig.sol";
import { ISystemConfig } from "src/L1/interfaces/ISystemConfig.sol";

contract L1CrossDomainMessenger_Test is Bridge_Initializer {
contract L1CrossDomainMessenger_Test is CommonTest {
/// @dev The receiver address
address recipient = address(0xabbaacdc);

Expand Down Expand Up @@ -742,7 +742,7 @@ contract L1CrossDomainMessenger_Test is Bridge_Initializer {

/// @dev A regression test against a reentrancy vulnerability in the CrossDomainMessenger contract, which
/// was possible by intercepting and sandwhiching a signed Safe Transaction to upgrade it.
contract L1CrossDomainMessenger_ReinitReentryTest is Bridge_Initializer {
contract L1CrossDomainMessenger_ReinitReentryTest is CommonTest {
bool attacked;

// Common values used across functions
Expand Down
8 changes: 4 additions & 4 deletions packages/contracts-bedrock/test/L1/L1ERC721Bridge.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity 0.8.15;

// Testing
import { Bridge_Initializer } from "test/setup/Bridge_Initializer.sol";
import { CommonTest } from "test/setup/CommonTest.sol";

// Contracts
import { ERC721 } from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
Expand All @@ -25,7 +25,7 @@ contract TestERC721 is ERC721 {
}
}

contract L1ERC721Bridge_Test is Bridge_Initializer {
contract L1ERC721Bridge_Test is CommonTest {
TestERC721 internal localToken;
TestERC721 internal remoteToken;
uint256 internal constant tokenId = 1;
Expand Down Expand Up @@ -315,7 +315,7 @@ contract L1ERC721Bridge_Test is Bridge_Initializer {
}
}

contract L1ERC721Bridge_Pause_Test is Bridge_Initializer {
contract L1ERC721Bridge_Pause_Test is CommonTest {
/// @dev Verifies that the `paused` accessor returns the same value as the `paused` function of the
/// `superchainConfig`.
function test_paused_succeeds() external view {
Expand Down Expand Up @@ -343,7 +343,7 @@ contract L1ERC721Bridge_Pause_Test is Bridge_Initializer {
}
}

contract L1ERC721Bridge_Pause_TestFail is Bridge_Initializer {
contract L1ERC721Bridge_Pause_TestFail is CommonTest {
/// @dev Sets up the test by pausing the bridge, giving ether to the bridge and mocking
/// the calls to the xDomainMessageSender so that it returns the correct value.
function setUp() public override {
Expand Down
42 changes: 21 additions & 21 deletions packages/contracts-bedrock/test/L1/L1StandardBridge.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity 0.8.15;

// Testing
import { stdStorage, StdStorage } from "forge-std/Test.sol";
import { Bridge_Initializer } from "test/setup/Bridge_Initializer.sol";
import { CommonTest } from "test/setup/CommonTest.sol";

// Contracts
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
Expand All @@ -19,7 +19,7 @@ import { ISuperchainConfig } from "src/L1/interfaces/ISuperchainConfig.sol";
import { IOptimismPortal } from "src/L1/interfaces/IOptimismPortal.sol";
import { IL1StandardBridge } from "src/L1/interfaces/IL1StandardBridge.sol";

contract L1StandardBridge_Getter_Test is Bridge_Initializer {
contract L1StandardBridge_Getter_Test is CommonTest {
/// @dev Test that the accessors return the correct initialized values.
function test_getters_succeeds() external view {
assert(l1StandardBridge.l2TokenBridge() == address(l2StandardBridge));
Expand All @@ -31,7 +31,7 @@ contract L1StandardBridge_Getter_Test is Bridge_Initializer {
}
}

contract L1StandardBridge_Initialize_Test is Bridge_Initializer {
contract L1StandardBridge_Initialize_Test is CommonTest {
/// @dev Test that the constructor sets the correct values.
/// @notice Marked virtual to be overridden in
/// test/kontrol/deployment/DeploymentSummary.t.sol
Expand All @@ -58,7 +58,7 @@ contract L1StandardBridge_Initialize_Test is Bridge_Initializer {
}
}

contract L1StandardBridge_Pause_Test is Bridge_Initializer {
contract L1StandardBridge_Pause_Test is CommonTest {
/// @dev Verifies that the `paused` accessor returns the same value as the `paused` function of the
/// `superchainConfig`.
function test_paused_succeeds() external view {
Expand Down Expand Up @@ -86,7 +86,7 @@ contract L1StandardBridge_Pause_Test is Bridge_Initializer {
}
}

contract L1StandardBridge_Pause_TestFail is Bridge_Initializer {
contract L1StandardBridge_Pause_TestFail is CommonTest {
/// @dev Sets up the test by pausing the bridge, giving ether to the bridge and mocking
/// the calls to the xDomainMessageSender so that it returns the correct value.
function setUp() public override {
Expand Down Expand Up @@ -157,9 +157,9 @@ contract L1StandardBridge_Pause_TestFail is Bridge_Initializer {
}
}

contract L1StandardBridge_Initialize_TestFail is Bridge_Initializer { }
contract L1StandardBridge_Initialize_TestFail is CommonTest { }

contract L1StandardBridge_Receive_Test is Bridge_Initializer {
contract L1StandardBridge_Receive_Test is CommonTest {
/// @dev Tests receive bridges ETH successfully.
function test_receive_succeeds() external {
assertEq(address(optimismPortal).balance, 0);
Expand Down Expand Up @@ -190,7 +190,7 @@ contract L1StandardBridge_Receive_Test is Bridge_Initializer {
}
}

contract L1StandardBridge_Receive_TestFail is Bridge_Initializer {
contract L1StandardBridge_Receive_TestFail is CommonTest {
/// @dev Tests receive function reverts with custom gas token.
function testFuzz_receive_customGasToken_reverts(uint256 _value) external {
vm.prank(alice, alice);
Expand All @@ -207,7 +207,7 @@ contract L1StandardBridge_Receive_TestFail is Bridge_Initializer {
}
}

contract PreBridgeETH is Bridge_Initializer {
contract PreBridgeETH is CommonTest {
/// @dev Asserts the expected calls and events for bridging ETH depending
/// on whether the bridge call is legacy or not.
function _preBridgeETH(bool isLegacy, uint256 value) internal {
Expand Down Expand Up @@ -285,7 +285,7 @@ contract L1StandardBridge_DepositETH_Test is PreBridgeETH {
}
}

contract L1StandardBridge_DepositETH_TestFail is Bridge_Initializer {
contract L1StandardBridge_DepositETH_TestFail is CommonTest {
/// @dev Tests that depositing ETH reverts if the call is not from an EOA.
function test_depositETH_notEoa_reverts() external {
vm.etch(alice, address(L1Token).code);
Expand Down Expand Up @@ -331,7 +331,7 @@ contract L1StandardBridge_BridgeETH_TestFail is PreBridgeETH {
}
}

contract PreBridgeETHTo is Bridge_Initializer {
contract PreBridgeETHTo is CommonTest {
/// @dev Asserts the expected calls and events for bridging ETH to a different
/// address depending on whether the bridge call is legacy or not.
function _preBridgeETHTo(bool isLegacy, uint256 value) internal {
Expand Down Expand Up @@ -411,7 +411,7 @@ contract L1StandardBridge_DepositETHTo_Test is PreBridgeETHTo {
}
}

contract L1StandardBridge_DepositETHTo_TestFail is Bridge_Initializer {
contract L1StandardBridge_DepositETHTo_TestFail is CommonTest {
/// @dev Tests that depositETHTo reverts with custom gas token.
function testFuzz_depositETHTo_customGasToken_reverts(
uint256 _value,
Expand Down Expand Up @@ -463,7 +463,7 @@ contract L1StandardBridge_BridgeETHTo_TestFail is PreBridgeETHTo {
}
}

contract L1StandardBridge_DepositERC20_Test is Bridge_Initializer {
contract L1StandardBridge_DepositERC20_Test is CommonTest {
using stdStorage for StdStorage;

// depositERC20
Expand Down Expand Up @@ -540,7 +540,7 @@ contract L1StandardBridge_DepositERC20_Test is Bridge_Initializer {
}
}

contract L1StandardBridge_DepositERC20_TestFail is Bridge_Initializer {
contract L1StandardBridge_DepositERC20_TestFail is CommonTest {
/// @dev Tests that depositing an ERC20 to the bridge reverts
/// if the caller is not an EOA.
function test_depositERC20_notEoa_reverts() external {
Expand All @@ -553,7 +553,7 @@ contract L1StandardBridge_DepositERC20_TestFail is Bridge_Initializer {
}
}

contract L1StandardBridge_DepositERC20To_Test is Bridge_Initializer {
contract L1StandardBridge_DepositERC20To_Test is CommonTest {
/// @dev Tests that depositing ERC20 to the bridge succeeds when
/// sent to a different address.
/// Bridge deposits are updated.
Expand Down Expand Up @@ -622,7 +622,7 @@ contract L1StandardBridge_DepositERC20To_Test is Bridge_Initializer {
}
}

contract L1StandardBridge_FinalizeETHWithdrawal_Test is Bridge_Initializer {
contract L1StandardBridge_FinalizeETHWithdrawal_Test is CommonTest {
using stdStorage for StdStorage;

/// @dev Tests that finalizing an ETH withdrawal succeeds.
Expand Down Expand Up @@ -654,7 +654,7 @@ contract L1StandardBridge_FinalizeETHWithdrawal_Test is Bridge_Initializer {
}
}

contract L1StandardBridge_FinalizeETHWithdrawal_TestFail is Bridge_Initializer {
contract L1StandardBridge_FinalizeETHWithdrawal_TestFail is CommonTest {
/// @dev Tests that finalizeETHWithdrawal reverts with custom gas token.
function testFuzz_finalizeETHWithdrawal_customGasToken_reverts(
uint256 _value,
Expand All @@ -678,7 +678,7 @@ contract L1StandardBridge_FinalizeETHWithdrawal_TestFail is Bridge_Initializer {
}
}

contract L1StandardBridge_FinalizeERC20Withdrawal_Test is Bridge_Initializer {
contract L1StandardBridge_FinalizeERC20Withdrawal_Test is CommonTest {
using stdStorage for StdStorage;

/// @dev Tests that finalizing an ERC20 withdrawal succeeds.
Expand Down Expand Up @@ -717,7 +717,7 @@ contract L1StandardBridge_FinalizeERC20Withdrawal_Test is Bridge_Initializer {
}
}

contract L1StandardBridge_FinalizeERC20Withdrawal_TestFail is Bridge_Initializer {
contract L1StandardBridge_FinalizeERC20Withdrawal_TestFail is CommonTest {
/// @dev Tests that finalizing an ERC20 withdrawal reverts if the caller is not the L2 bridge.
function test_finalizeERC20Withdrawal_notMessenger_reverts() external {
vm.mockCall(
Expand All @@ -743,7 +743,7 @@ contract L1StandardBridge_FinalizeERC20Withdrawal_TestFail is Bridge_Initializer
}
}

contract L1StandardBridge_FinalizeBridgeETH_Test is Bridge_Initializer {
contract L1StandardBridge_FinalizeBridgeETH_Test is CommonTest {
/// @dev Tests that finalizing bridged ETH succeeds.
function test_finalizeBridgeETH_succeeds() external {
address messenger = address(l1StandardBridge.messenger());
Expand All @@ -762,7 +762,7 @@ contract L1StandardBridge_FinalizeBridgeETH_Test is Bridge_Initializer {
}
}

contract L1StandardBridge_FinalizeBridgeETH_TestFail is Bridge_Initializer {
contract L1StandardBridge_FinalizeBridgeETH_TestFail is CommonTest {
/// @dev Tests that finalizing bridged reverts with custom gas token.
function testFuzz_finalizeBridgeETH_customGasToken_reverts(uint256 _value, bytes calldata _extraData) external {
vm.mockCall(
Expand Down
4 changes: 2 additions & 2 deletions packages/contracts-bedrock/test/L2/BaseFeeVault.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
pragma solidity 0.8.15;

// Testing utilities
import { Bridge_Initializer } from "test/setup/Bridge_Initializer.sol";
import { CommonTest } from "test/setup/CommonTest.sol";

// Libraries
import { Types } from "src/libraries/Types.sol";

// Test the implementations of the FeeVault
contract FeeVault_Test is Bridge_Initializer {
contract FeeVault_Test is CommonTest {
/// @dev Tests that the constructor sets the correct values.
function test_constructor_baseFeeVault_succeeds() external view {
assertEq(baseFeeVault.RECIPIENT(), deploy.cfg().baseFeeVaultRecipient());
Expand Down
4 changes: 2 additions & 2 deletions packages/contracts-bedrock/test/L2/CrossDomainOwnable2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity 0.8.15;

// Testing utilities
import { Bridge_Initializer } from "test/setup/Bridge_Initializer.sol";
import { CommonTest } from "test/setup/CommonTest.sol";

// Libraries
import { Hashing } from "src/libraries/Hashing.sol";
Expand All @@ -23,7 +23,7 @@ contract XDomainSetter2 is CrossDomainOwnable2 {
}
}

contract CrossDomainOwnable2_Test is Bridge_Initializer {
contract CrossDomainOwnable2_Test is CommonTest {
XDomainSetter2 setter;

/// @dev Sets up the test suite.
Expand Down
4 changes: 2 additions & 2 deletions packages/contracts-bedrock/test/L2/CrossDomainOwnable3.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity 0.8.15;

// Testing utilities
import { Bridge_Initializer } from "test/setup/Bridge_Initializer.sol";
import { CommonTest } from "test/setup/CommonTest.sol";

// Libraries
import { Hashing } from "src/libraries/Hashing.sol";
Expand All @@ -23,7 +23,7 @@ contract XDomainSetter3 is CrossDomainOwnable3 {
}
}

contract CrossDomainOwnable3_Test is Bridge_Initializer {
contract CrossDomainOwnable3_Test is CommonTest {
XDomainSetter3 setter;

/// @dev CrossDomainOwnable3.sol transferOwnership event
Expand Down
4 changes: 2 additions & 2 deletions packages/contracts-bedrock/test/L2/L1FeeVault.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
pragma solidity 0.8.15;

// Testing utilities
import { Bridge_Initializer } from "test/setup/Bridge_Initializer.sol";
import { CommonTest } from "test/setup/CommonTest.sol";

// Libraries
import { Types } from "src/libraries/Types.sol";

// Test the implementations of the FeeVault
contract FeeVault_Test is Bridge_Initializer {
contract FeeVault_Test is CommonTest {
/// @dev Tests that the constructor sets the correct values.
function test_constructor_l1FeeVault_succeeds() external view {
assertEq(l1FeeVault.RECIPIENT(), deploy.cfg().l1FeeVaultRecipient());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity 0.8.15;

// Testing
import { Bridge_Initializer } from "test/setup/Bridge_Initializer.sol";
import { CommonTest } from "test/setup/CommonTest.sol";
import { Reverter } from "test/mocks/Callers.sol";
import { EIP1967Helper } from "test/mocks/EIP1967Helper.sol";

Expand All @@ -16,7 +16,7 @@ import { AddressAliasHelper } from "src/vendor/AddressAliasHelper.sol";
import { IL2CrossDomainMessenger } from "src/L2/interfaces/IL2CrossDomainMessenger.sol";
import { IL2ToL1MessagePasser } from "src/L2/interfaces/IL2ToL1MessagePasser.sol";

contract L2CrossDomainMessenger_Test is Bridge_Initializer {
contract L2CrossDomainMessenger_Test is CommonTest {
/// @dev Receiver address for testing
address recipient = address(0xabbaacdc);

Expand Down
4 changes: 2 additions & 2 deletions packages/contracts-bedrock/test/L2/L2ERC721Bridge.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity 0.8.15;

// Testing
import { Bridge_Initializer } from "test/setup/Bridge_Initializer.sol";
import { CommonTest } from "test/setup/CommonTest.sol";

// Contracts
import { ERC721 } from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
Expand Down Expand Up @@ -33,7 +33,7 @@ contract TestMintableERC721 is OptimismMintableERC721 {
}
}

contract L2ERC721Bridge_Test is Bridge_Initializer {
contract L2ERC721Bridge_Test is CommonTest {
TestMintableERC721 internal localToken;
TestERC721 internal remoteToken;
uint256 internal constant tokenId = 1;
Expand Down
Loading

0 comments on commit 6ea4e40

Please sign in to comment.