Repository navigation
fix(hardhat-3-plugin): build the mock contracts with the project - #439
alexshchur merged 1 commit into
Conversation
🦋 Changeset detectedLatest commit: 3a3c232 The changes in this PR will be included in the next version bump. This PR includes changesets to release 9 packages
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 |
|
Extra check outside the monorepo, against the published packages: a clean npm project with
Plain So projects using the published plugin lose the mock artifacts on every full build, on both Hardhat versions, and listing the mocks in |
4368bc3 to
de24792
Compare
de24792 to
3a3c232
Compare
alexshchur
left a comment
There was a problem hiding this comment.
Thanks, nice find @nftpoetrist . The full build was deleting the mocks and the test workers tripped over each other rebuilding them, silently dropping whole files from the run. Building them with the project fixes it properly. Merging.
Summary
solidity.npmFilesToBuildin the plugin's config hook, so a fullhardhat buildbuilds them with the project instead of deleting them.@cofhe/hardhat-3-plugin.Root cause
The plugin compiles the mocks when the HRE is created (hre.ts#L152-L166), outside the project's root files. A full build, which
hardhat testruns before the tests, then removes the artifacts of every file it did not build (build.ts#L115-L121, build-system.ts#L905-L936), including the mocks and their build info.Each node:test worker creates its own HRE, so the workers compile the mocks again during the test run while other workers read the build info in
network.connect(). A read that lands in the middle of a write fails with "Failed to parse build info", and that test file fails at setup.Hardhat's node test runner does not count a test file that fails inside its
describecallback as failing (adescribecallback that throws makeshardhat testexit 0), so CI stays green when this happens. Two recentTest (local)runs ran only 23 of the 43 hardhat-3-plugin tests, with "Failed to parse build info" in the log: 38910038228, 38904992679.Fix
resolvePluginConfigappends the mock files (@cofhe/mock-contracts/contracts/*.sol) tosolidity.npmFilesToBuild. Hardhat includes those in every full build, so the cleanup keeps the mocks and the workers' startup build finds them up to date. The startup build stays for runs that skip the build (hardhat run --no-compile).getMockContractsNpmPathsnow maps a newgetMockContractsNpmFileshelper that returns the npm module paths.If
@cofhe/mock-contractscan't be resolved from the project, the startup build already fails with HHE901, so this adds no new failure.Testing
mock-build.test.ts:hre.solidity.getRootFilePaths()includes every mock contract. RED onmaster: fails on the first file (ABITest.sol).artifacts/cache, creating the HRE and then running a fullhardhat build: mock artifact directories go from 12 to 0 onmaster, and stay at 12 with the fix.hardhat testruns (clearedartifacts/cache, as in CI): onmastera worker compiled the mocks again during the node:test phase in each of 5 runs; with the fix, in none of 5. 46 passing (master: 45).hardhat-plugin-test: 102 passing.pnpm check:types,pnpm lint,pnpm check:formatting(tracked files),check:circles,check:pinned-deps: pass.Scope
Hardhat 3 plugin only. User projects get the same change: a full
hardhat buildno longer removes the mock artifacts. #431 and #438 touch other files of this plugin; merged together locally, they apply cleanly.