github.com/ethereum-optimism/optimism@v1.7.2/packages/contracts-bedrock/test/setup/CommonTest.sol (about)

     1  // SPDX-License-Identifier: MIT
     2  pragma solidity 0.8.15;
     3  
     4  import { Test } from "forge-std/Test.sol";
     5  import { Setup } from "test/setup/Setup.sol";
     6  import { Events } from "test/setup/Events.sol";
     7  import { FFIInterface } from "test/setup/FFIInterface.sol";
     8  import "scripts/DeployConfig.s.sol";
     9  
    10  /// @title CommonTest
    11  /// @dev An extenstion to `Test` that sets up the optimism smart contracts.
    12  contract CommonTest is Test, Setup, Events {
    13      address alice;
    14      address bob;
    15  
    16      bytes32 constant nonZeroHash = keccak256(abi.encode("NON_ZERO"));
    17  
    18      FFIInterface constant ffi = FFIInterface(address(uint160(uint256(keccak256(abi.encode("optimism.ffi"))))));
    19  
    20      bool usePlasmaOverride;
    21  
    22      function setUp() public virtual override {
    23          alice = makeAddr("alice");
    24          bob = makeAddr("bob");
    25          vm.deal(alice, 10000 ether);
    26          vm.deal(bob, 10000 ether);
    27  
    28          Setup.setUp();
    29  
    30          // Override the plasma config after the deploy script initialized the config
    31          if (usePlasmaOverride) {
    32              deploy.cfg().setUsePlasma(true);
    33          }
    34  
    35          vm.etch(address(ffi), vm.getDeployedCode("FFIInterface.sol:FFIInterface"));
    36          vm.label(address(ffi), "FFIInterface");
    37  
    38          // Exclude contracts for the invariant tests
    39          excludeContract(address(ffi));
    40          excludeContract(address(deploy));
    41          excludeContract(address(deploy.cfg()));
    42  
    43          // Make sure the base fee is non zero
    44          vm.fee(1 gwei);
    45  
    46          // Set sane initialize block numbers
    47          vm.warp(deploy.cfg().l2OutputOracleStartingTimestamp() + 1);
    48          vm.roll(deploy.cfg().l2OutputOracleStartingBlockNumber() + 1);
    49  
    50          // Deploy L1
    51          Setup.L1();
    52          // Deploy L2
    53          Setup.L2();
    54      }
    55  
    56      /// @dev Helper function that wraps `TransactionDeposited` event.
    57      ///      The magic `0` is the version.
    58      function emitTransactionDeposited(
    59          address _from,
    60          address _to,
    61          uint256 _mint,
    62          uint256 _value,
    63          uint64 _gasLimit,
    64          bool _isCreation,
    65          bytes memory _data
    66      )
    67          internal
    68      {
    69          emit TransactionDeposited(_from, _to, 0, abi.encodePacked(_mint, _value, _gasLimit, _isCreation, _data));
    70      }
    71  
    72      // @dev Advance the evm's time to meet the L2OutputOracle's requirements for proposeL2Output
    73      function warpToProposeTime(uint256 _nextBlockNumber) public {
    74          vm.warp(l2OutputOracle.computeL2Timestamp(_nextBlockNumber) + 1);
    75      }
    76  
    77      /// @dev Helper function to propose an output.
    78      function proposeAnotherOutput() public {
    79          bytes32 proposedOutput2 = keccak256(abi.encode());
    80          uint256 nextBlockNumber = l2OutputOracle.nextBlockNumber();
    81          uint256 nextOutputIndex = l2OutputOracle.nextOutputIndex();
    82          warpToProposeTime(nextBlockNumber);
    83          uint256 proposedNumber = l2OutputOracle.latestBlockNumber();
    84  
    85          uint256 submissionInterval = deploy.cfg().l2OutputOracleSubmissionInterval();
    86          // Ensure the submissionInterval is enforced
    87          assertEq(nextBlockNumber, proposedNumber + submissionInterval);
    88  
    89          vm.roll(nextBlockNumber + 1);
    90  
    91          vm.expectEmit(true, true, true, true);
    92          emit OutputProposed(proposedOutput2, nextOutputIndex, nextBlockNumber, block.timestamp);
    93  
    94          address proposer = deploy.cfg().l2OutputOracleProposer();
    95          vm.prank(proposer);
    96          l2OutputOracle.proposeL2Output(proposedOutput2, nextBlockNumber, 0, 0);
    97      }
    98  
    99      function enableFaultProofs() public {
   100          // Check if the system has already been deployed, based off of the heuristic that alice and bob have not been
   101          // set by the `setUp` function yet.
   102          if (!(alice == address(0) && bob == address(0))) {
   103              revert("CommonTest: Cannot enable fault proofs after deployment. Consider overriding `setUp`.");
   104          }
   105  
   106          // Set `useFaultProofs` to `true` in the deploy config so that the deploy script deploys the Fault Proof system.
   107          // This directly overrides the deploy config's `useFaultProofs` value, if the test requires it.
   108          vm.store(
   109              address(uint160(uint256(keccak256(abi.encode("optimism.deployconfig"))))),
   110              USE_FAULT_PROOFS_SLOT,
   111              bytes32(uint256(1))
   112          );
   113      }
   114  
   115      function enablePlasma() public {
   116          // Check if the system has already been deployed, based off of the heuristic that alice and bob have not been
   117          // set by the `setUp` function yet.
   118          if (!(alice == address(0) && bob == address(0))) {
   119              revert("CommonTest: Cannot enable plasma after deployment. Consider overriding `setUp`.");
   120          }
   121  
   122          usePlasmaOverride = true;
   123      }
   124  }