Skip to content

Commit b6fdcac

Browse files
authored
Merge pull request #8128 from NomicFoundation/dont-split-compilations-phase-1
Add `splitTestsCompilation` solidity setting (1): Configuration updates
2 parents a99a5b9 + be8bf71 commit b6fdcac

File tree

4 files changed

+187
-0
lines changed

4 files changed

+187
-0
lines changed

packages/hardhat/src/internal/builtin-plugins/solidity/config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ const incompatibleCompilerFields = {
8181
const commonSolidityUserConfigFields = {
8282
isolated: z.boolean().optional(),
8383
npmFilesToBuild: z.array(z.string()).optional(),
84+
splitTestsCompilation: z.boolean().optional(),
8485
};
8586

8687
const commonSolidityCompilerUserConfigFields = {
@@ -209,6 +210,7 @@ const buildProfilesSolidityUserConfigType = z.object({
209210
"Expected an object configuring one or more versions of Solidity",
210211
),
211212
),
213+
...commonSolidityUserConfigFields,
212214
...incompatibleProfileFields,
213215
});
214216

@@ -437,6 +439,7 @@ function resolveSolidityConfig(
437439
},
438440
npmFilesToBuild: [],
439441
registeredCompilerTypes: ["solc"],
442+
splitTestsCompilation: false,
440443
};
441444
}
442445

@@ -457,6 +460,7 @@ function resolveSolidityConfig(
457460
},
458461
npmFilesToBuild: solidityConfig.npmFilesToBuild ?? [],
459462
registeredCompilerTypes: ["solc"],
463+
splitTestsCompilation: solidityConfig.splitTestsCompilation ?? false,
460464
};
461465
}
462466

@@ -488,6 +492,7 @@ function resolveSolidityConfig(
488492
profiles,
489493
npmFilesToBuild: solidityConfig.npmFilesToBuild ?? [],
490494
registeredCompilerTypes: ["solc"],
495+
splitTestsCompilation: solidityConfig.splitTestsCompilation ?? false,
491496
};
492497
}
493498

packages/hardhat/src/internal/builtin-plugins/solidity/type-extensions.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ declare module "../../../types/config.js" {
5151
export interface CommonSolidityUserConfig {
5252
isolated?: boolean;
5353
npmFilesToBuild?: string[];
54+
/**
55+
* Controls whether Solidity test files are compiled in a separate pass
56+
* from contract files.
57+
*
58+
* When `false` (the default), contracts and tests are compiled together
59+
* in a single pass.
60+
*
61+
* When `true`, contracts and tests are compiled separately.
62+
*/
63+
splitTestsCompilation?: boolean;
5464
}
5565

5666
/**
@@ -289,6 +299,7 @@ declare module "../../../types/config.js" {
289299
profiles: Record<string, SolidityBuildProfileConfig>;
290300
npmFilesToBuild: string[];
291301
registeredCompilerTypes: SolidityCompilerType[];
302+
splitTestsCompilation: boolean;
292303
}
293304

294305
/**

packages/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
@@ -98,6 +98,7 @@ describe(
9898
},
9999
npmFilesToBuild: [],
100100
registeredCompilerTypes: ["solc"],
101+
splitTestsCompilation: false,
101102
};
102103

103104
before(async () => {

packages/hardhat/test/internal/builtin-plugins/solidity/config.ts

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,103 @@ describe("solidity plugin config validation", () => {
841841
);
842842
});
843843
});
844+
845+
describe("splitTestsCompilation validation", () => {
846+
it("Should accept splitTestsCompilation: true in a single-version config", () => {
847+
assert.deepEqual(
848+
validateSolidityUserConfig({
849+
solidity: {
850+
version: "0.8.28",
851+
splitTestsCompilation: true,
852+
},
853+
}),
854+
[],
855+
);
856+
});
857+
858+
it("Should accept splitTestsCompilation: false in a single-version config", () => {
859+
assert.deepEqual(
860+
validateSolidityUserConfig({
861+
solidity: {
862+
version: "0.8.28",
863+
splitTestsCompilation: false,
864+
},
865+
}),
866+
[],
867+
);
868+
});
869+
870+
it("Should accept omitted splitTestsCompilation", () => {
871+
assert.deepEqual(
872+
validateSolidityUserConfig({
873+
solidity: {
874+
version: "0.8.28",
875+
},
876+
}),
877+
[],
878+
);
879+
});
880+
881+
it("Should reject invalid non-boolean splitTestsCompilation values", () => {
882+
assert.deepEqual(
883+
validateSolidityUserConfig({
884+
solidity: {
885+
version: "0.8.28",
886+
splitTestsCompilation: "yes",
887+
} as any,
888+
}),
889+
[
890+
{
891+
path: ["solidity", "splitTestsCompilation"],
892+
message: "Expected boolean, received string",
893+
},
894+
],
895+
);
896+
897+
assert.deepEqual(
898+
validateSolidityUserConfig({
899+
solidity: {
900+
version: "0.8.28",
901+
splitTestsCompilation: 1,
902+
} as any,
903+
}),
904+
[
905+
{
906+
path: ["solidity", "splitTestsCompilation"],
907+
message: "Expected boolean, received number",
908+
},
909+
],
910+
);
911+
});
912+
913+
it("Should accept splitTestsCompilation in a multi-version config", () => {
914+
assert.deepEqual(
915+
validateSolidityUserConfig({
916+
solidity: {
917+
compilers: [{ version: "0.8.28" }],
918+
splitTestsCompilation: true,
919+
},
920+
}),
921+
[],
922+
);
923+
});
924+
925+
it("Should accept splitTestsCompilation in a build-profiles config", () => {
926+
assert.deepEqual(
927+
validateSolidityUserConfig({
928+
solidity: {
929+
profiles: {
930+
default: {
931+
version: "0.8.28",
932+
},
933+
},
934+
splitTestsCompilation: true,
935+
},
936+
}),
937+
[],
938+
);
939+
});
940+
});
844941
});
845942

846943
describe("solidity plugin config resolution", () => {
@@ -854,6 +951,78 @@ describe("solidity plugin config resolution", () => {
854951

855952
it.todo("should resolve a BuildProfilesSolidityUserConfig value", () => {});
856953

954+
describe("splitTestsCompilation resolution", () => {
955+
const otherResolvedConfig = { paths: { root: process.cwd() } } as any;
956+
957+
it("should default splitTestsCompilation to false for a string config", async () => {
958+
const resolvedConfig = await resolveSolidityUserConfig(
959+
{ solidity: "0.8.28" },
960+
otherResolvedConfig,
961+
);
962+
assert.equal(resolvedConfig.solidity.splitTestsCompilation, false);
963+
});
964+
965+
it("should default splitTestsCompilation to false for a string-array config", async () => {
966+
const resolvedConfig = await resolveSolidityUserConfig(
967+
{ solidity: ["0.8.28"] },
968+
otherResolvedConfig,
969+
);
970+
assert.equal(resolvedConfig.solidity.splitTestsCompilation, false);
971+
});
972+
973+
it("should default splitTestsCompilation to false when omitted from an object config", async () => {
974+
const resolvedConfig = await resolveSolidityUserConfig(
975+
{ solidity: { version: "0.8.28" } },
976+
otherResolvedConfig,
977+
);
978+
assert.equal(resolvedConfig.solidity.splitTestsCompilation, false);
979+
});
980+
981+
it("should resolve splitTestsCompilation: true from a single-version config", async () => {
982+
const resolvedConfig = await resolveSolidityUserConfig(
983+
{ solidity: { version: "0.8.28", splitTestsCompilation: true } },
984+
otherResolvedConfig,
985+
);
986+
assert.equal(resolvedConfig.solidity.splitTestsCompilation, true);
987+
});
988+
989+
it("should resolve splitTestsCompilation: false from a single-version config", async () => {
990+
const resolvedConfig = await resolveSolidityUserConfig(
991+
{ solidity: { version: "0.8.28", splitTestsCompilation: false } },
992+
otherResolvedConfig,
993+
);
994+
assert.equal(resolvedConfig.solidity.splitTestsCompilation, false);
995+
});
996+
997+
it("should resolve splitTestsCompilation from a multi-version config", async () => {
998+
const resolvedConfig = await resolveSolidityUserConfig(
999+
{
1000+
solidity: {
1001+
compilers: [{ version: "0.8.28" }],
1002+
splitTestsCompilation: true,
1003+
},
1004+
},
1005+
otherResolvedConfig,
1006+
);
1007+
assert.equal(resolvedConfig.solidity.splitTestsCompilation, true);
1008+
});
1009+
1010+
it("should resolve splitTestsCompilation from a build-profiles config", async () => {
1011+
const resolvedConfig = await resolveSolidityUserConfig(
1012+
{
1013+
solidity: {
1014+
profiles: {
1015+
default: { version: "0.8.28" },
1016+
},
1017+
splitTestsCompilation: true,
1018+
},
1019+
},
1020+
otherResolvedConfig,
1021+
);
1022+
assert.equal(resolvedConfig.solidity.splitTestsCompilation, true);
1023+
});
1024+
});
1025+
8571026
describe("profile-level preferWasm setting resolution", function () {
8581027
const otherResolvedConfig = { paths: { root: process.cwd() } } as any;
8591028

@@ -1595,6 +1764,7 @@ describe("validateResolvedConfig", () => {
15951764
profiles,
15961765
npmFilesToBuild: [],
15971766
registeredCompilerTypes,
1767+
splitTestsCompilation: false,
15981768
},
15991769
}) as unknown as HardhatConfig;
16001770

0 commit comments

Comments
 (0)