Skip to content

Commit 4508170

Browse files
authored
chore: update hardhat tests (#687)
* Upgrade hardhat * Remove old patch * Sync hardhat-tests with hardhat repo * Update hardhat in other packages * Lint fixes * Replace HARDHAT_ with EDR_ in env vars
1 parent 2c2c78b commit 4508170

File tree

11 files changed

+109
-81
lines changed

11 files changed

+109
-81
lines changed

Diff for: .syncpackrc.js

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ const config = {
1010
// latest ethers v5 version
1111
pinVersion: "5.7.2",
1212
},
13+
{
14+
packages: ["**"],
15+
dependencies: ["@nomicfoundation/edr"],
16+
dependencyTypes: ["local"],
17+
},
1318
],
1419
semverGroups: [
1520
{

Diff for: crates/tools/js/benchmark/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"eslint-plugin-import": "2.27.5",
1818
"eslint-plugin-mocha": "10.4.1",
1919
"eslint-plugin-prettier": "5.2.1",
20-
"hardhat": "2.22.10",
20+
"hardhat": "2.22.12",
2121
"lodash": "^4.17.11",
2222
"mocha": "^10.0.0",
2323
"prettier": "^3.2.5",

Diff for: hardhat-tests/integration/smock/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"@types/node": "^20.0.0",
1010
"chai": "^4.3.6",
1111
"ethers": "5.7.2",
12-
"hardhat": "2.22.10",
12+
"hardhat": "2.22.12",
1313
"mocha": "^10.0.0"
1414
},
1515
"keywords": [],

Diff for: hardhat-tests/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"author": "Nomic Foundation",
55
"devDependencies": {
66
"@metamask/eth-sig-util": "^4.0.0",
7+
"@nomicfoundation/edr": "workspace:*",
78
"@nomicfoundation/ethereumjs-block": "5.0.4",
89
"@nomicfoundation/ethereumjs-common": "^4.0.4",
910
"@nomicfoundation/ethereumjs-tx": "^5.0.4",
@@ -38,7 +39,7 @@
3839
"ethereumjs-abi": "^0.6.8",
3940
"ethers": "^6.1.0",
4041
"fs-extra": "^7.0.1",
41-
"hardhat": "2.22.10",
42+
"hardhat": "2.22.12",
4243
"mocha": "^10.0.0",
4344
"prettier": "^3.2.5",
4445
"rimraf": "^3.0.2",

Diff for: hardhat-tests/test/internal/hardhat-network/stack-traces/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,6 @@ These compilers are grouped by minor version (that is, a group with all the 0.5.
6262

6363
The solidity files in each test directory are compiled (unless a cached compilation output exists) and then the `test.json` description is then executed.
6464

65-
## The `HARDHAT_TESTS_SOLC_PATH` environment variable
65+
## The `EDR_TESTS_SOLC_PATH` environment variable
6666

67-
If this variable is set, the only compiler used will be the one that is available in that path. For example, if you want to test a nightly version, you would set the envvars `HARDHAT_TESTS_SOLC_PATH=/path/to/solc-nightly-0.8.21 HARDHAT_TESTS_SOLC_VERSION=0.8.21` and then run the tests. This would only run the test files under `test-files/0_8` and `test-files/version-independent`.
67+
If this variable is set, the only compiler used will be the one that is available in that path. For example, if you want to test a nightly version, you would set the envvars `EDR_TESTS_SOLC_PATH=/path/to/solc-nightly-0.8.21 EDR_TESTS_SOLC_VERSION=0.8.21` and then run the tests. This would only run the test files under `test-files/0_8` and `test-files/version-independent`.

Diff for: hardhat-tests/test/internal/hardhat-network/stack-traces/compilation.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export async function compileFiles(
132132
if (path.isAbsolute(compilerOptions.compilerPath)) {
133133
compiler = {
134134
compilerPath: compilerOptions.compilerPath,
135-
isSolcJs: process.env.HARDHAT_TESTS_SOLC_NATIVE !== "true",
135+
isSolcJs: process.env.EDR_TESTS_SOLC_NATIVE !== "true",
136136
version: compilerOptions.solidityVersion,
137137
longVersion: compilerOptions.solidityVersion,
138138
};

Diff for: hardhat-tests/test/internal/hardhat-network/stack-traces/compilers-list.ts

+41-5
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ export const solidityCompilers: SolidityCompiler[] = [
220220
{
221221
solidityVersion: "0.8.22",
222222
compilerPath: "soljson-v0.8.22+commit.4fc1097e.js",
223-
latestSolcVersion: true,
224223
},
225224
{
226225
solidityVersion: "0.8.22",
@@ -229,12 +228,10 @@ export const solidityCompilers: SolidityCompiler[] = [
229228
runs: 200,
230229
viaIR: true,
231230
},
232-
latestSolcVersion: true,
233231
},
234232
{
235233
solidityVersion: "0.8.23",
236234
compilerPath: "soljson-v0.8.23+commit.f704f362.js",
237-
latestSolcVersion: true,
238235
},
239236
{
240237
solidityVersion: "0.8.23",
@@ -243,12 +240,10 @@ export const solidityCompilers: SolidityCompiler[] = [
243240
runs: 200,
244241
viaIR: true,
245242
},
246-
latestSolcVersion: true,
247243
},
248244
{
249245
solidityVersion: "0.8.24",
250246
compilerPath: "soljson-v0.8.24+commit.e11b9ed9.js",
251-
latestSolcVersion: true,
252247
},
253248
{
254249
solidityVersion: "0.8.24",
@@ -257,6 +252,47 @@ export const solidityCompilers: SolidityCompiler[] = [
257252
runs: 200,
258253
viaIR: true,
259254
},
255+
},
256+
{
257+
solidityVersion: "0.8.25",
258+
compilerPath: "soljson-v0.8.25+commit.b61c2a91.js",
259+
latestSolcVersion: true,
260+
},
261+
{
262+
solidityVersion: "0.8.25",
263+
compilerPath: "soljson-v0.8.25+commit.b61c2a91.js",
264+
optimizer: {
265+
runs: 200,
266+
viaIR: true,
267+
},
268+
latestSolcVersion: true,
269+
},
270+
{
271+
solidityVersion: "0.8.26",
272+
compilerPath: "soljson-v0.8.26+commit.8a97fa7a.js",
273+
latestSolcVersion: true,
274+
},
275+
{
276+
solidityVersion: "0.8.26",
277+
compilerPath: "soljson-v0.8.26+commit.8a97fa7a.js",
278+
optimizer: {
279+
runs: 200,
280+
viaIR: true,
281+
},
282+
latestSolcVersion: true,
283+
},
284+
{
285+
solidityVersion: "0.8.27",
286+
compilerPath: "soljson-v0.8.27+commit.40a35a09.js",
287+
latestSolcVersion: true,
288+
},
289+
{
290+
solidityVersion: "0.8.27",
291+
compilerPath: "soljson-v0.8.27+commit.40a35a09.js",
292+
optimizer: {
293+
runs: 200,
294+
viaIR: true,
295+
},
260296
latestSolcVersion: true,
261297
},
262298
];

Diff for: hardhat-tests/test/internal/hardhat-network/stack-traces/execution.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export async function instantiateProvider(
3131
tracingConfig: TracingConfig
3232
): Promise<EdrProviderWrapper> {
3333
const config = {
34-
hardfork: "shanghai",
34+
hardfork: "cancun",
3535
chainId: 1,
3636
networkId: 1,
3737
blockGasLimit: 10_000_000,

Diff for: hardhat-tests/test/internal/hardhat-network/stack-traces/test.ts

+23-26
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { stackTraceEntryTypeToString } from "@nomicfoundation/edr";
12
import { toBytes } from "@nomicfoundation/ethereumjs-util";
23
import { assert } from "chai";
34
import { BUILD_INFO_FORMAT_VERSION } from "hardhat/internal/constants";
@@ -23,7 +24,7 @@ import {
2324
StackTraceEntryType,
2425
} from "hardhat/internal/hardhat-network/stack-traces/solidity-stack-trace";
2526
import { SolidityTracer } from "hardhat/internal/hardhat-network/stack-traces/solidityTracer";
26-
import { VmTraceDecoder } from "hardhat/internal/hardhat-network/stack-traces/vm-trace-decoder";
27+
import { VmTraceDecoderT } from "hardhat/internal/hardhat-network/stack-traces/vm-trace-decoder";
2728
import { SUPPORTED_SOLIDITY_VERSION_RANGE } from "hardhat/internal/hardhat-network/stack-traces/constants";
2829
import {
2930
BuildInfo,
@@ -248,7 +249,7 @@ async function compileIfNecessary(
248249
fs.statSync(inputPath).ctimeMs > maxSourceCtime &&
249250
fs.statSync(outputPath).ctimeMs > maxSourceCtime;
250251

251-
const usingCustomSolc = process.env.HARDHAT_TESTS_SOLC_PATH !== undefined;
252+
const usingCustomSolc = process.env.EDR_TESTS_SOLC_PATH !== undefined;
252253

253254
if (!usingCustomSolc && isCached) {
254255
const inputJson = fs.readFileSync(inputPath, "utf8");
@@ -303,7 +304,7 @@ function compareStackTraces(
303304
const actual = trace[i];
304305
const expected = description[i];
305306

306-
const actualErrorType = StackTraceEntryType[actual.type];
307+
const actualErrorType = stackTraceEntryTypeToString(actual.type);
307308
const expectedErrorType = expected.type;
308309

309310
if (
@@ -322,19 +323,15 @@ function compareStackTraces(
322323
`Stack trace of tx ${txIndex} entry ${i} type is incorrect: expected ${expectedErrorType}, got ${actualErrorType}`
323324
);
324325

325-
const actualMessage = "message" in actual ? actual.message : undefined;
326-
327-
// actual.message is a ReturnData in revert errors, but a string
328-
// in custom errors
329-
let decodedMessage = "";
330-
if (typeof actualMessage === "string") {
331-
decodedMessage = actualMessage;
332-
} else if (
333-
actualMessage instanceof ReturnData &&
334-
actualMessage.isErrorReturnData()
335-
) {
336-
decodedMessage = actualMessage.decodeError();
337-
}
326+
// actual.message is a ReturnData in revert errors but in custom errors
327+
// we need to decode it
328+
const decodedMessage =
329+
"message" in actual
330+
? actual.message
331+
: "returnData" in actual &&
332+
new ReturnData(actual.returnData).isErrorReturnData()
333+
? new ReturnData(actual.returnData).decodeError()
334+
: "";
338335

339336
if (expected.message !== undefined) {
340337
assert.equal(
@@ -482,6 +479,7 @@ async function runTest(
482479
};
483480

484481
const logger = new FakeModulesLogger();
482+
const solidityTracer = new SolidityTracer();
485483
const provider = await instantiateProvider(
486484
{
487485
enabled: false,
@@ -529,17 +527,15 @@ async function runTest(
529527
);
530528
}
531529

532-
compareConsoleLogs(logger.lines, tx.consoleLogs);
533-
534530
// eslint-disable-next-line @typescript-eslint/dot-notation
535-
const vmTraceDecoder = provider["_vmTraceDecoder"] as VmTraceDecoder;
531+
const vmTraceDecoder = provider["_vmTraceDecoder"] as VmTraceDecoderT;
536532
const decodedTrace = vmTraceDecoder.tryToDecodeMessageTrace(trace);
537533

538534
try {
539535
if (tx.stackTrace === undefined) {
540536
assert.isFalse(
541537
trace.exit.isError(),
542-
`Transaction ${txIndex} shouldn't have failed`
538+
`Transaction ${txIndex} shouldn't have failed (${trace.exit.getReason()})`
543539
);
544540
} else {
545541
assert.isDefined(
@@ -554,7 +550,6 @@ async function runTest(
554550
}
555551

556552
if (trace.exit.isError()) {
557-
const solidityTracer = new SolidityTracer();
558553
const stackTrace = solidityTracer.getStackTrace(decodedTrace);
559554

560555
try {
@@ -575,6 +570,8 @@ async function runTest(
575570
throw err;
576571
}
577572
}
573+
574+
compareConsoleLogs(logger.lines, tx.consoleLogs);
578575
}
579576
}
580577

@@ -717,7 +714,7 @@ async function runCallTransactionTest(
717714
}
718715

719716
const onlyLatestSolcVersions =
720-
process.env.HARDHAT_TESTS_ALL_SOLC_VERSIONS === undefined;
717+
process.env.EDR_TESTS_ALL_SOLC_VERSIONS === undefined;
721718

722719
const filterSolcVersionBy =
723720
(versionRange: string) =>
@@ -747,19 +744,19 @@ describe("Stack traces", function () {
747744

748745
// if a path to a solc file was specified, we only run these tests and use
749746
// that compiler
750-
const customSolcPath = process.env.HARDHAT_TESTS_SOLC_PATH;
747+
const customSolcPath = process.env.EDR_TESTS_SOLC_PATH;
751748
if (customSolcPath !== undefined) {
752-
const customSolcVersion = process.env.HARDHAT_TESTS_SOLC_VERSION;
749+
const customSolcVersion = process.env.EDR_TESTS_SOLC_VERSION;
753750

754751
if (customSolcVersion === undefined) {
755752
console.error(
756-
"HARDHAT_TESTS_SOLC_VERSION has to be set when using HARDHAT_TESTS_SOLC_PATH"
753+
"EDR_TESTS_SOLC_VERSION has to be set when using EDR_TESTS_SOLC_PATH"
757754
);
758755
process.exit(1);
759756
}
760757

761758
if (!path.isAbsolute(customSolcPath)) {
762-
console.error("HARDHAT_TESTS_SOLC_PATH has to be an absolute path");
759+
console.error("EDR_TESTS_SOLC_PATH has to be an absolute path");
763760
process.exit(1);
764761
}
765762

Diff for: patches/[email protected]

-13
This file was deleted.

0 commit comments

Comments
 (0)