feat: add Hardhat v3 artifact & build-info loading from disk - #1635
feat: add Hardhat v3 artifact & build-info loading from disk#1635popescuoctavian wants to merge 6 commits into
Conversation
🦋 Changeset detectedLatest commit: 9ebb067 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1635 +/- ##
==========================================
- Coverage 80.01% 79.98% -0.04%
==========================================
Files 464 462 -2
Lines 80392 80702 +310
Branches 80392 80702 +310
==========================================
+ Hits 64329 64548 +219
- Misses 13856 13923 +67
- Partials 2207 2231 +24 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
/bench |
|
🚀 Starting regression benchmark for |
|
❌ Regression benchmark failed for |
|
/bench |
|
🚀 Starting regression benchmark for |
|
❌ Regression benchmark failed for |
|
/bench hardhat-ref=popescuoctavian/artifact-loading-to-EDR |
|
🚀 Starting regression benchmark for |
|
❌ Regression benchmark failed for |
|
/bench hardhat-ref=popescuoctavian/artifact-loading-to-EDR |
|
🚀 Starting regression benchmark for |
|
❌ Regression benchmark failed for |
|
/bench |
|
🚀 Starting regression benchmark for |
|
❌ Regression benchmark failed for |
2007f4b to
f0ce372
Compare
|
/bench hardhat-ref=popescuoctavian/artifact-loading-to-EDR |
|
🚀 Starting regression benchmark for |
|
❌ Regression benchmark failed for |
|
/bench hardhat-ref=popescuoctavian/artifact-loading-to-EDR |
|
🚀 Starting regression benchmark for |
|
❌ Regression benchmark failed for |
This PR adds the ability to load Hardhat v3 compilation artifacts and build infos
in EDR, so they are read from disk in Rust instead of being serialized and passed
over N-API.
New API
EdrContext.runSolidityTestsFromPaths— likerunSolidityTests, buttakes the paths of the project's artifact directories (in the Hardhat v3
format) instead of
Artifact[]and a tracing config. All artifacts andbuild infos are loaded from disk so that linking, cheatcodes and stack
trace generation keep working. Test suites are selected with a new
TestSuiteReference(source+name), which doesn't require knowing thesolc version up front: it's resolved from the artifacts on disk, and both
the user-facing source name (
contracts/Counter.t.sol) and the compilerinput source name (
project/contracts/Counter.t.sol) are accepted.ContractDecoder.fromProject— creates a decoder by reading aproject's build infos from disk (
artifactsDir, optionalbuildInfoDirand
ignoreContracts).Both existing entry points (
runSolidityTests,ContractDecoder.withContracts)are unchanged.
Implementation
edr_solidity::projectmodule that understands the Hardhat v3 artifactlayout:
hh3-artifact-1artifact files (validated by_format), pairedbuild-info/<id>.json+<id>.output.jsonfiles, and solc versionextraction from build info ids
(
solc-<major>_<minor>_<patch>[-<compilerType>]-<hex>). Unlinked bytecodekeeps its
__$...$__placeholders for the linker, matching the existingN-API conversion.
edr_napi's test execution path is refactored so both entry points share acommon
run_test_suitesfunction; the disk-loading variant runs file IO ona blocking thread.
Code mapping: EDR ⇄ Hardhat (Claude-generated)
New EDR code vs. the Hardhat code it ports, verified against Hardhat 3.15.0
(latest release). Hardhat paths are relative to
packages/hardhat/src/in theHardhat monorepo.
crates/edr_solidity/src/project.rs—find_artifact_filesinternal/builtin-plugins/artifacts/artifact-manager.ts—#readFsDataFromFileSystem: same three conditions (.jsonfiles only, top-level files excluded,build-infodir excluded)project.rs—BUILD_INFO_DIR_NAMEartifact-manager.ts—BUILD_INFO_DIR_NAMEproject.rs—HardhatV3ArtifactArtifactinterface intypes/artifacts.ts(declared fields only)project.rs—load_artifacts/to_loaded_artifact(id frominputSourceName ?? sourceName, solc version from build info id, ABI + bytecodes + link references)internal/builtin-plugins/solidity-test/edr-artifacts.ts—buildEdrArtifactsWithMetadata(JSON reads viaartifact-manager.tsreadArtifact)project.rs—solc_version_from_build_info_idedr-artifacts.ts— theBUILD_INFO_FORMATregex, including 3.15.0's hyphenated compiler types (solc-0_8_28-zk-solx-<hex>)project.rs—find_build_info_files(flat dir,.jsonminus.output.json, pair with output)artifact-manager.ts—getAllBuildInfoIds+getBuildInfoPath+getBuildInfoOutputPathproject.rs—load_build_info_config(skips build infos without an output)internal/builtin-plugins/network-manager/network-manager.ts—#getBuildInfosAndOutputsAsBuffers(same skip-if-either-missing behavior)crates/edr_napi/src/solidity_tests.rs—load_project_inputs(loop over artifact directories, concatenate artifacts + build infos)internal/builtin-plugins/solidity-test/task-action.ts—loadArtifacts(per-scopegetArtifactsDirectory→buildEdrArtifactsWithMetadata+getBuildInfosAndOutputs)solidity_tests.rs— hard error on a missing.output.jsonedr-artifacts.ts—getBuildInfosAndOutputs'sassertHardhatInvariants on both paths (the strict counterpart to network-manager's skip)solidity_tests.rs—resolve_test_suites/LoadedArtifact.user_source_name(accepting either source name)task-action.ts— thesourceNameToUserSourceNamemap anduserSourceNamemetadata threading;TestSuiteReferenceresolves the// TODO: This is a temporary solution...comment inedr-artifacts.tsabout input vs. user source namescrates/edr_napi/src/contract_decoder.rs—ContractDecoder.fromProjectnetwork-manager.ts#getBuildInfosAndOutputsAsBuffers→internal/builtin-plugins/network-manager/edr/edr-provider.tscreateContractDecoder→ContractDecoder.withContractscrates/edr_napi/src/context.rs—run_solidity_tests_from_pathstask-action.ts'srun(...)call (passingedrArtifacts,testSuiteIds,tracingConfigover N-API)Deliberately not ported (stays in Hardhat for now): deciding which contracts are
test suites (
isTestSuiteArtifactinsolidity-test/helpers.tsplus thetest-root filtering in
task-action.ts— EDR receives explicitTestSuiteReferences), and the artifact manager's name-lookup/cachingmachinery (FQN maps, edit-distance suggestions).
Known behavioral delta: for a build info id that doesn't match the format,
Hardhat filters it out of the solc-version map and later fails an
assertHardhatInvariantwhen an artifact references it; EDR reports the typedInvalidBuildInfoIderror up front.