-
Notifications
You must be signed in to change notification settings - Fork 3.9k
feat: add OPCMv2 tests for existing behaviors #18389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
smartcontracts
wants to merge
4
commits into
develop
Choose a base branch
from
sc/opcm-existing-behavior-tests
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+318
−4
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
189 changes: 189 additions & 0 deletions
189
packages/contracts-bedrock/test/L1/opcm/OPContractsManagerContainer.t.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,189 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity 0.8.15; | ||
|
|
||
| // Testing | ||
| import { Test } from "forge-std/Test.sol"; | ||
|
|
||
| // Contracts | ||
| import { OPContractsManagerContainer } from "src/L1/opcm/OPContractsManagerContainer.sol"; | ||
|
|
||
| // Libraries | ||
| import { Constants } from "src/libraries/Constants.sol"; | ||
|
|
||
| /// @title OPContractsManagerContainer_TestInit | ||
| /// @notice Shared setup for OPContractsManagerContainer tests. | ||
| contract OPContractsManagerContainer_TestInit is Test { | ||
| OPContractsManagerContainer.Blueprints internal blueprints; | ||
| OPContractsManagerContainer.Implementations internal implementations; | ||
|
|
||
| function setUp() public virtual { | ||
| blueprints = OPContractsManagerContainer.Blueprints({ | ||
| addressManager: makeAddr("addressManager"), | ||
| proxy: makeAddr("proxy"), | ||
| proxyAdmin: makeAddr("proxyAdmin"), | ||
| l1ChugSplashProxy: makeAddr("l1ChugSplashProxy"), | ||
| resolvedDelegateProxy: makeAddr("resolvedDelegateProxy"), | ||
| permissionedDisputeGame1: makeAddr("permissionedDisputeGame1"), | ||
| permissionedDisputeGame2: makeAddr("permissionedDisputeGame2"), | ||
| permissionlessDisputeGame1: makeAddr("permissionlessDisputeGame1"), | ||
| permissionlessDisputeGame2: makeAddr("permissionlessDisputeGame2") | ||
| }); | ||
|
|
||
| implementations = OPContractsManagerContainer.Implementations({ | ||
| superchainConfigImpl: makeAddr("superchainConfigImpl"), | ||
| protocolVersionsImpl: makeAddr("protocolVersionsImpl"), | ||
| l1ERC721BridgeImpl: makeAddr("l1ERC721BridgeImpl"), | ||
| optimismPortalImpl: makeAddr("optimismPortalImpl"), | ||
| optimismPortalInteropImpl: makeAddr("optimismPortalInteropImpl"), | ||
| ethLockboxImpl: makeAddr("ethLockboxImpl"), | ||
| systemConfigImpl: makeAddr("systemConfigImpl"), | ||
| optimismMintableERC20FactoryImpl: makeAddr("optimismMintableERC20FactoryImpl"), | ||
| l1CrossDomainMessengerImpl: makeAddr("l1CrossDomainMessengerImpl"), | ||
| l1StandardBridgeImpl: makeAddr("l1StandardBridgeImpl"), | ||
| disputeGameFactoryImpl: makeAddr("disputeGameFactoryImpl"), | ||
| anchorStateRegistryImpl: makeAddr("anchorStateRegistryImpl"), | ||
| delayedWETHImpl: makeAddr("delayedWETHImpl"), | ||
| mipsImpl: makeAddr("mipsImpl"), | ||
| faultDisputeGameV2Impl: makeAddr("faultDisputeGameV2Impl"), | ||
| permissionedDisputeGameV2Impl: makeAddr("permissionedDisputeGameV2Impl"), | ||
| superFaultDisputeGameImpl: makeAddr("superFaultDisputeGameImpl"), | ||
| superPermissionedDisputeGameImpl: makeAddr("superPermissionedDisputeGameImpl"), | ||
| storageSetterImpl: makeAddr("storageSetterImpl") | ||
| }); | ||
| } | ||
|
|
||
| /// @notice Deploys a new OPContractsManagerContainer with the given dev feature bitmap. | ||
| /// @param _devFeatureBitmap The dev feature bitmap to use. | ||
| /// @return The deployed OPContractsManagerContainer. | ||
| function _deploy(bytes32 _devFeatureBitmap) internal returns (OPContractsManagerContainer) { | ||
| return new OPContractsManagerContainer(blueprints, implementations, _devFeatureBitmap); | ||
| } | ||
| } | ||
|
|
||
| /// @title OPContractsManagerContainer_Constructor_Test | ||
| /// @notice Tests the constructor of OPContractsManagerContainer. | ||
| contract OPContractsManagerContainer_Constructor_Test is OPContractsManagerContainer_TestInit { | ||
| /// @notice Tests that the constructor succeeds with any dev bitmap when in a test environment. | ||
| /// @param _devFeatureBitmap The dev feature bitmap to use. | ||
| function testFuzz_constructor_devBitmapInTestEnv_succeeds(bytes32 _devFeatureBitmap) public { | ||
| // Etch code into the magic testing address so we're recognized as a test env. | ||
| vm.etch(Constants.TESTING_ENVIRONMENT_ADDRESS, hex"01"); | ||
|
|
||
| OPContractsManagerContainer container = _deploy(_devFeatureBitmap); | ||
|
|
||
| assertEq(container.devFeatureBitmap(), _devFeatureBitmap); | ||
| } | ||
|
|
||
| /// @notice Tests that the constructor reverts when dev features are enabled on mainnet without | ||
| /// test env. | ||
| /// @param _devFeatureBitmap The dev feature bitmap to use. | ||
| function testFuzz_constructor_devBitmapOnMainnet_reverts(bytes32 _devFeatureBitmap) public { | ||
| // Ensure at least one dev feature is enabled. | ||
| _devFeatureBitmap = bytes32(bound(uint256(_devFeatureBitmap), 1, type(uint256).max)); | ||
|
|
||
| // Clear the magic testing address so we're recognized as production. | ||
| vm.etch(Constants.TESTING_ENVIRONMENT_ADDRESS, hex""); | ||
|
|
||
| // Set chain ID to mainnet. | ||
| vm.chainId(1); | ||
|
|
||
| vm.expectRevert(OPContractsManagerContainer.OPContractsManagerContractsContainer_DevFeatureInProd.selector); | ||
| _deploy(_devFeatureBitmap); | ||
| } | ||
|
|
||
| /// @notice Tests that the constructor succeeds on mainnet when the test env flag is set. | ||
| /// @param _devFeatureBitmap The dev feature bitmap to use. | ||
| function testFuzz_constructor_devBitmapOnMainnetButTestEnv_succeeds(bytes32 _devFeatureBitmap) public { | ||
| // Etch code into the magic testing address. | ||
| vm.etch(Constants.TESTING_ENVIRONMENT_ADDRESS, hex"01"); | ||
|
|
||
| // Set chain ID to mainnet. | ||
| vm.chainId(1); | ||
|
|
||
| OPContractsManagerContainer container = _deploy(_devFeatureBitmap); | ||
|
|
||
| assertEq(container.devFeatureBitmap(), _devFeatureBitmap); | ||
| } | ||
|
|
||
| /// @notice Tests that the constructor succeeds on mainnet with a zero dev bitmap. | ||
| function test_constructor_zeroBitmapOnMainnet_succeeds() public { | ||
| // Clear the magic testing address. | ||
| vm.etch(Constants.TESTING_ENVIRONMENT_ADDRESS, hex""); | ||
|
|
||
| // Set chain ID to mainnet. | ||
| vm.chainId(1); | ||
|
|
||
| OPContractsManagerContainer container = _deploy(bytes32(0)); | ||
|
|
||
| assertEq(container.devFeatureBitmap(), bytes32(0)); | ||
| } | ||
| } | ||
|
|
||
| /// @title OPContractsManagerContainer_Blueprints_Test | ||
| /// @notice Tests the blueprints() getter. | ||
| contract OPContractsManagerContainer_Blueprints_Test is OPContractsManagerContainer_TestInit { | ||
| /// @notice Tests that blueprints() returns the struct provided at construction. | ||
| function test_blueprints_succeeds() public { | ||
| OPContractsManagerContainer container = _deploy(bytes32(0)); | ||
|
|
||
| assertEq(abi.encode(container.blueprints()), abi.encode(blueprints)); | ||
| } | ||
| } | ||
|
|
||
| /// @title OPContractsManagerContainer_Implementations_Test | ||
| /// @notice Tests the implementations() getter. | ||
| contract OPContractsManagerContainer_Implementations_Test is OPContractsManagerContainer_TestInit { | ||
| /// @notice Tests that implementations() returns the struct provided at construction. | ||
| function test_implementations_succeeds() public { | ||
| OPContractsManagerContainer container = _deploy(bytes32(0)); | ||
|
|
||
| assertEq(abi.encode(container.implementations()), abi.encode(implementations)); | ||
| } | ||
| } | ||
|
|
||
| /// @title OPContractsManagerContainer_IsDevFeatureEnabled_Test | ||
| /// @notice Tests the isDevFeatureEnabled() function. | ||
| contract OPContractsManagerContainer_IsDevFeatureEnabled_Test is OPContractsManagerContainer_TestInit { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe a sanity check, this should always hold: |
||
| /// @notice Tests that isDevFeatureEnabled returns true when the feature bit is set. | ||
| /// @param _bitIndex The bit index to test. | ||
| function testFuzz_isDevFeatureEnabled_bitSet_succeeds(uint8 _bitIndex) public { | ||
| bytes32 bitmap = bytes32(uint256(1) << _bitIndex); | ||
| bytes32 feature = bytes32(uint256(1) << _bitIndex); | ||
|
|
||
| OPContractsManagerContainer container = _deploy(bitmap); | ||
|
|
||
| assertTrue(container.isDevFeatureEnabled(feature)); | ||
| } | ||
|
|
||
| /// @notice Tests that isDevFeatureEnabled returns false when the feature bit is not set. | ||
| /// @param _bitIndex The bit index to test. | ||
| function testFuzz_isDevFeatureEnabled_bitNotSet_succeeds(uint8 _bitIndex) public { | ||
| // Create a bitmap with all bits set except the one we're testing. | ||
| bytes32 bitmap = bytes32(type(uint256).max ^ (uint256(1) << _bitIndex)); | ||
| bytes32 feature = bytes32(uint256(1) << _bitIndex); | ||
|
|
||
| OPContractsManagerContainer container = _deploy(bitmap); | ||
|
|
||
| assertFalse(container.isDevFeatureEnabled(feature)); | ||
| } | ||
|
|
||
| /// @notice Tests that isDevFeatureEnabled returns false when the bitmap is zero. | ||
| /// @param _feature The feature to check. | ||
| function testFuzz_isDevFeatureEnabled_zeroBitmap_succeeds(bytes32 _feature) public { | ||
| OPContractsManagerContainer container = _deploy(bytes32(0)); | ||
|
|
||
| assertFalse(container.isDevFeatureEnabled(_feature)); | ||
| } | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe test for when multiple bits are set? |
||
|
|
||
| /// @title OPContractsManagerContainer_DevFeatureBitmap_Test | ||
| /// @notice Tests the devFeatureBitmap() getter. | ||
| contract OPContractsManagerContainer_DevFeatureBitmap_Test is OPContractsManagerContainer_TestInit { | ||
| /// @notice Tests that devFeatureBitmap() returns the value provided at construction. | ||
| /// @param _devFeatureBitmap The dev feature bitmap to use. | ||
| function testFuzz_devFeatureBitmap_succeeds(bytes32 _devFeatureBitmap) public { | ||
| OPContractsManagerContainer container = _deploy(_devFeatureBitmap); | ||
|
|
||
| assertEq(container.devFeatureBitmap(), _devFeatureBitmap); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: should we have this test for non-mainnet chains?