Commit 90a344fe authored by clabby's avatar clabby Committed by GitHub

feat(ctb): ChainAssertions and Initializer tests for `DisputeGameFactory` (#9425)

* `ChainAssertions` and initializer test for DGF

* lint
parent 65c9a4a1
...@@ -9,6 +9,7 @@ import { SystemConfig } from "src/L1/SystemConfig.sol"; ...@@ -9,6 +9,7 @@ import { SystemConfig } from "src/L1/SystemConfig.sol";
import { Constants } from "src/libraries/Constants.sol"; import { Constants } from "src/libraries/Constants.sol";
import { L1StandardBridge } from "src/L1/L1StandardBridge.sol"; import { L1StandardBridge } from "src/L1/L1StandardBridge.sol";
import { L2OutputOracle } from "src/L1/L2OutputOracle.sol"; import { L2OutputOracle } from "src/L1/L2OutputOracle.sol";
import { DisputeGameFactory } from "src/dispute/DisputeGameFactory.sol";
import { ProtocolVersion, ProtocolVersions } from "src/L1/ProtocolVersions.sol"; import { ProtocolVersion, ProtocolVersions } from "src/L1/ProtocolVersions.sol";
import { SuperchainConfig } from "src/L1/SuperchainConfig.sol"; import { SuperchainConfig } from "src/L1/SuperchainConfig.sol";
import { OptimismPortal } from "src/L1/OptimismPortal.sol"; import { OptimismPortal } from "src/L1/OptimismPortal.sol";
...@@ -166,6 +167,14 @@ library ChainAssertions { ...@@ -166,6 +167,14 @@ library ChainAssertions {
} }
} }
/// @notice Asserts that the DisputeGameFactory is setup correctly
function checkDisputeGameFactory(Types.ContractSet memory _contracts, address _expectedOwner) internal view {
console.log("Running chain assertions on the DisputeGameFactory");
DisputeGameFactory factory = DisputeGameFactory(_contracts.DisputeGameFactory);
require(factory.owner() == _expectedOwner);
}
/// @notice Asserts that the L2OutputOracle is setup correctly /// @notice Asserts that the L2OutputOracle is setup correctly
function checkL2OutputOracle( function checkL2OutputOracle(
Types.ContractSet memory _contracts, Types.ContractSet memory _contracts,
......
...@@ -639,8 +639,12 @@ contract Deploy is Deployer { ...@@ -639,8 +639,12 @@ contract Deploy is Deployer {
DisputeGameFactory factory = new DisputeGameFactory{ salt: _implSalt() }(); DisputeGameFactory factory = new DisputeGameFactory{ salt: _implSalt() }();
save("DisputeGameFactory", address(factory)); save("DisputeGameFactory", address(factory));
console.log("DisputeGameFactory deployed at %s", address(factory)); console.log("DisputeGameFactory deployed at %s", address(factory));
// TODO: Run the checkDisputeGameFactory function here.
// @see https://github.com/ethereum-optimism/optimism/issues/9354 // Override the `DisputeGameFactory` contract to the deployed implementation. This is necessary to check the
// `DisputeGameFactory` implementation alongside dependent contracts, which are always proxies.
Types.ContractSet memory contracts = _proxiesUnstrict();
contracts.DisputeGameFactory = address(factory);
ChainAssertions.checkDisputeGameFactory({ _contracts: contracts, _expectedOwner: address(0) });
addr_ = address(factory); addr_ = address(factory);
} }
...@@ -787,8 +791,8 @@ contract Deploy is Deployer { ...@@ -787,8 +791,8 @@ contract Deploy is Deployer {
string memory version = DisputeGameFactory(disputeGameFactoryProxy).version(); string memory version = DisputeGameFactory(disputeGameFactoryProxy).version();
console.log("DisputeGameFactory version: %s", version); console.log("DisputeGameFactory version: %s", version);
// TODO: Run the checkDisputeGameFactory function here.
// @see https://github.com/ethereum-optimism/optimism/issues/9354 ChainAssertions.checkDisputeGameFactory({ _contracts: _proxiesUnstrict(), _expectedOwner: msg.sender });
} }
/// @notice Initialize the SystemConfig /// @notice Initialize the SystemConfig
...@@ -1089,6 +1093,7 @@ contract Deploy is Deployer { ...@@ -1089,6 +1093,7 @@ contract Deploy is Deployer {
disputeGameFactory.transferOwnership(safe); disputeGameFactory.transferOwnership(safe);
console.log("DisputeGameFactory ownership transferred to Safe at: %s", safe); console.log("DisputeGameFactory ownership transferred to Safe at: %s", safe);
} }
ChainAssertions.checkDisputeGameFactory({ _contracts: _proxies(), _expectedOwner: safe });
} }
/// @notice Loads the mips absolute prestate from the prestate-proof for devnets otherwise /// @notice Loads the mips absolute prestate from the prestate-proof for devnets otherwise
......
...@@ -68,6 +68,22 @@ contract Initializer_Test is Bridge_Initializer { ...@@ -68,6 +68,22 @@ contract Initializer_Test is Bridge_Initializer {
initializedSlotVal: deploy.loadInitializedSlot("L1CrossDomainMessengerProxy") initializedSlotVal: deploy.loadInitializedSlot("L1CrossDomainMessengerProxy")
}) })
); );
// DisputeGameFactoryImpl
contracts.push(
InitializeableContract({
target: deploy.mustGetAddress("DisputeGameFactory"),
initCalldata: abi.encodeCall(disputeGameFactory.initialize, (address(0))),
initializedSlotVal: deploy.loadInitializedSlot("DisputeGameFactory")
})
);
// DisputeGameFactoryProxy
contracts.push(
InitializeableContract({
target: address(disputeGameFactory),
initCalldata: abi.encodeCall(disputeGameFactory.initialize, (address(0))),
initializedSlotVal: deploy.loadInitializedSlot("DisputeGameFactoryProxy")
})
);
// L2OutputOracleImpl // L2OutputOracleImpl
contracts.push( contracts.push(
InitializeableContract({ InitializeableContract({
...@@ -92,6 +108,16 @@ contract Initializer_Test is Bridge_Initializer { ...@@ -92,6 +108,16 @@ contract Initializer_Test is Bridge_Initializer {
initializedSlotVal: deploy.loadInitializedSlot("OptimismPortal") initializedSlotVal: deploy.loadInitializedSlot("OptimismPortal")
}) })
); );
// OptimismPortal2Impl
contracts.push(
InitializeableContract({
target: deploy.mustGetAddress("OptimismPortal2"),
initCalldata: abi.encodeCall(
optimismPortal2.initialize, (disputeGameFactory, systemConfig, superchainConfig)
),
initializedSlotVal: deploy.loadInitializedSlot("OptimismPortal2")
})
);
// OptimismPortalProxy // OptimismPortalProxy
contracts.push( contracts.push(
InitializeableContract({ InitializeableContract({
...@@ -271,9 +297,9 @@ contract Initializer_Test is Bridge_Initializer { ...@@ -271,9 +297,9 @@ contract Initializer_Test is Bridge_Initializer {
/// 3. The `initialize()` function of each contract cannot be called more than once. /// 3. The `initialize()` function of each contract cannot be called more than once.
function test_cannotReinitialize_succeeds() public { function test_cannotReinitialize_succeeds() public {
// Ensure that all L1, L2 `Initializable` contracts are accounted for, in addition to // Ensure that all L1, L2 `Initializable` contracts are accounted for, in addition to
// OptimismMintableERC20FactoryImpl and OptimismMintableERC20FactoryProxy. // OptimismMintableERC20FactoryImpl, OptimismMintableERC20FactoryProxy, OptimismPortal2, DisputeGameFactoryImpl
// TODO: Add `OptimismPortal2` and `OptimismPortal2Proxy` once the deployment scripts are updated. // and DisputeGameFactoryProxy
assertEq(_getNumInitializable(), contracts.length); assertEq(_getNumInitializable() + 3, contracts.length);
// Attempt to re-initialize all contracts within the `contracts` array. // Attempt to re-initialize all contracts within the `contracts` array.
for (uint256 i; i < contracts.length; i++) { for (uint256 i; i < contracts.length; i++) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment