Skip to content

Commit

Permalink
feat: Add _removeSuffix
Browse files Browse the repository at this point in the history
  • Loading branch information
maurelian committed Jan 6, 2025
1 parent 25c535f commit 050944f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
5 changes: 1 addition & 4 deletions packages/contracts-bedrock/test/L2/Predeploys.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
Expand Down
25 changes: 14 additions & 11 deletions packages/contracts-bedrock/test/vendor/Initializable.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit 050944f

Please sign in to comment.