From 050944f08e8ba1cfddb27726d01fce03d1f3023b Mon Sep 17 00:00:00 2001 From: Maurelian Date: Fri, 3 Jan 2025 20:49:12 -0500 Subject: [PATCH] feat: Add _removeSuffix --- .../test/L2/Predeploys.t.sol | 5 +--- .../test/vendor/Initializable.t.sol | 25 +++++++++++-------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/contracts-bedrock/test/L2/Predeploys.t.sol b/packages/contracts-bedrock/test/L2/Predeploys.t.sol index ebf3eb019f1a..ccbe0ff9fa24 100644 --- a/packages/contracts-bedrock/test/L2/Predeploys.t.sol +++ b/packages/contracts-bedrock/test/L2/Predeploys.t.sol @@ -106,10 +106,7 @@ contract PredeploysBaseTest is CommonTest { } if (_isInitializable(addr)) { - assertEq(l2Genesis.loadInitializedSlot({ - _sourceName: cname, - _deploymentName: cname - }), uint8(1)); + assertEq(l2Genesis.loadInitializedSlot({ _sourceName: cname, _deploymentName: cname }), uint8(1)); } } } diff --git a/packages/contracts-bedrock/test/vendor/Initializable.t.sol b/packages/contracts-bedrock/test/vendor/Initializable.t.sol index ac52676171ed..382b18d61b49 100644 --- a/packages/contracts-bedrock/test/vendor/Initializable.t.sol +++ b/packages/contracts-bedrock/test/vendor/Initializable.t.sol @@ -416,19 +416,12 @@ contract Initializer_Test is CommonTest { for (uint256 i; i < contracts.length; i++) { InitializeableContract memory _contract = contracts[i]; string memory deploymentName = _getRealContractName(_contract.name); - string memory sourceName = deploymentName; // Grab the value of the "initialized" storage slot. - // Check if the contract name ends with `Proxy` and, if so override the contract name which is used to - // retrieve the storage layout. - if (LibString.endsWith(deploymentName, "Proxy")) { - sourceName = LibString.slice(deploymentName, 0, bytes(deploymentName).length - 5); - } - if (LibString.endsWith(deploymentName, "Impl")) { - sourceName = LibString.slice(deploymentName, 0, bytes(deploymentName).length - 4); - } - uint8 initializedSlotVal; - initializedSlotVal = deploy.loadInitializedSlot(sourceName, deploymentName); + uint8 initializedSlotVal = deploy.loadInitializedSlot({ + _sourceName: _removeSuffix(deploymentName), + _deploymentName: deploymentName + }); // Assert that the contract is already initialized. assertTrue( @@ -481,4 +474,14 @@ contract Initializer_Test is CommonTest { revert("Initializer_Test: Invalid returndata format. Expected `Error(string)`"); } } + + /// @dev Removes the `Proxy` or `Impl` suffix from the contract name. + function _removeSuffix(string memory _contractName) internal pure returns (string memory deploymentName_) { + if (LibString.endsWith(_contractName, "Proxy")) { + deploymentName_ = LibString.slice(_contractName, 0, bytes(_contractName).length - 5); + } + if (LibString.endsWith(_contractName, "Impl")) { + deploymentName_ = LibString.slice(_contractName, 0, bytes(_contractName).length - 4); + } + } }