Skip to content

Commit 95596d0

Browse files
committed
test: implement config tests for the isolated option
1 parent bf2d771 commit 95596d0

File tree

4 files changed

+210
-10
lines changed

4 files changed

+210
-10
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ const sourcePathsType = conditionalUnionType(
2626
"Expected a string or an array of strings",
2727
);
2828

29+
const commonSolcUserConfigType = z.object({
30+
isolated: z.boolean().optional(),
31+
});
32+
2933
const solcUserConfigType = z.object({
3034
version: z.string(),
3135
settings: z.any().optional(),
@@ -34,10 +38,10 @@ const solcUserConfigType = z.object({
3438
profiles: incompatibleFieldType("This field is incompatible with `version`"),
3539
});
3640

37-
// NOTE: This is only to match the setup present in ./type-extensions.ts
38-
const singleVersionSolcUserConfigType = solcUserConfigType;
41+
const singleVersionSolcUserConfigType =
42+
commonSolcUserConfigType.merge(solcUserConfigType);
3943

40-
const multiVersionSolcUserConfigType = z.object({
44+
const multiVersionSolcUserConfigType = commonSolcUserConfigType.extend({
4145
compilers: z.array(solcUserConfigType).nonempty(),
4246
overrides: z.record(z.string(), solcUserConfigType).optional(),
4347
version: incompatibleFieldType("This field is incompatible with `compilers`"),

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ describe(
8888
},
8989
],
9090
overrides: {},
91+
isolated: false,
9192
},
9293
},
9394
npmFilesToBuild: [],

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ describe("SolcConfigSelector", () => {
5353
buildProfile = {
5454
compilers: [],
5555
overrides: {},
56+
isolated: false,
5657
};
5758
root = createProjectResolvedFile("root.sol", ["^0.8.0"]);
5859
dependencyGraph = new DependencyGraphImplementation();
@@ -357,7 +358,11 @@ describe("SolcConfigSelector", () => {
357358

358359
const selector = new SolcConfigSelector(
359360
buildProfileName,
360-
{ compilers: [{ version: "0.8.0", settings: {} }], overrides: {} },
361+
{
362+
compilers: [{ version: "0.8.0", settings: {} }],
363+
overrides: {},
364+
isolated: false,
365+
},
361366
dependencyGraph,
362367
);
363368

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

Lines changed: 196 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,108 @@ describe("solidity plugin config validation", () => {
232232
);
233233
});
234234

235-
it.todo("Should reject invalid SingleVersionSolidityUserConfig values");
235+
it("Should reject invalid SingleVersionSolidityUserConfig values", () => {
236+
assert.deepEqual(
237+
validateSolidityUserConfig({
238+
solidity: {
239+
version: 123,
240+
npmFilesToBuild: {},
241+
isolated: "false",
242+
},
243+
}),
244+
[
245+
{
246+
message: "Expected boolean, received string",
247+
path: ["solidity", "isolated"],
248+
},
249+
{
250+
message: "Expected string, received number",
251+
path: ["solidity", "version"],
252+
},
253+
{
254+
message: "Expected array, received object",
255+
path: ["solidity", "npmFilesToBuild"],
256+
},
257+
],
258+
);
259+
});
236260

237-
it.todo("Should reject invalid MultiVersionSolidityUserConfig values");
261+
it("Should reject invalid MultiVersionSolidityUserConfig values", () => {
262+
assert.deepEqual(
263+
validateSolidityUserConfig({
264+
solidity: {
265+
compilers: [
266+
{
267+
version: 123,
268+
},
269+
],
270+
overrides: [],
271+
isolated: "false",
272+
},
273+
}),
274+
[
275+
{
276+
message: "Expected boolean, received string",
277+
path: ["solidity", "isolated"],
278+
},
279+
{
280+
message: "Expected string, received number",
281+
path: ["solidity", "compilers", 0, "version"],
282+
},
283+
{
284+
message: "Expected object, received array",
285+
path: ["solidity", "overrides"],
286+
},
287+
],
288+
);
289+
});
238290

239-
it.todo("Should reject invalid BuildProfilesSolidityUserConfig values");
291+
it("Should reject invalid BuildProfilesSolidityUserConfig values", () => {
292+
assert.deepEqual(
293+
validateSolidityUserConfig({
294+
solidity: {
295+
profiles: {
296+
default: {
297+
version: 123,
298+
isolated: "false",
299+
},
300+
production: {
301+
version: "0.8.0",
302+
compilers: [
303+
{
304+
version: 123,
305+
},
306+
],
307+
overrides: [],
308+
isolated: "true",
309+
},
310+
},
311+
},
312+
}),
313+
[
314+
{
315+
message: "Expected boolean, received string",
316+
path: ["solidity", "profiles", "default", "isolated"],
317+
},
318+
{
319+
message: "Expected string, received number",
320+
path: ["solidity", "profiles", "default", "version"],
321+
},
322+
{
323+
message: "Expected boolean, received string",
324+
path: ["solidity", "profiles", "production", "isolated"],
325+
},
326+
{
327+
message: "This field is incompatible with `version`",
328+
path: ["solidity", "profiles", "production", "compilers"],
329+
},
330+
{
331+
message: "This field is incompatible with `version`",
332+
path: ["solidity", "profiles", "production", "overrides"],
333+
},
334+
],
335+
);
336+
});
240337

241338
it("Should accept solidity version strings", () => {
242339
assert.deepEqual(validateSolidityUserConfig({ solidity: "0.8.0" }), []);
@@ -249,11 +346,104 @@ describe("solidity plugin config validation", () => {
249346
);
250347
});
251348

252-
it.todo("Should accept a SingleVersionSolidityUserConfig value");
349+
it("Should accept a SingleVersionSolidityUserConfig value", () => {
350+
assert.deepEqual(
351+
validateSolidityUserConfig({
352+
solidity: {
353+
version: "0.8.0",
354+
settings: {
355+
optimizer: {
356+
enabled: true,
357+
runs: 200,
358+
},
359+
},
360+
npmFilesToBuild: ["./build.js"],
361+
isolated: false,
362+
},
363+
}),
364+
[],
365+
);
366+
});
253367

254-
it.todo("Should accept a MultiVersionSolidityUserConfig value");
368+
it("Should accept a MultiVersionSolidityUserConfig value", () => {
369+
assert.deepEqual(
370+
validateSolidityUserConfig({
371+
solidity: {
372+
compilers: [
373+
{
374+
version: "0.8.0",
375+
settings: {
376+
optimizer: {
377+
enabled: true,
378+
runs: 200,
379+
},
380+
},
381+
},
382+
],
383+
overrides: {
384+
"contracts/Contract.sol": {
385+
version: "0.8.1",
386+
settings: {
387+
optimizer: {
388+
enabled: false,
389+
runs: 100,
390+
},
391+
},
392+
},
393+
},
394+
isolated: false,
395+
},
396+
}),
397+
[],
398+
);
399+
});
255400

256-
it.todo("Should accept a BuildProfilesSolidityUserConfig value");
401+
it("Should accept a BuildProfilesSolidityUserConfig value", () => {
402+
assert.deepEqual(
403+
validateSolidityUserConfig({
404+
solidity: {
405+
profiles: {
406+
default: {
407+
version: "0.8.0",
408+
settings: {
409+
optimizer: {
410+
enabled: true,
411+
runs: 200,
412+
},
413+
},
414+
isolated: false,
415+
},
416+
production: {
417+
compilers: [
418+
{
419+
version: "0.8.0",
420+
settings: {
421+
optimizer: {
422+
enabled: true,
423+
runs: 200,
424+
},
425+
},
426+
},
427+
],
428+
overrides: {
429+
"contracts/Contract.sol": {
430+
version: "0.8.1",
431+
settings: {
432+
optimizer: {
433+
enabled: true,
434+
runs: 300,
435+
},
436+
},
437+
},
438+
},
439+
isolated: true,
440+
},
441+
},
442+
},
443+
}),
444+
[],
445+
);
446+
});
257447
});
258448
});
259449

0 commit comments

Comments
 (0)