Skip to content

Commit bea3c22

Browse files
committed
Update hardhat-ignition
1 parent 96b513c commit bea3c22

File tree

4 files changed

+210
-2
lines changed

4 files changed

+210
-2
lines changed

packages/hardhat-ignition/src/internal/tasks/deploy.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,10 @@ const taskDeploy: NewTaskActionFunction<TaskDeployArguments> = async (
154154
);
155155
}
156156

157+
const noTests = hre.config.solidity.splitTestsCompilation;
157158
await hre.tasks.getTask("build").run({
158159
quiet: true,
159-
noTests: true,
160+
noTests,
160161
defaultBuildProfile: "production",
161162
});
162163

packages/hardhat-ignition/src/internal/tasks/visualize.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ const visualizeTask: NewTaskActionFunction<TaskVisualizeArguments> = async (
2222
{ noOpen, modulePath }: { noOpen: boolean; modulePath: string },
2323
hre: HardhatRuntimeEnvironment,
2424
) => {
25-
await hre.tasks.getTask("build").run({ noTests: true, quiet: true });
25+
const noTests = hre.config.solidity.splitTestsCompilation;
26+
await hre.tasks.getTask("build").run({ noTests, quiet: true });
2627

2728
const userModule = await loadModule(hre.config.paths.ignition, modulePath);
2829

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import path from "node:path";
2+
import { fileURLToPath, pathToFileURL } from "node:url";
3+
4+
import { assert } from "chai";
5+
import { overrideTask } from "hardhat/config";
6+
import { createHardhatRuntimeEnvironment } from "hardhat/hre";
7+
8+
import hardhatIgnitionPlugin from "../../src/index.js";
9+
10+
describe("deploy - build invocation", function () {
11+
function buildArgCaptor() {
12+
const buildArgs: any[] = [];
13+
const buildOverride = overrideTask("build")
14+
.setAction(async () => ({
15+
default: async (args: any) => {
16+
buildArgs.push(args);
17+
return { contractRootPaths: [], testRootPaths: [] };
18+
},
19+
}))
20+
.build();
21+
return { buildArgs, buildOverride };
22+
}
23+
24+
function getProjectConfig() {
25+
const projectPath = path.join(
26+
path.dirname(fileURLToPath(import.meta.url)),
27+
"../fixture-projects",
28+
"minimal",
29+
);
30+
31+
const configPath = path.join(projectPath, "hardhat.config.js");
32+
33+
return { projectPath, configPath };
34+
}
35+
36+
it("should call build without noTests when splitTestsCompilation is false", async function () {
37+
const { buildArgs, buildOverride } = buildArgCaptor();
38+
const { projectPath, configPath } = getProjectConfig();
39+
40+
const { default: userConfig } = await import(
41+
pathToFileURL(configPath).href
42+
);
43+
44+
const hre = await createHardhatRuntimeEnvironment(
45+
{
46+
...userConfig,
47+
plugins: [hardhatIgnitionPlugin],
48+
tasks: [buildOverride],
49+
},
50+
{ config: configPath },
51+
projectPath,
52+
);
53+
54+
// The deploy task continues after build and may fail looking for artifacts;
55+
// we only care about the build invocation args captured before that point.
56+
try {
57+
await hre.tasks.getTask(["ignition", "deploy"]).run({
58+
modulePath: path.join(
59+
projectPath,
60+
"ignition",
61+
"modules",
62+
"MyModule.js",
63+
),
64+
});
65+
} catch {}
66+
67+
assert.equal(buildArgs.length, 1);
68+
assert.equal(buildArgs[0].noTests, false);
69+
assert.equal(buildArgs[0].defaultBuildProfile, "production");
70+
assert.equal(buildArgs[0].quiet, true);
71+
});
72+
73+
it("should call build with noTests when splitTestsCompilation is true", async function () {
74+
const { buildArgs, buildOverride } = buildArgCaptor();
75+
const { projectPath, configPath } = getProjectConfig();
76+
77+
const { default: userConfig } = await import(
78+
pathToFileURL(configPath).href
79+
);
80+
81+
const hre = await createHardhatRuntimeEnvironment(
82+
{
83+
...userConfig,
84+
solidity: {
85+
...userConfig.solidity,
86+
splitTestsCompilation: true,
87+
},
88+
plugins: [hardhatIgnitionPlugin],
89+
tasks: [buildOverride],
90+
},
91+
{ config: configPath },
92+
projectPath,
93+
);
94+
95+
try {
96+
await hre.tasks.getTask(["ignition", "deploy"]).run({
97+
modulePath: path.join(
98+
projectPath,
99+
"ignition",
100+
"modules",
101+
"MyModule.js",
102+
),
103+
});
104+
} catch {}
105+
106+
assert.equal(buildArgs.length, 1);
107+
assert.equal(buildArgs[0].noTests, true);
108+
assert.equal(buildArgs[0].defaultBuildProfile, "production");
109+
assert.equal(buildArgs[0].quiet, true);
110+
});
111+
});
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import path from "node:path";
2+
import { fileURLToPath, pathToFileURL } from "node:url";
3+
4+
import { assert } from "chai";
5+
import { overrideTask } from "hardhat/config";
6+
import { createHardhatRuntimeEnvironment } from "hardhat/hre";
7+
8+
import hardhatIgnitionPlugin from "../../src/index.js";
9+
10+
describe("visualize - build invocation", function () {
11+
function buildArgCaptor() {
12+
const buildArgs: any[] = [];
13+
const buildOverride = overrideTask("build")
14+
.setAction(async () => ({
15+
default: async (args: any) => {
16+
buildArgs.push(args);
17+
return { contractRootPaths: [], testRootPaths: [] };
18+
},
19+
}))
20+
.build();
21+
return { buildArgs, buildOverride };
22+
}
23+
24+
function getProjectConfig() {
25+
const projectPath = path.join(
26+
path.dirname(fileURLToPath(import.meta.url)),
27+
"../fixture-projects",
28+
"minimal",
29+
);
30+
31+
const configPath = path.join(projectPath, "hardhat.config.js");
32+
33+
return { projectPath, configPath };
34+
}
35+
36+
it("should call build without noTests when splitTestsCompilation is false", async function () {
37+
const { buildArgs, buildOverride } = buildArgCaptor();
38+
const { projectPath, configPath } = getProjectConfig();
39+
40+
const { default: userConfig } = await import(
41+
pathToFileURL(configPath).href
42+
);
43+
44+
const hre = await createHardhatRuntimeEnvironment(
45+
{
46+
...userConfig,
47+
plugins: [hardhatIgnitionPlugin],
48+
tasks: [buildOverride],
49+
},
50+
{ config: configPath },
51+
projectPath,
52+
);
53+
54+
await hre.tasks.getTask(["ignition", "visualize"]).run({
55+
noOpen: true,
56+
modulePath: path.join(projectPath, "ignition", "modules", "MyModule.js"),
57+
});
58+
59+
assert.equal(buildArgs.length, 1);
60+
assert.equal(buildArgs[0].noTests, false);
61+
assert.equal(buildArgs[0].quiet, true);
62+
});
63+
64+
it("should call build with noTests when splitTestsCompilation is true", async function () {
65+
const { buildArgs, buildOverride } = buildArgCaptor();
66+
const { projectPath, configPath } = getProjectConfig();
67+
68+
const { default: userConfig } = await import(
69+
pathToFileURL(configPath).href
70+
);
71+
72+
const hre = await createHardhatRuntimeEnvironment(
73+
{
74+
...userConfig,
75+
solidity: {
76+
...userConfig.solidity,
77+
splitTestsCompilation: true,
78+
},
79+
plugins: [hardhatIgnitionPlugin],
80+
tasks: [buildOverride],
81+
},
82+
{ config: configPath },
83+
projectPath,
84+
);
85+
86+
await hre.tasks.getTask(["ignition", "visualize"]).run({
87+
noOpen: true,
88+
modulePath: path.join(projectPath, "ignition", "modules", "MyModule.js"),
89+
});
90+
91+
assert.equal(buildArgs.length, 1);
92+
assert.equal(buildArgs[0].noTests, true);
93+
assert.equal(buildArgs[0].quiet, true);
94+
});
95+
});

0 commit comments

Comments
 (0)