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";
import { Constants } from "src/libraries/Constants.sol";
import { L1StandardBridge } from "src/L1/L1StandardBridge.sol";
import { L2OutputOracle } from "src/L1/L2OutputOracle.sol";
import { DisputeGameFactory } from "src/dispute/DisputeGameFactory.sol";
import { ProtocolVersion, ProtocolVersions } from "src/L1/ProtocolVersions.sol";
import { SuperchainConfig } from "src/L1/SuperchainConfig.sol";
import { OptimismPortal } from "src/L1/OptimismPortal.sol";
......@@ -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
function checkL2OutputOracle(
Types.ContractSet memory _contracts,
......
......@@ -639,8 +639,12 @@ contract Deploy is Deployer {
DisputeGameFactory factory = new DisputeGameFactory{ salt: _implSalt() }();
save("DisputeGameFactory", 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);
}
......@@ -787,8 +791,8 @@ contract Deploy is Deployer {
string memory version = DisputeGameFactory(disputeGameFactoryProxy).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
......@@ -1089,6 +1093,7 @@ contract Deploy is Deployer {
disputeGameFactory.transferOwnership(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
......
......@@ -68,6 +68,22 @@ contract Initializer_Test is Bridge_Initializer {
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
contracts.push(
InitializeableContract({
......@@ -92,6 +108,16 @@ contract Initializer_Test is Bridge_Initializer {
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
contracts.push(
InitializeableContract({
......@@ -271,9 +297,9 @@ contract Initializer_Test is Bridge_Initializer {
/// 3. The `initialize()` function of each contract cannot be called more than once.
function test_cannotReinitialize_succeeds() public {
// Ensure that all L1, L2 `Initializable` contracts are accounted for, in addition to
// OptimismMintableERC20FactoryImpl and OptimismMintableERC20FactoryProxy.
// TODO: Add `OptimismPortal2` and `OptimismPortal2Proxy` once the deployment scripts are updated.
assertEq(_getNumInitializable(), contracts.length);
// OptimismMintableERC20FactoryImpl, OptimismMintableERC20FactoryProxy, OptimismPortal2, DisputeGameFactoryImpl
// and DisputeGameFactoryProxy
assertEq(_getNumInitializable() + 3, contracts.length);
// Attempt to re-initialize all contracts within the `contracts` array.
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