Skip to content

Commit

Permalink
chore: update hardhat tests (#687)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
fvictorio committed Sep 27, 2024
1 parent 2c2c78b commit 4508170
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 81 deletions.
5 changes: 5 additions & 0 deletions .syncpackrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ const config = {
// latest ethers v5 version
pinVersion: "5.7.2",
},
{
packages: ["**"],
dependencies: ["@nomicfoundation/edr"],
dependencyTypes: ["local"],
},
],
semverGroups: [
{
Expand Down
2 changes: 1 addition & 1 deletion crates/tools/js/benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"eslint-plugin-import": "2.27.5",
"eslint-plugin-mocha": "10.4.1",
"eslint-plugin-prettier": "5.2.1",
"hardhat": "2.22.10",
"hardhat": "2.22.12",
"lodash": "^4.17.11",
"mocha": "^10.0.0",
"prettier": "^3.2.5",
Expand Down
2 changes: 1 addition & 1 deletion hardhat-tests/integration/smock/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"@types/node": "^20.0.0",
"chai": "^4.3.6",
"ethers": "5.7.2",
"hardhat": "2.22.10",
"hardhat": "2.22.12",
"mocha": "^10.0.0"
},
"keywords": [],
Expand Down
3 changes: 2 additions & 1 deletion hardhat-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"author": "Nomic Foundation",
"devDependencies": {
"@metamask/eth-sig-util": "^4.0.0",
"@nomicfoundation/edr": "workspace:*",
"@nomicfoundation/ethereumjs-block": "5.0.4",
"@nomicfoundation/ethereumjs-common": "^4.0.4",
"@nomicfoundation/ethereumjs-tx": "^5.0.4",
Expand Down Expand Up @@ -38,7 +39,7 @@
"ethereumjs-abi": "^0.6.8",
"ethers": "^6.1.0",
"fs-extra": "^7.0.1",
"hardhat": "2.22.10",
"hardhat": "2.22.12",
"mocha": "^10.0.0",
"prettier": "^3.2.5",
"rimraf": "^3.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ These compilers are grouped by minor version (that is, a group with all the 0.5.

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

## The `HARDHAT_TESTS_SOLC_PATH` environment variable
## The `EDR_TESTS_SOLC_PATH` environment variable

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`.
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`.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export async function compileFiles(
if (path.isAbsolute(compilerOptions.compilerPath)) {
compiler = {
compilerPath: compilerOptions.compilerPath,
isSolcJs: process.env.HARDHAT_TESTS_SOLC_NATIVE !== "true",
isSolcJs: process.env.EDR_TESTS_SOLC_NATIVE !== "true",
version: compilerOptions.solidityVersion,
longVersion: compilerOptions.solidityVersion,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ export const solidityCompilers: SolidityCompiler[] = [
{
solidityVersion: "0.8.22",
compilerPath: "soljson-v0.8.22+commit.4fc1097e.js",
latestSolcVersion: true,
},
{
solidityVersion: "0.8.22",
Expand All @@ -229,12 +228,10 @@ export const solidityCompilers: SolidityCompiler[] = [
runs: 200,
viaIR: true,
},
latestSolcVersion: true,
},
{
solidityVersion: "0.8.23",
compilerPath: "soljson-v0.8.23+commit.f704f362.js",
latestSolcVersion: true,
},
{
solidityVersion: "0.8.23",
Expand All @@ -243,12 +240,10 @@ export const solidityCompilers: SolidityCompiler[] = [
runs: 200,
viaIR: true,
},
latestSolcVersion: true,
},
{
solidityVersion: "0.8.24",
compilerPath: "soljson-v0.8.24+commit.e11b9ed9.js",
latestSolcVersion: true,
},
{
solidityVersion: "0.8.24",
Expand All @@ -257,6 +252,47 @@ export const solidityCompilers: SolidityCompiler[] = [
runs: 200,
viaIR: true,
},
},
{
solidityVersion: "0.8.25",
compilerPath: "soljson-v0.8.25+commit.b61c2a91.js",
latestSolcVersion: true,
},
{
solidityVersion: "0.8.25",
compilerPath: "soljson-v0.8.25+commit.b61c2a91.js",
optimizer: {
runs: 200,
viaIR: true,
},
latestSolcVersion: true,
},
{
solidityVersion: "0.8.26",
compilerPath: "soljson-v0.8.26+commit.8a97fa7a.js",
latestSolcVersion: true,
},
{
solidityVersion: "0.8.26",
compilerPath: "soljson-v0.8.26+commit.8a97fa7a.js",
optimizer: {
runs: 200,
viaIR: true,
},
latestSolcVersion: true,
},
{
solidityVersion: "0.8.27",
compilerPath: "soljson-v0.8.27+commit.40a35a09.js",
latestSolcVersion: true,
},
{
solidityVersion: "0.8.27",
compilerPath: "soljson-v0.8.27+commit.40a35a09.js",
optimizer: {
runs: 200,
viaIR: true,
},
latestSolcVersion: true,
},
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export async function instantiateProvider(
tracingConfig: TracingConfig
): Promise<EdrProviderWrapper> {
const config = {
hardfork: "shanghai",
hardfork: "cancun",
chainId: 1,
networkId: 1,
blockGasLimit: 10_000_000,
Expand Down
49 changes: 23 additions & 26 deletions hardhat-tests/test/internal/hardhat-network/stack-traces/test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { stackTraceEntryTypeToString } from "@nomicfoundation/edr";
import { toBytes } from "@nomicfoundation/ethereumjs-util";
import { assert } from "chai";
import { BUILD_INFO_FORMAT_VERSION } from "hardhat/internal/constants";
Expand All @@ -23,7 +24,7 @@ import {
StackTraceEntryType,
} from "hardhat/internal/hardhat-network/stack-traces/solidity-stack-trace";
import { SolidityTracer } from "hardhat/internal/hardhat-network/stack-traces/solidityTracer";
import { VmTraceDecoder } from "hardhat/internal/hardhat-network/stack-traces/vm-trace-decoder";
import { VmTraceDecoderT } from "hardhat/internal/hardhat-network/stack-traces/vm-trace-decoder";
import { SUPPORTED_SOLIDITY_VERSION_RANGE } from "hardhat/internal/hardhat-network/stack-traces/constants";
import {
BuildInfo,
Expand Down Expand Up @@ -248,7 +249,7 @@ async function compileIfNecessary(
fs.statSync(inputPath).ctimeMs > maxSourceCtime &&
fs.statSync(outputPath).ctimeMs > maxSourceCtime;

const usingCustomSolc = process.env.HARDHAT_TESTS_SOLC_PATH !== undefined;
const usingCustomSolc = process.env.EDR_TESTS_SOLC_PATH !== undefined;

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

const actualErrorType = StackTraceEntryType[actual.type];
const actualErrorType = stackTraceEntryTypeToString(actual.type);
const expectedErrorType = expected.type;

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

const actualMessage = "message" in actual ? actual.message : undefined;

// actual.message is a ReturnData in revert errors, but a string
// in custom errors
let decodedMessage = "";
if (typeof actualMessage === "string") {
decodedMessage = actualMessage;
} else if (
actualMessage instanceof ReturnData &&
actualMessage.isErrorReturnData()
) {
decodedMessage = actualMessage.decodeError();
}
// actual.message is a ReturnData in revert errors but in custom errors
// we need to decode it
const decodedMessage =
"message" in actual
? actual.message
: "returnData" in actual &&
new ReturnData(actual.returnData).isErrorReturnData()
? new ReturnData(actual.returnData).decodeError()
: "";

if (expected.message !== undefined) {
assert.equal(
Expand Down Expand Up @@ -482,6 +479,7 @@ async function runTest(
};

const logger = new FakeModulesLogger();
const solidityTracer = new SolidityTracer();
const provider = await instantiateProvider(
{
enabled: false,
Expand Down Expand Up @@ -529,17 +527,15 @@ async function runTest(
);
}

compareConsoleLogs(logger.lines, tx.consoleLogs);

// eslint-disable-next-line @typescript-eslint/dot-notation
const vmTraceDecoder = provider["_vmTraceDecoder"] as VmTraceDecoder;
const vmTraceDecoder = provider["_vmTraceDecoder"] as VmTraceDecoderT;
const decodedTrace = vmTraceDecoder.tryToDecodeMessageTrace(trace);

try {
if (tx.stackTrace === undefined) {
assert.isFalse(
trace.exit.isError(),
`Transaction ${txIndex} shouldn't have failed`
`Transaction ${txIndex} shouldn't have failed (${trace.exit.getReason()})`
);
} else {
assert.isDefined(
Expand All @@ -554,7 +550,6 @@ async function runTest(
}

if (trace.exit.isError()) {
const solidityTracer = new SolidityTracer();
const stackTrace = solidityTracer.getStackTrace(decodedTrace);

try {
Expand All @@ -575,6 +570,8 @@ async function runTest(
throw err;
}
}

compareConsoleLogs(logger.lines, tx.consoleLogs);
}
}

Expand Down Expand Up @@ -717,7 +714,7 @@ async function runCallTransactionTest(
}

const onlyLatestSolcVersions =
process.env.HARDHAT_TESTS_ALL_SOLC_VERSIONS === undefined;
process.env.EDR_TESTS_ALL_SOLC_VERSIONS === undefined;

const filterSolcVersionBy =
(versionRange: string) =>
Expand Down Expand Up @@ -747,19 +744,19 @@ describe("Stack traces", function () {

// if a path to a solc file was specified, we only run these tests and use
// that compiler
const customSolcPath = process.env.HARDHAT_TESTS_SOLC_PATH;
const customSolcPath = process.env.EDR_TESTS_SOLC_PATH;
if (customSolcPath !== undefined) {
const customSolcVersion = process.env.HARDHAT_TESTS_SOLC_VERSION;
const customSolcVersion = process.env.EDR_TESTS_SOLC_VERSION;

if (customSolcVersion === undefined) {
console.error(
"HARDHAT_TESTS_SOLC_VERSION has to be set when using HARDHAT_TESTS_SOLC_PATH"
"EDR_TESTS_SOLC_VERSION has to be set when using EDR_TESTS_SOLC_PATH"
);
process.exit(1);
}

if (!path.isAbsolute(customSolcPath)) {
console.error("HARDHAT_TESTS_SOLC_PATH has to be an absolute path");
console.error("EDR_TESTS_SOLC_PATH has to be an absolute path");
process.exit(1);
}

Expand Down
13 changes: 0 additions & 13 deletions patches/[email protected]

This file was deleted.

Loading

0 comments on commit 4508170

Please sign in to comment.