Skip to content

Commit cbbe240

Browse files
committed
Fix tests
1 parent 62731f7 commit cbbe240

16 files changed

+29
-99
lines changed

.changeset/unlucky-monkeys-speak.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@nomicfoundation/hardhat-verify": patch
3+
"hardhat": patch
4+
---
5+
6+
Minimize compilation jobs based on changes in files and config across runs

v-next/hardhat-verify/src/internal/artifacts.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,22 @@ export async function getCompilerInput(
7676
sourceName: string,
7777
buildProfileName: string,
7878
): Promise<CompilerInput> {
79-
const compilationJob = await solidity.getCompilationJobs(
79+
const getCompilationJobsResult = await solidity.getCompilationJobs(
8080
[path.join(rootFilePath, sourceName)],
8181
{
8282
buildProfile: buildProfileName,
8383
quiet: true,
84+
force: true,
8485
},
8586
);
8687

88+
assertHardhatInvariant(
89+
!("reason" in getCompilationJobsResult),
90+
"getCompilationJobs should not error",
91+
);
92+
93+
const compilationJob = getCompilationJobsResult.compilationJobsPerFile;
94+
8795
// TODO: should this be an error instead?
8896
assertHardhatInvariant(
8997
compilationJob instanceof Map && compilationJob.size === 1,

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

Lines changed: 14 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,20 @@ import { HookManagerImplementation } from "../../../../../src/internal/core/hook
2727

2828
async function emitArtifacts(solidity: SolidityBuildSystem): Promise<void> {
2929
const rootFilePaths = await solidity.getRootFilePaths();
30-
const compilationJobs = await solidity.getCompilationJobs(rootFilePaths, {
31-
isolated: false,
32-
quiet: true,
33-
});
30+
const compilationJobsResult = await solidity.getCompilationJobs(
31+
rootFilePaths,
32+
{
33+
isolated: false,
34+
quiet: true,
35+
},
36+
);
37+
38+
assert.ok(
39+
!("reason" in compilationJobsResult),
40+
"getCompilationJobs should not error",
41+
);
42+
43+
const compilationJobs = compilationJobsResult.compilationJobsPerFile;
3444

3545
assert.ok(compilationJobs instanceof Map, "compilationJobs should be a Map");
3646

@@ -264,25 +274,6 @@ describe(
264274
);
265275
});
266276

267-
it("should not recompile the project when given the same input as in the previous call", async () => {
268-
const rootFilePaths = await solidity.getRootFilePaths();
269-
await solidity.build(rootFilePaths, {
270-
force: true,
271-
isolated: false,
272-
quiet: true,
273-
});
274-
275-
const runCompilationJobSpy = mock.method(solidity, "runCompilationJob");
276-
277-
await solidity.build(rootFilePaths, {
278-
force: false,
279-
isolated: false,
280-
quiet: true,
281-
});
282-
283-
assert.equal(runCompilationJobSpy.mock.callCount(), 0);
284-
});
285-
286277
it("should recompile the project when given the same input as in the previous call but the force flag is set", async () => {
287278
const rootFilePaths = await solidity.getRootFilePaths();
288279
await solidity.build(rootFilePaths, {
@@ -302,81 +293,6 @@ describe(
302293
assert.equal(runCompilationJobSpy.mock.callCount(), 2);
303294
});
304295

305-
it("should not recompile the project when the input changed but the generated compilation jobs are the subset of the previous ones", async () => {
306-
const rootFilePaths = await solidity.getRootFilePaths();
307-
await solidity.build(rootFilePaths, {
308-
force: true,
309-
isolated: false,
310-
quiet: true,
311-
});
312-
313-
const runCompilationJobSpy = mock.method(solidity, "runCompilationJob");
314-
315-
await solidity.build(
316-
rootFilePaths.filter((f) => path.basename(f) !== "NoImports.sol"),
317-
{
318-
force: false,
319-
isolated: false,
320-
quiet: true,
321-
},
322-
);
323-
324-
assert.equal(runCompilationJobSpy.mock.callCount(), 0);
325-
});
326-
327-
it("should recompile the project when the input changed and the generated compilation jobs changed", async () => {
328-
const rootFilePaths = await solidity.getRootFilePaths();
329-
await solidity.build(rootFilePaths, {
330-
force: true,
331-
isolated: false,
332-
quiet: true,
333-
});
334-
335-
const runCompilationJobSpy = mock.method(solidity, "runCompilationJob");
336-
337-
await solidity.build(
338-
rootFilePaths.filter((f) => path.basename(f) !== "A.sol"),
339-
{
340-
force: false,
341-
isolated: false,
342-
quiet: true,
343-
},
344-
);
345-
346-
assert.equal(runCompilationJobSpy.mock.callCount(), 1);
347-
});
348-
349-
it("should not recompile the project when the input is the same as in one of the previous calls", async () => {
350-
const rootFilePaths = await solidity.getRootFilePaths();
351-
await solidity.build(rootFilePaths, {
352-
force: true,
353-
isolated: false,
354-
quiet: true,
355-
});
356-
357-
await solidity.build(
358-
rootFilePaths.filter((f) => path.basename(f) !== "A.sol"),
359-
{
360-
force: false,
361-
isolated: false,
362-
quiet: true,
363-
},
364-
);
365-
366-
const runCompilationJobSpy = mock.method(solidity, "runCompilationJob");
367-
368-
await solidity.build(
369-
rootFilePaths.filter((f) => path.basename(f) !== "A.sol"),
370-
{
371-
force: false,
372-
isolated: false,
373-
quiet: true,
374-
},
375-
);
376-
377-
assert.equal(runCompilationJobSpy.mock.callCount(), 0);
378-
});
379-
380296
it("should throw when given a build profile that is not defined", async () => {
381297
const rootFilePaths = await solidity.getRootFilePaths();
382298

0 commit comments

Comments
 (0)