Skip to content

Commit 32b867e

Browse files
authored
Merge pull request #5780 from NomicFoundation/feat/skeleton-solidity-test-integration
add skeleton EDR Solidity Testing integration
2 parents ea16594 + 16d7c13 commit 32b867e

File tree

19 files changed

+1120
-424
lines changed

19 files changed

+1120
-424
lines changed

pnpm-lock.yaml

+438-398
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

v-next/example-project/.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,9 @@
66

77
# pnpm deploy output
88
/bundle
9+
10+
# Hardhat Build Artifacts
11+
/artifacts
12+
13+
# Hardhat compilation (v2) support directory
14+
/cache
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.0;
3+
4+
contract Counter {
5+
uint public x;
6+
7+
function inc() public {
8+
x++;
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.0;
3+
4+
import "./Counter.sol";
5+
6+
contract CounterTest {
7+
Counter counter;
8+
9+
function setUp() public {
10+
counter = new Counter();
11+
}
12+
13+
function testInitialValue() public view {
14+
require(counter.x() == 0, "Initial value should be 0");
15+
}
16+
17+
function testInc() public {
18+
counter.inc();
19+
require(counter.x() == 1, "Value after inc should be 1");
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity ^0.8.0;
3+
4+
contract Rocket {
5+
string public name;
6+
string public status;
7+
8+
constructor(string memory _name) {
9+
name = _name;
10+
status = "ignition";
11+
}
12+
13+
function launch() public {
14+
status = "lift-off";
15+
}
16+
}

v-next/hardhat-build-system/package.json

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@ignored/hardhat-vnext-build-system",
33
"private": true,
4-
"version": "2.0.1-next.0",
4+
"version": "3.0.0-next.2",
55
"description": "Build and Solidity compilation system for Hardhat",
66
"homepage": "https://github.com/nomicfoundation/hardhat/tree/main/v-next/hardhat-build-system",
77
"repository": {
@@ -13,6 +13,9 @@
1313
"license": "MIT",
1414
"type": "module",
1515
"types": "dist/src/index.d.ts",
16+
"exports": {
17+
".": "./dist/src/index.js"
18+
},
1619
"keywords": [
1720
"ethereum",
1821
"smart-contracts",
@@ -38,8 +41,8 @@
3841
"README.md"
3942
],
4043
"dependencies": {
41-
"@ignored/hardhat-vnext-errors": "workspace:^3.0.0-next.0",
42-
"@ignored/hardhat-vnext-utils": "workspace:^3.0.0-next.0",
44+
"@ignored/hardhat-vnext-errors": "workspace:^3.0.0-next.2",
45+
"@ignored/hardhat-vnext-utils": "workspace:^3.0.0-next.2",
4346
"@nomicfoundation/ethereumjs-util": "9.0.4",
4447
"@nomicfoundation/solidity-analyzer": "^0.1.0",
4548
"adm-zip": "^0.4.16",
@@ -60,8 +63,7 @@
6063
},
6164
"devDependencies": {
6265
"@eslint-community/eslint-plugin-eslint-comments": "^4.3.0",
63-
"@ignored/hardhat-vnext-node-test-reporter": "workspace:^3.0.0-next.0",
64-
"@nomicfoundation/hardhat-test-utils": "workspace:^",
66+
"@ignored/hardhat-vnext-node-test-reporter": "workspace:^3.0.0-next.2",
6567
"@types/ci-info": "^2.0.0",
6668
"@types/debug": "^4.1.4",
6769
"@types/find-up": "^2.1.1",

v-next/hardhat-build-system/src/internal/solidity/compiler/compiler-input.ts

+56-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
import type { CompilationJob, CompilerInput } from "../../types/index.js";
22

3+
const defaultSolcOutputSelection = {
4+
"*": {
5+
"*": [
6+
"abi",
7+
"evm.bytecode",
8+
"evm.deployedBytecode",
9+
"evm.methodIdentifiers",
10+
"metadata",
11+
],
12+
"": ["ast"],
13+
},
14+
} as const;
15+
316
export function getInputFromCompilationJob(
417
compilationJob: CompilationJob,
518
): CompilerInput {
@@ -18,9 +31,50 @@ export function getInputFromCompilationJob(
1831

1932
const { settings } = compilationJob.getSolcConfig();
2033

21-
return {
34+
const result = {
2235
language: "Solidity",
2336
sources,
24-
settings,
37+
settings: settings ?? {},
38+
};
39+
40+
// This code is pulled in from `resolveCompiler` in
41+
// `packages/hardhat-core/src/internal/core/config/config-resolution.ts`
42+
//
43+
// In v2 the config loading sets the default values that will be passed
44+
// to the compiler. I am pulling it to here for the moment to keep
45+
// the build system encapsulated.
46+
result.settings.optimizer = {
47+
enabled: false,
48+
runs: 200,
49+
...result.settings.optimizer,
2550
};
51+
52+
if (result.settings.outputSelection === undefined) {
53+
result.settings.outputSelection = {};
54+
}
55+
56+
for (const [file, contractSelection] of Object.entries(
57+
defaultSolcOutputSelection,
58+
)) {
59+
if (result.settings.outputSelection[file] === undefined) {
60+
result.settings.outputSelection[file] = {};
61+
}
62+
63+
for (const [contract, outputs] of Object.entries(contractSelection)) {
64+
if (result.settings.outputSelection[file][contract] === undefined) {
65+
result.settings.outputSelection[file][contract] = [];
66+
}
67+
68+
for (const output of outputs) {
69+
const includesOutput: boolean =
70+
result.settings.outputSelection[file][contract].includes(output);
71+
72+
if (!includesOutput) {
73+
result.settings.outputSelection[file][contract].push(output);
74+
}
75+
}
76+
}
77+
}
78+
79+
return result;
2680
}

v-next/hardhat-errors/src/descriptors.ts

+13
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ export const ERROR_CATEGORIES: {
7373
max: 999,
7474
websiteTitle: "Network-helpers errors",
7575
},
76+
SOLIDITY_TESTS: {
77+
min: 1000,
78+
max: 1099,
79+
websiteTitle: "Solidity tests errors",
80+
},
7681
};
7782

7883
export const ERRORS = {
@@ -685,4 +690,12 @@ This might be caused by using hardhat_reset and loadFixture calls in a testcase.
685690
websiteDescription: "Error while reverting snapshot",
686691
},
687692
},
693+
SOLIDITY_TESTS: {
694+
BUILD_INFO_NOT_FOUND_FOR_CONTRACT: {
695+
number: 1000,
696+
messageTemplate: `Build info not found for contract {fqn}`,
697+
websiteTitle: `Build info not found for contract`,
698+
websiteDescription: `Build info not found for contract while compiling Solidity test contracts.`,
699+
},
700+
},
688701
} as const;

v-next/hardhat/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@
7777
"typescript-eslint": "7.7.1"
7878
},
7979
"dependencies": {
80+
"@ignored/edr": "0.6.2-alpha.0",
81+
"@ignored/hardhat-vnext-build-system": "workspace:^3.0.0-next.2",
8082
"@ignored/hardhat-vnext-errors": "workspace:^3.0.0-next.2",
8183
"@ignored/hardhat-vnext-utils": "workspace:^3.0.0-next.2",
8284
"@ignored/hardhat-vnext-zod-utils": "workspace:^3.0.0-next.2",

0 commit comments

Comments
 (0)