Skip to content

Commit d08b13b

Browse files
authored
Merge pull request #6194 from NomicFoundation/solidity-build-system-tests
Implement the first batch of solidity build system tests
2 parents 47fba67 + 00119c3 commit d08b13b

35 files changed

+2230
-11
lines changed

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -481,11 +481,9 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
481481
return result;
482482
}
483483

484-
public async cleanupArtifacts(): Promise<void> {
484+
public async cleanupArtifacts(rootFilePaths: string[]): Promise<void> {
485485
log(`Cleaning up artifacts`);
486486

487-
const rootFilePaths = await this.getRootFilePaths();
488-
489487
const publicSourceNames = rootFilePaths.map((rootFilePath) => {
490488
const parsed = parseRootPath(rootFilePath);
491489
return isNpmParsedRootPath(parsed)

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ export type ParsedRootPath = { npmPath: string } | { fsPath: string };
2626
* @param rootPath The root path.
2727
* @returns The parsed root path.
2828
*/
29-
export function parseRootPath(
30-
rootPath: string,
31-
): { npmPath: string } | { fsPath: string } {
29+
export function parseRootPath(rootPath: string): ParsedRootPath {
3230
if (rootPath.startsWith("npm:")) {
3331
return { npmPath: rootPath.substring(4) };
3432
}

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import type { DependencyGraphImplementation } from "./dependency-graph.js";
21
import type {
32
SolcConfig,
43
SolidityBuildProfileConfig,
54
} from "../../../../types/config.js";
65
import type { CompilationJobCreationError } from "../../../../types/solidity/build-system.js";
76
import type { ResolvedFile } from "../../../../types/solidity/resolved-file.js";
7+
import type { DependencyGraph } from "../../../../types/solidity.js";
88

99
import { assertHardhatInvariant } from "@ignored/hardhat-vnext-errors";
1010
import { shortenPath } from "@ignored/hardhat-vnext-utils/path";
@@ -30,7 +30,7 @@ export class SolcConfigSelector {
3030
constructor(
3131
buildProfileName: string,
3232
buildProfile: SolidityBuildProfileConfig,
33-
_dependencyGraph: DependencyGraphImplementation,
33+
_dependencyGraph: DependencyGraph,
3434
) {
3535
this.#buildProfileName = buildProfileName;
3636
this.#buildProfile = buildProfile;
@@ -45,7 +45,7 @@ export class SolcConfigSelector {
4545
* CompilationJobCreationError if no compatible solc version could be found.
4646
*/
4747
public selectBestSolcConfigForSingleRootGraph(
48-
subgraph: DependencyGraphImplementation,
48+
subgraph: DependencyGraph,
4949
): SolcConfig | CompilationJobCreationError {
5050
const roots = subgraph.getRoots();
5151

@@ -105,7 +105,7 @@ export class SolcConfigSelector {
105105

106106
#getCompilationJobCreationError(
107107
root: ResolvedFile,
108-
dependencyGraph: DependencyGraphImplementation,
108+
dependencyGraph: DependencyGraph,
109109
compilerVersions: string[],
110110
overriden: boolean,
111111
): CompilationJobCreationError {
@@ -165,7 +165,7 @@ export class SolcConfigSelector {
165165

166166
*#getTransitiveDependencies(
167167
root: ResolvedFile,
168-
dependencyGraph: DependencyGraphImplementation,
168+
dependencyGraph: DependencyGraph,
169169
visited = new Set<ResolvedFile>([root]),
170170
): Generator<{
171171
fsPath: string[];

v-next/hardhat/test/fixture-projects/solidity/example-project/artifacts/artifacts.d.ts

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"_format": "hh3-sol-build-info-1",
3+
"id": "89eed7b31e13eec3ee71467386d39108",
4+
"solcVersion": "0.7.1",
5+
"solcLongVersion": "0.7.1+commit.f4a555be",
6+
"publicSourceNameMap": {
7+
"contracts/NoImports.sol": "contracts/NoImports.sol"
8+
},
9+
"input": {
10+
"language": "Solidity",
11+
"sources": {
12+
"contracts/NoImports.sol": {
13+
"content": "// SPDX-License-Identifier: SEE LICENSE IN LICENSE\npragma solidity ^0.7.0;\n\ncontract NoImports {}\n"
14+
}
15+
},
16+
"settings": {
17+
"evmVersion": "istanbul",
18+
"outputSelection": {
19+
"*": {
20+
"": ["ast"]
21+
},
22+
"contracts/NoImports.sol": {
23+
"*": [
24+
"abi",
25+
"evm.bytecode",
26+
"evm.deployedBytecode",
27+
"evm.methodIdentifiers",
28+
"metadata"
29+
]
30+
}
31+
},
32+
"remappings": [
33+
"remapped/=npm/@openzeppelin/[email protected]/access/",
34+
"@openzeppelin/contracts/=npm/@openzeppelin/[email protected]/"
35+
]
36+
}
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"_format": "hh3-sol-build-info-output-1",
3+
"id": "89eed7b31e13eec3ee71467386d39108",
4+
"output": {
5+
"contracts": {
6+
"contracts/NoImports.sol": {
7+
"NoImports": {
8+
"abi": [],
9+
"evm": {
10+
"bytecode": {
11+
"linkReferences": {},
12+
"object": "6080604052348015600f57600080fd5b50603f80601d6000396000f3fe6080604052600080fdfea2646970667358221220622ff1f92fb75a340477cc69a6f9fcbbd9518f40d01c4ed0fc96c42f94e05c5a64736f6c63430007010033",
13+
"opcodes": "PUSH1 0x80 PUSH1 0x40 MSTORE CALLVALUE DUP1 ISZERO PUSH1 0xF JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH1 0x3F DUP1 PUSH1 0x1D PUSH1 0x0 CODECOPY PUSH1 0x0 RETURN INVALID PUSH1 0x80 PUSH1 0x40 MSTORE PUSH1 0x0 DUP1 REVERT INVALID LOG2 PUSH5 0x6970667358 0x22 SLT KECCAK256 PUSH3 0x2FF1F9 0x2F 0xB7 GAS CALLVALUE DIV PUSH24 0xCC69A6F9FCBBD9518F40D01C4ED0FC96C42F94E05C5A6473 PUSH16 0x6C634300070100330000000000000000 ",
14+
"sourceMap": "76:21:0:-:0;;;;;;;;;;;;;;;;;;;"
15+
},
16+
"deployedBytecode": {
17+
"immutableReferences": {},
18+
"linkReferences": {},
19+
"object": "6080604052600080fdfea2646970667358221220622ff1f92fb75a340477cc69a6f9fcbbd9518f40d01c4ed0fc96c42f94e05c5a64736f6c63430007010033",
20+
"opcodes": "PUSH1 0x80 PUSH1 0x40 MSTORE PUSH1 0x0 DUP1 REVERT INVALID LOG2 PUSH5 0x6970667358 0x22 SLT KECCAK256 PUSH3 0x2FF1F9 0x2F 0xB7 GAS CALLVALUE DIV PUSH24 0xCC69A6F9FCBBD9518F40D01C4ED0FC96C42F94E05C5A6473 PUSH16 0x6C634300070100330000000000000000 ",
21+
"sourceMap": "76:21:0:-:0;;;;;"
22+
},
23+
"methodIdentifiers": {}
24+
},
25+
"metadata": "{\"compiler\":{\"version\":\"0.7.1+commit.f4a555be\"},\"language\":\"Solidity\",\"output\":{\"abi\":[],\"devdoc\":{\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"contracts/NoImports.sol\":\"NoImports\"},\"evmVersion\":\"istanbul\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":false,\"runs\":200},\"remappings\":[\":@openzeppelin/contracts/=npm/@openzeppelin/[email protected]/\",\":remapped/=npm/@openzeppelin/[email protected]/access/\"]},\"sources\":{\"contracts/NoImports.sol\":{\"keccak256\":\"0x3a28c66ec59da4cb822584ed8f391ddaff26410fb89766d49d577497823bc5ea\",\"license\":\"SEE LICENSE IN LICENSE\",\"urls\":[\"bzz-raw://fb9c7244739857b5c2b14000e0cdf717a521671457ed04d73bf4dfce002cf454\",\"dweb:/ipfs/QmZH2Ky7fy8Q87bsf7g9wcMnM1qNJQLzjcyQSG8nX84yPY\"]}},\"version\":1}"
26+
}
27+
}
28+
},
29+
"sources": {
30+
"contracts/NoImports.sol": {
31+
"ast": {
32+
"absolutePath": "contracts/NoImports.sol",
33+
"exportedSymbols": { "NoImports": [2] },
34+
"id": 3,
35+
"license": "SEE LICENSE IN LICENSE",
36+
"nodeType": "SourceUnit",
37+
"nodes": [
38+
{
39+
"id": 1,
40+
"literals": ["solidity", "^", "0.7", ".0"],
41+
"nodeType": "PragmaDirective",
42+
"src": "51:23:0"
43+
},
44+
{
45+
"abstract": false,
46+
"baseContracts": [],
47+
"contractDependencies": [],
48+
"contractKind": "contract",
49+
"fullyImplemented": true,
50+
"id": 2,
51+
"linearizedBaseContracts": [2],
52+
"name": "NoImports",
53+
"nodeType": "ContractDefinition",
54+
"nodes": [],
55+
"scope": 3,
56+
"src": "76:21:0"
57+
}
58+
],
59+
"src": "51:47:0"
60+
},
61+
"id": 0
62+
}
63+
}
64+
}
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
{
2+
"_format": "hh3-sol-build-info-1",
3+
"id": "c6d3d46c7bda8aac0e4258c216012f50",
4+
"solcVersion": "0.8.22",
5+
"solcLongVersion": "0.8.22+commit.4fc1097e",
6+
"publicSourceNameMap": {
7+
"contracts/A.sol": "contracts/A.sol",
8+
"contracts/B.sol": "contracts/B.sol",
9+
"contracts/C.sol": "contracts/C.sol",
10+
"contracts/D.sol": "contracts/D.sol",
11+
"contracts/E.sol": "contracts/E.sol",
12+
"contracts/UserRemappedImport.sol": "contracts/UserRemappedImport.sol"
13+
},
14+
"input": {
15+
"language": "Solidity",
16+
"sources": {
17+
"contracts/A.sol": {
18+
"content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.0;\npragma solidity *;\n\nimport \"./B.sol\";\n\ncontract A is B {}\n"
19+
},
20+
"contracts/B.sol": {
21+
"content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.0;\n\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\n\ncontract B {}\n"
22+
},
23+
"contracts/C.sol": {
24+
"content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.0;\n\nimport \"./B.sol\";\n\ncontract C {}\n\ncontract C2 {}\n"
25+
},
26+
"contracts/D.sol": {
27+
"content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.22;\n\nimport \"./C.sol\";\n"
28+
},
29+
"contracts/E.sol": {
30+
"content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.22;\n\nimport \"./C.sol\";\n"
31+
},
32+
"contracts/UserRemappedImport.sol": {
33+
"content": "// SPDX-License-Identifier: SEE LICENSE IN LICENSE\npragma solidity ^0.8.0;\n\nimport \"remapped/Ownable.sol\";\n"
34+
},
35+
"npm/@openzeppelin/[email protected]/access/Ownable.sol": {
36+
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)\n\npragma solidity ^0.8.20;\n\nabstract contract Ownable {}\n"
37+
}
38+
},
39+
"settings": {
40+
"evmVersion": "shanghai",
41+
"outputSelection": {
42+
"*": {
43+
"": ["ast"]
44+
},
45+
"contracts/A.sol": {
46+
"*": [
47+
"abi",
48+
"evm.bytecode",
49+
"evm.deployedBytecode",
50+
"evm.methodIdentifiers",
51+
"metadata"
52+
]
53+
},
54+
"contracts/B.sol": {
55+
"*": [
56+
"abi",
57+
"evm.bytecode",
58+
"evm.deployedBytecode",
59+
"evm.methodIdentifiers",
60+
"metadata"
61+
]
62+
},
63+
"contracts/C.sol": {
64+
"*": [
65+
"abi",
66+
"evm.bytecode",
67+
"evm.deployedBytecode",
68+
"evm.methodIdentifiers",
69+
"metadata"
70+
]
71+
},
72+
"contracts/D.sol": {
73+
"*": [
74+
"abi",
75+
"evm.bytecode",
76+
"evm.deployedBytecode",
77+
"evm.methodIdentifiers",
78+
"metadata"
79+
]
80+
},
81+
"contracts/E.sol": {
82+
"*": [
83+
"abi",
84+
"evm.bytecode",
85+
"evm.deployedBytecode",
86+
"evm.methodIdentifiers",
87+
"metadata"
88+
]
89+
},
90+
"contracts/UserRemappedImport.sol": {
91+
"*": [
92+
"abi",
93+
"evm.bytecode",
94+
"evm.deployedBytecode",
95+
"evm.methodIdentifiers",
96+
"metadata"
97+
]
98+
}
99+
},
100+
"remappings": [
101+
"remapped/=npm/@openzeppelin/[email protected]/access/",
102+
"@openzeppelin/contracts/=npm/@openzeppelin/[email protected]/"
103+
]
104+
}
105+
}
106+
}

0 commit comments

Comments
 (0)