Skip to content

Commit 8bd46cb

Browse files
committed
Avoid cleaning up solidity test artifacts on compile task
1 parent a7f9950 commit 8bd46cb

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

.changeset/forty-steaks-live.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"hardhat": patch
3+
---
4+
5+
Stop solidity tests being recompiled unnecessarily ([#7116](https://github.com/NomicFoundation/hardhat/issues/7116))

v-next/hardhat/src/internal/builtin-plugins/solidity/build-system/build-system.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export interface SolidityBuildSystemOptions {
8484
readonly soliditySourcesPaths: string[];
8585
readonly artifactsPath: string;
8686
readonly cachePath: string;
87+
readonly solidityTestsPath: string;
8788
}
8889

8990
export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
@@ -290,6 +291,8 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
290291
rootFilePaths: string[],
291292
options?: GetCompilationJobsOptions,
292293
): Promise<CompilationJobCreationError | GetCompilationJobsResult> {
294+
const isolated = options?.isolated ?? false;
295+
293296
await this.#downloadConfiguredCompilers(options?.quiet);
294297

295298
const dependencyGraph = await buildDependencyGraph(
@@ -397,7 +400,7 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
397400
options?.force === true ||
398401
cacheResult === undefined ||
399402
cacheResult.jobHash !== jobHash ||
400-
cacheResult.isolated !== options?.isolated
403+
cacheResult.isolated !== isolated
401404
) {
402405
rootFilesToCompile.add(rootFile);
403406
continue;
@@ -424,10 +427,7 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
424427
}
425428
}
426429

427-
if (
428-
options?.isolated !== true &&
429-
shouldMergeCompilationJobs(buildProfileName)
430-
) {
430+
if (!isolated && shouldMergeCompilationJobs(buildProfileName)) {
431431
// non-isolated mode
432432
log(`Merging compilation jobs`);
433433

@@ -702,6 +702,20 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
702702
)) {
703703
const relativePath = path.relative(this.#options.artifactsPath, file);
704704

705+
const testDirectorySubpath = path.relative(
706+
this.#options.projectRoot,
707+
this.#options.solidityTestsPath,
708+
);
709+
const hasTestFileExtension = file.endsWith(".t.sol");
710+
const isInsideTestFolder = relativePath.startsWith(
711+
testDirectorySubpath + path.sep,
712+
);
713+
714+
// Skip test artifacts, since our full compilation doesn't include them, they would incorrectly be marked for deletion
715+
if (hasTestFileExtension || isInsideTestFolder) {
716+
continue;
717+
}
718+
705719
if (!userSourceNamesSet.has(relativePath)) {
706720
await remove(file);
707721
}

v-next/hardhat/src/internal/builtin-plugins/solidity/hook-handlers/hre.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ export default async (): Promise<Partial<HardhatRuntimeEnvironmentHooks>> => {
120120
soliditySourcesPaths: hre.config.paths.sources.solidity,
121121
artifactsPath: hre.config.paths.artifacts,
122122
cachePath: hre.config.paths.cache,
123+
solidityTestsPath: hre.config.paths.tests.solidity,
123124
});
124125
},
125126
};

v-next/hardhat/test/internal/builtin-plugins/solidity/build-system/build-system.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ describe(
107107
soliditySourcesPaths: [path.join(process.cwd(), "contracts")],
108108
artifactsPath: expectedArtifactsPath,
109109
cachePath: expectedCachePath,
110+
solidityTestsPath: path.join(process.cwd(), "tests"),
110111
});
111112
const rootFilePaths = await solidity.getRootFilePaths();
112113
await solidity.build(rootFilePaths, {
@@ -129,6 +130,7 @@ describe(
129130
soliditySourcesPaths: [path.join(process.cwd(), "contracts")],
130131
artifactsPath: actualArtifactsPath,
131132
cachePath: actualCachePath,
133+
solidityTestsPath: path.join(process.cwd(), "tests"),
132134
});
133135
});
134136

0 commit comments

Comments
 (0)