Skip to content

Commit 324ed7f

Browse files
chore: fix incorrect contract name when using another artifact
1 parent 8f9e942 commit 324ed7f

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

script/libraries/LibInitializeGuard.sol

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,27 @@ library LibInitializeGuard {
327327
function _getContractAbsolutePath(uint256 forkId, address addr) private view returns (string memory contractName) {
328328
TNetwork networkType = vme.getNetworkTypeByForkId(forkId);
329329
TContract contractType = vme.getContractTypeByRawData(networkType, addr);
330-
contractName = vme.getContractAbsolutePath(contractType);
330+
string memory contractTypeName = vme.getContractName(contractType);
331+
string memory contractNameMap = _getContractNameFromAbsolutePath(vme.getContractAbsolutePath(contractType));
332+
contractName =
333+
(keccak256(bytes(contractNameMap)) == keccak256(bytes(contractTypeName))) ? contractTypeName : contractNameMap;
334+
}
335+
336+
function _getContractNameFromAbsolutePath(string memory path) internal pure returns (string memory contractName) {
337+
bytes memory pathBytes = bytes(path);
338+
uint256 length = pathBytes.length;
339+
bytes memory contractNameBytes = new bytes(length - 4);
340+
341+
if (
342+
length > 4 && pathBytes[length - 4] == "." && pathBytes[length - 3] == "s" && pathBytes[length - 2] == "o"
343+
&& pathBytes[length - 1] == "l"
344+
) {
345+
// Create a new bytes array without the ".sol" extension
346+
for (uint256 i = 0; i < length - 4; i++) {
347+
contractNameBytes[i] = pathBytes[i];
348+
}
349+
}
350+
return string(contractNameBytes);
331351
}
332352

333353
/**

0 commit comments

Comments
 (0)