Skip to content

Commit 0899f37

Browse files
committed
chore: update dependencies and improve artifact search logic in Utils.sol
1 parent 20aaa5c commit 0899f37

File tree

3 files changed

+111
-103
lines changed

3 files changed

+111
-103
lines changed

package.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@
2929
"version-package": "bash scripts/release/version.sh",
3030
"publish-package": "bash scripts/release/publish.sh"
3131
},
32-
"devDependencies": {
33-
"@nomicfoundation/hardhat-foundry": "^1.1.1",
34-
"@openzeppelin/contracts": "^5.0.2",
35-
"@openzeppelin/contracts-upgradeable": "^5.0.2",
36-
"@openzeppelin/contracts-v4": "npm:@openzeppelin/contracts@^v4.9.6",
37-
"@openzeppelin/contracts-upgradeable-v4": "npm:@openzeppelin/contracts-upgradeable@^v4.9.6",
38-
"@openzeppelin/defender-deploy-client-cli": "0.0.1-alpha.10",
39-
"@openzeppelin/upgrades-core": "2.0.0-alpha.0",
32+
"devDependencies": {
33+
"@nomicfoundation/hardhat-foundry": "^1.1.1",
34+
"@openzeppelin/contracts": "^5.0.2",
35+
"@openzeppelin/contracts-upgradeable": "^5.0.2",
36+
"@openzeppelin/contracts-v4": "npm:@openzeppelin/contracts@^v4.9.6",
37+
"@openzeppelin/contracts-upgradeable-v4": "npm:@openzeppelin/contracts-upgradeable@^v4.9.6",
38+
"@openzeppelin/defender-deploy-client-cli": "0.0.1-alpha.10",
39+
"@openzeppelin/upgrades-core": "2.0.0-alpha.0",
4040
"hardhat": "^2.21.0",
4141
"prettier": "^3.0.0",
4242
"prettier-plugin-solidity": "^1.1.0",
@@ -46,8 +46,8 @@
4646
"@changesets/cli": "^2.29.3",
4747
"@changesets/changelog-github": "^0.5.1"
4848
},
49-
"peerDependencies": {
50-
"@openzeppelin/defender-deploy-client-cli": "0.0.1-alpha.10",
51-
"@openzeppelin/upgrades-core": "2.0.0-alpha.0"
52-
}
49+
"peerDependencies": {
50+
"@openzeppelin/defender-deploy-client-cli": "0.0.1-alpha.10",
51+
"@openzeppelin/upgrades-core": "2.0.0-alpha.0"
52+
}
5353
}

src/internal/Utils.sol

Lines changed: 65 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ library Utils {
136136

137137
/**
138138
* @dev Recursively searches for artifact file. Fallback for when direct path fails.
139+
* Fails if zero or multiple matches are found to avoid ambiguity.
139140
*/
140141
function _findArtifactRecursive(
141142
Vm vm,
@@ -151,36 +152,87 @@ library Utils {
151152
inputs[5] = string(abi.encodePacked(shortName, ".json"));
152153

153154
Vm.FfiResult memory result = runAsBashCommand(inputs);
154-
if (result.exitCode != 0) {
155+
string memory stdout = string(result.stdout);
156+
157+
// Check for no matches (empty output or find failure)
158+
if (result.exitCode != 0 || bytes(stdout).length == 0) {
159+
revert(
160+
string(abi.encodePacked("Could not find artifact for contract ", shortName, " in directory ", outDir))
161+
);
162+
}
163+
164+
// Split by newlines and filter empty entries
165+
string[] memory lines = vm.split(stdout, "\n");
166+
uint256 matchCount = 0;
167+
string memory firstMatch;
168+
169+
for (uint256 i = 0; i < lines.length; i++) {
170+
if (bytes(lines[i]).length > 0) {
171+
if (matchCount == 0) {
172+
firstMatch = lines[i];
173+
}
174+
matchCount++;
175+
}
176+
}
177+
178+
// Fail on zero matches
179+
if (matchCount == 0) {
155180
revert(
156181
string(abi.encodePacked("Could not find artifact for contract ", shortName, " in directory ", outDir))
157182
);
158183
}
159184

160-
// Get first line only (first match)
161-
string[] memory lines = vm.split(string(result.stdout), "\n");
162-
return lines.length > 0 ? lines[0] : "";
185+
// Fail on multiple matches to avoid ambiguity
186+
if (matchCount > 1) {
187+
revert(
188+
string(
189+
abi.encodePacked(
190+
"Found multiple artifacts for contract ",
191+
shortName,
192+
" in directory ",
193+
outDir,
194+
". Please specify the full contract name in the format 'MyContract.sol:MyContract' or use the artifact path."
195+
)
196+
)
197+
);
198+
}
199+
200+
return firstMatch;
163201
}
164202

165203
using StringFinder for string;
166204

167205
/**
168-
* @dev Gets the build info directory. Detects the environment by checking the outDir value.
169-
* If outDir is not "out", it means the project is using Hardhat (which sets FOUNDRY_OUT=artifacts/contracts),
170-
* so return artifacts/build-info. Otherwise, return the Foundry default outDir/build-info.
206+
* @dev Gets the build info directory. Detects the environment by checking if outDir
207+
* starts with "artifacts/contracts" (Hardhat convention).
171208
*
172209
* @param outDir Foundry output directory (e.g., "out" or "artifacts/contracts")
173210
* @return The path to the build-info directory
174211
*/
175-
function getBuildInfoDir(string memory outDir) internal view returns (string memory) {
176-
// If outDir is not "out", this is likely Hardhat (which uses artifacts/contracts)
177-
// In that case, use artifacts/build-info
178-
if (!Strings.equal(outDir, "out")) {
212+
function getBuildInfoDir(string memory outDir) internal pure returns (string memory) {
213+
// Normalize outDir by removing trailing slash if present
214+
string memory normalizedOutDir = outDir;
215+
if (outDir.endsWith("/")) {
216+
// Remove trailing slash by taking substring
217+
bytes memory outDirBytes = bytes(outDir);
218+
bytes memory trimmed = new bytes(outDirBytes.length - 1);
219+
for (uint256 i = 0; i < trimmed.length; i++) {
220+
trimmed[i] = outDirBytes[i];
221+
}
222+
normalizedOutDir = string(trimmed);
223+
}
224+
225+
// Detect Hardhat specifically by checking for artifacts/contracts prefix
226+
// Hardhat sets FOUNDRY_OUT=artifacts/contracts, and build-info is at artifacts/build-info
227+
if (
228+
StringFinder.startsWith(normalizedOutDir, "artifacts/contracts") ||
229+
StringFinder.startsWith(normalizedOutDir, "artifacts\\contracts")
230+
) {
179231
return "artifacts/build-info";
180232
}
181233

182-
// Default: Foundry uses outDir/build-info
183-
return string(abi.encodePacked(outDir, "/build-info"));
234+
// Default: Foundry uses outDir/build-info (works for custom FOUNDRY_OUT values)
235+
return string(abi.encodePacked(normalizedOutDir, "/build-info"));
184236
}
185237

186238
/**

yarn.lock

Lines changed: 34 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,11 @@
524524
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.27.1.tgz#9fce313d12c9a77507f264de74626e87fd0dc541"
525525
integrity sha512-1x3D2xEk2fRo3PAhwQwu5UubzgiVWSXTBfWpVd2Mx2AzRqJuDJCsgaDVZ7HB5iGzDW1Hl1sWN2mFyKjmR9uAog==
526526

527+
"@bytecodealliance/preview2-shim@0.17.0":
528+
version "0.17.0"
529+
resolved "https://registry.yarnpkg.com/@bytecodealliance/preview2-shim/-/preview2-shim-0.17.0.tgz#9bc1cadbb9f86c446c6f579d3431c08a06a6672e"
530+
integrity sha512-JorcEwe4ud0x5BS/Ar2aQWOQoFzjq/7jcnxYXCvSMh0oRm0dQXzOA+hqLDBnOMks1LLBA7dmiLLsEBl09Yd6iQ==
531+
527532
"@changesets/apply-release-plan@^7.0.12":
528533
version "7.0.12"
529534
resolved "https://registry.yarnpkg.com/@changesets/apply-release-plan/-/apply-release-plan-7.0.12.tgz#8413977f117fa95f6e2db6f0c35479a2eba6960a"
@@ -1080,65 +1085,12 @@
10801085
dependencies:
10811086
chalk "^2.4.2"
10821087

1083-
"@nomicfoundation/slang-darwin-arm64@0.17.0":
1084-
version "0.17.0"
1085-
resolved "https://registry.yarnpkg.com/@nomicfoundation/slang-darwin-arm64/-/slang-darwin-arm64-0.17.0.tgz#8cded3c24322624e3b6618760caba8e840bd1c1d"
1086-
integrity sha512-O0q94EUtoWy9A5kOTOa9/khtxXDYnLqmuda9pQELurSiwbQEVCPQL8kb34VbOW+ifdre66JM/05Xw9JWhIZ9sA==
1087-
1088-
"@nomicfoundation/slang-darwin-x64@0.17.0":
1089-
version "0.17.0"
1090-
resolved "https://registry.yarnpkg.com/@nomicfoundation/slang-darwin-x64/-/slang-darwin-x64-0.17.0.tgz#6ebeb33a2ced89fc6023f6cda4af96403486038a"
1091-
integrity sha512-IaDbHzvT08sBK2HyGzonWhq1uu8IxdjmTqAWHr25Oh/PYnamdi8u4qchZXXYKz/DHLoYN3vIpBXoqLQIomhD/g==
1092-
1093-
"@nomicfoundation/slang-linux-arm64-gnu@0.17.0":
1094-
version "0.17.0"
1095-
resolved "https://registry.yarnpkg.com/@nomicfoundation/slang-linux-arm64-gnu/-/slang-linux-arm64-gnu-0.17.0.tgz#41c7e57a9b1a3aee6911f0cab22e683c149fb470"
1096-
integrity sha512-Lj4anvOsQZxs1SycG8VyT2Rl2oqIhyLSUCgGepTt3CiJ/bM+8r8bLJIgh8vKkki4BWz49YsYIgaJB2IPv8FFTw==
1097-
1098-
"@nomicfoundation/slang-linux-arm64-musl@0.17.0":
1099-
version "0.17.0"
1100-
resolved "https://registry.yarnpkg.com/@nomicfoundation/slang-linux-arm64-musl/-/slang-linux-arm64-musl-0.17.0.tgz#9c4b51689274ae75c2c8a4cddd2e1cc0a79c191d"
1101-
integrity sha512-/xkTCa9d5SIWUBQE3BmLqDFfJRr4yUBwbl4ynPiGUpRXrD69cs6pWKkwjwz/FdBpXqVo36I+zY95qzoTj/YhOA==
1102-
1103-
"@nomicfoundation/slang-linux-x64-gnu@0.17.0":
1104-
version "0.17.0"
1105-
resolved "https://registry.yarnpkg.com/@nomicfoundation/slang-linux-x64-gnu/-/slang-linux-x64-gnu-0.17.0.tgz#c3a3b6a7b775fc617832958d10e6664bf86d39d0"
1106-
integrity sha512-oe5IO5vntOqYvTd67deCHPIWuSuWm6aYtT2/0Kqz2/VLtGz4ClEulBSRwfnNzBVtw2nksWipE1w8BzhImI7Syg==
1107-
1108-
"@nomicfoundation/slang-linux-x64-musl@0.17.0":
1109-
version "0.17.0"
1110-
resolved "https://registry.yarnpkg.com/@nomicfoundation/slang-linux-x64-musl/-/slang-linux-x64-musl-0.17.0.tgz#725118ff99a7217b9f1d1bd84411d9442084077d"
1111-
integrity sha512-PpYCI5K/kgLAMXaPY0V4VST5gCDprEOh7z/47tbI8kJQumI5odjsj/Cs8MpTo7/uRH6flKYbVNgUzcocWVYrAQ==
1112-
1113-
"@nomicfoundation/slang-win32-arm64-msvc@0.17.0":
1114-
version "0.17.0"
1115-
resolved "https://registry.yarnpkg.com/@nomicfoundation/slang-win32-arm64-msvc/-/slang-win32-arm64-msvc-0.17.0.tgz#9c8bc4ccf21eaaac0cfcb6d3954ede4e2dea4c02"
1116-
integrity sha512-u/Mkf7OjokdBilP7QOJj6QYJU4/mjkbKnTX21wLyCIzeVWS7yafRPYpBycKIBj2pRRZ6ceAY5EqRpb0aiCq+0Q==
1117-
1118-
"@nomicfoundation/slang-win32-ia32-msvc@0.17.0":
1119-
version "0.17.0"
1120-
resolved "https://registry.yarnpkg.com/@nomicfoundation/slang-win32-ia32-msvc/-/slang-win32-ia32-msvc-0.17.0.tgz#3fc5d00a3f8c1d85a5e94146af78a5526a4f3d27"
1121-
integrity sha512-XJBVQfNnZQUv0tP2JSJ573S+pmgrLWgqSZOGaMllnB/TL1gRci4Z7dYRJUF2s82GlRJE+FHSI2Ro6JISKmlXCg==
1122-
1123-
"@nomicfoundation/slang-win32-x64-msvc@0.17.0":
1124-
version "0.17.0"
1125-
resolved "https://registry.yarnpkg.com/@nomicfoundation/slang-win32-x64-msvc/-/slang-win32-x64-msvc-0.17.0.tgz#f6a5e3250fa07cbda49151edeb80f09090e5b71a"
1126-
integrity sha512-zPGsAeiTfqfPNYHD8BfrahQmYzA78ZraoHKTGraq/1xwJwzBK4bu/NtvVA4pJjBV+B4L6DCxVhSbpn40q26JQA==
1127-
1128-
"@nomicfoundation/slang@^0.17.0":
1129-
version "0.17.0"
1130-
resolved "https://registry.yarnpkg.com/@nomicfoundation/slang/-/slang-0.17.0.tgz#d9c25cd711ebf3490c9d0c99e9b4ca2481341a6b"
1131-
integrity sha512-1GlkGRcGpVnjFw9Z1vvDKOKo2mzparFt7qrl2pDxWp+jrVtlvej98yCMX52pVyrYE7ZeOSZFnx/DtsSgoukStQ==
1132-
dependencies:
1133-
"@nomicfoundation/slang-darwin-arm64" "0.17.0"
1134-
"@nomicfoundation/slang-darwin-x64" "0.17.0"
1135-
"@nomicfoundation/slang-linux-arm64-gnu" "0.17.0"
1136-
"@nomicfoundation/slang-linux-arm64-musl" "0.17.0"
1137-
"@nomicfoundation/slang-linux-x64-gnu" "0.17.0"
1138-
"@nomicfoundation/slang-linux-x64-musl" "0.17.0"
1139-
"@nomicfoundation/slang-win32-arm64-msvc" "0.17.0"
1140-
"@nomicfoundation/slang-win32-ia32-msvc" "0.17.0"
1141-
"@nomicfoundation/slang-win32-x64-msvc" "0.17.0"
1088+
"@nomicfoundation/slang@^0.18.3":
1089+
version "0.18.3"
1090+
resolved "https://registry.yarnpkg.com/@nomicfoundation/slang/-/slang-0.18.3.tgz#976b6c3820081cebf050afbea434038aac9313cc"
1091+
integrity sha512-YqAWgckqbHM0/CZxi9Nlf4hjk9wUNLC9ngWCWBiqMxPIZmzsVKYuChdlrfeBPQyvQQBoOhbx+7C1005kLVQDZQ==
1092+
dependencies:
1093+
"@bytecodealliance/preview2-shim" "0.17.0"
11421094

11431095
"@nomicfoundation/solidity-analyzer-darwin-arm64@0.1.1":
11441096
version "0.1.1"
@@ -1264,21 +1216,22 @@
12641216
axios "^1.7.4"
12651217
lodash "^4.17.21"
12661218

1267-
"@openzeppelin/upgrades-core@^1.37.0":
1268-
version "1.37.1"
1269-
resolved "https://registry.yarnpkg.com/@openzeppelin/upgrades-core/-/upgrades-core-1.37.1.tgz#b1879270a83e57639227770b5462b707ad6ab5b0"
1270-
integrity sha512-dMQPDoMn1OUZXsCHT1thnAmkZ14v0FNlst5Ej8MIfujOv0k74kUok5XeuNF42fYewnNUYMkkz3PhXU1OIwSeyg==
1219+
"@openzeppelin/upgrades-core@2.0.0-alpha.0":
1220+
version "2.0.0-alpha.0"
1221+
resolved "https://registry.yarnpkg.com/@openzeppelin/upgrades-core/-/upgrades-core-2.0.0-alpha.0.tgz#030e458e042b6f94932c2abb5bce83b464a6f003"
1222+
integrity sha512-SlLCalHt6UTnvift5xvFQ4gKvtlGh2YYC1tQJeQvzi4AEhJQR8UM4VEW5EFFe4fcqfBu2Bpqi73lDgH5T2JtGw==
12711223
dependencies:
1272-
"@nomicfoundation/slang" "^0.17.0"
1273-
cbor "^9.0.0"
1224+
"@nomicfoundation/slang" "^0.18.3"
1225+
bignumber.js "^9.1.2"
1226+
cbor "^10.0.0"
12741227
chalk "^4.1.0"
12751228
compare-versions "^6.0.0"
12761229
debug "^4.1.1"
12771230
ethereumjs-util "^7.0.3"
12781231
minimatch "^9.0.5"
12791232
minimist "^1.2.7"
12801233
proper-lockfile "^4.1.1"
1281-
solidity-ast "^0.4.51"
1234+
solidity-ast "^0.4.60"
12821235

12831236
"@scure/base@~1.1.0":
12841237
version "1.1.5"
@@ -2097,6 +2050,11 @@ better-path-resolve@1.0.0:
20972050
dependencies:
20982051
is-windows "^1.0.0"
20992052

2053+
bignumber.js@^9.1.2:
2054+
version "9.3.1"
2055+
resolved "https://registry.yarnpkg.com/bignumber.js/-/bignumber.js-9.3.1.tgz#759c5aaddf2ffdc4f154f7b493e1c8770f88c4d7"
2056+
integrity sha512-Ko0uX15oIUS7wJ3Rb30Fs6SkVbLmPBAKdlm7q9+ak9bbIeFf0MwuBsQV6z7+X768/cHsfg+WlysDWJcmthjsjQ==
2057+
21002058
binary-extensions@^2.0.0:
21012059
version "2.2.0"
21022060
resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.2.0.tgz#75f502eeaf9ffde42fc98829645be4ea76bd9e2d"
@@ -2246,12 +2204,12 @@ camelcase@^6.0.0, camelcase@^6.2.0:
22462204
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-6.3.0.tgz#5685b95eb209ac9c0c177467778c9c84df58ba9a"
22472205
integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==
22482206

2249-
cbor@^9.0.0:
2250-
version "9.0.1"
2251-
resolved "https://registry.yarnpkg.com/cbor/-/cbor-9.0.1.tgz#b16e393d4948d44758cd54ac6151379d443b37ae"
2252-
integrity sha512-/TQOWyamDxvVIv+DY9cOLNuABkoyz8K/F3QE56539pGVYohx0+MEA1f4lChFTX79dBTBS7R1PF6ovH7G+VtBfQ==
2207+
cbor@^10.0.0:
2208+
version "10.0.11"
2209+
resolved "https://registry.yarnpkg.com/cbor/-/cbor-10.0.11.tgz#f60e7cc2be6c943fecec159874ae651e75661745"
2210+
integrity sha512-vIwORDd/WyB8Nc23o2zNN5RrtFGlR6Fca61TtjkUXueI3Jf2DOZDl1zsshvBntZ3wZHBM9ztjnkXSmzQDaq3WA==
22532211
dependencies:
2254-
nofilter "^3.1.0"
2212+
nofilter "^3.0.2"
22552213

22562214
chalk@^2.4.2:
22572215
version "2.4.2"
@@ -3711,7 +3669,7 @@ node-gyp-build@^4.2.0:
37113669
resolved "https://registry.yarnpkg.com/node-gyp-build/-/node-gyp-build-4.6.1.tgz#24b6d075e5e391b8d5539d98c7fc5c210cac8a3e"
37123670
integrity sha512-24vnklJmyRS8ViBNI8KbtK/r/DmXQMRiOMXTNz2nrTnAYUwjmEEbnnpB/+kt+yWRv73bPsSPRFddrcIbAxSiMQ==
37133671

3714-
nofilter@^3.1.0:
3672+
nofilter@^3.0.2:
37153673
version "3.1.0"
37163674
resolved "https://registry.yarnpkg.com/nofilter/-/nofilter-3.1.0.tgz#c757ba68801d41ff930ba2ec55bab52ca184aa66"
37173675
integrity sha512-l2NNj07e9afPnhAhvgVrCD/oy2Ai1yfLpuo3EpiO1jFTsB4sFz6oIfAfSZyQzVpkZQ9xS8ZS5g1jCBgq4Hwo0g==
@@ -4294,12 +4252,10 @@ solidity-ast@^0.4.38:
42944252
dependencies:
42954253
array.prototype.findlast "^1.2.2"
42964254

4297-
solidity-ast@^0.4.51:
4298-
version "0.4.52"
4299-
resolved "https://registry.yarnpkg.com/solidity-ast/-/solidity-ast-0.4.52.tgz#9f1a9abc7e5ba28bbf91146ecd07aec7e70f3c85"
4300-
integrity sha512-iOya9BSiB9jhM8Vf40n8lGELGzwrUc57rl5BhfNtJ5cvAaMvRcNlHeAMNvqJJyjoUnczqRbHqdivEqK89du3Cw==
4301-
dependencies:
4302-
array.prototype.findlast "^1.2.2"
4255+
solidity-ast@^0.4.60:
4256+
version "0.4.61"
4257+
resolved "https://registry.yarnpkg.com/solidity-ast/-/solidity-ast-0.4.61.tgz#b51720ece553a2c7d84551ee5a7a2306080d23d0"
4258+
integrity sha512-OYBJYcYyG7gLV0VuXl9CUrvgJXjV/v0XnR4+1YomVe3q+QyENQXJJxAEASUz4vN6lMAl+C8RSRSr5MBAz09f6w==
43034259

43044260
solidity-comments-extractor@^0.0.7:
43054261
version "0.0.7"

0 commit comments

Comments
 (0)