From 136b21f9dfeaf544f04cacd5c74c778202b71148 Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Wed, 28 Aug 2024 10:00:51 +0200 Subject: [PATCH 01/19] Add internal helpers package --- .syncpackrc.js | 2 +- crates/edr_napi/package.json | 1 + crates/edr_napi/test/solidity-tests.ts | 38 +------- crates/tools/js/benchmark/package.json | 1 + .../tools/js/benchmark/src/solidity-tests.ts | 38 +++----- hardhat-solidity-tests/package.json | 1 + hardhat-solidity-tests/src/index.ts | 70 +++++++-------- js/.gitignore | 1 + js/helpers/.gitignore | 1 + js/helpers/package.json | 28 ++++++ js/helpers/src/index.ts | 42 +++++++++ js/helpers/tsconfig.json | 9 ++ pnpm-lock.yaml | 87 +++++++++++++++++++ pnpm-workspace.yaml | 1 + 14 files changed, 217 insertions(+), 103 deletions(-) create mode 100644 js/.gitignore create mode 100644 js/helpers/.gitignore create mode 100644 js/helpers/package.json create mode 100644 js/helpers/src/index.ts create mode 100644 js/helpers/tsconfig.json diff --git a/.syncpackrc.js b/.syncpackrc.js index 3f3a2623e..338c1829f 100644 --- a/.syncpackrc.js +++ b/.syncpackrc.js @@ -12,7 +12,7 @@ const config = { }, { packages: ["**"], - dependencies: ["@nomicfoundation/edr", "hardhat-solidity-tests"], + dependencies: ["@nomicfoundation/edr", "@nomicfoundation/edr-helpers", "hardhat-solidity-tests"], dependencyTypes: ["local"] }, ], diff --git a/crates/edr_napi/package.json b/crates/edr_napi/package.json index 4bec33a80..b387089c3 100644 --- a/crates/edr_napi/package.json +++ b/crates/edr_napi/package.json @@ -3,6 +3,7 @@ "version": "0.5.2", "devDependencies": { "@napi-rs/cli": "^2.18.1", + "@nomicfoundation/edr-helpers": "workspace:*", "@types/chai": "^4.2.0", "@types/chai-as-promised": "^7.1.8", "@types/mocha": ">=9.1.0", diff --git a/crates/edr_napi/test/solidity-tests.ts b/crates/edr_napi/test/solidity-tests.ts index 51644e48a..c74aff1be 100644 --- a/crates/edr_napi/test/solidity-tests.ts +++ b/crates/edr_napi/test/solidity-tests.ts @@ -1,37 +1,7 @@ import { assert } from "chai"; +import { runAllSolidityTests } from "@nomicfoundation/edr-helpers"; -import { - ArtifactId, - ContractData, - SuiteResult, - runSolidityTests, - Artifact, - SolidityTestRunnerConfigArgs, -} from ".."; - -// This throws an error if the tests fail -async function executeSolidityTests( - artifacts: Artifact[], - testSuites: ArtifactId[], - configArgs: SolidityTestRunnerConfigArgs -): Promise { - return new Promise((resolve, reject) => { - const resultsFromCallback: SuiteResult[] = []; - - runSolidityTests( - artifacts, - testSuites, - configArgs, - (result: SuiteResult) => { - resultsFromCallback.push(result); - if (resultsFromCallback.length === artifacts.length) { - resolve(resultsFromCallback); - } - }, - reject - ); - }); -} +import { ArtifactId, ContractData, Artifact } from ".."; describe("Solidity Tests", () => { it("executes basic tests", async function () { @@ -45,7 +15,7 @@ describe("Solidity Tests", () => { projectRoot: __dirname, }; - const results = await executeSolidityTests(artifacts, testSuites, config); + const results = await runAllSolidityTests(artifacts, testSuites, config); assert.equal(results.length, artifacts.length); @@ -77,7 +47,7 @@ describe("Solidity Tests", () => { }; await assert.isRejected( - executeSolidityTests(artifacts, testSuites, config), + runAllSolidityTests(artifacts, testSuites, config), Error ); }); diff --git a/crates/tools/js/benchmark/package.json b/crates/tools/js/benchmark/package.json index 71e85c62e..4995ae404 100644 --- a/crates/tools/js/benchmark/package.json +++ b/crates/tools/js/benchmark/package.json @@ -5,6 +5,7 @@ "author": "", "devDependencies": { "@nomicfoundation/edr": "workspace:*", + "@nomicfoundation/edr-helpers": "workspace:*", "@types/argparse": "^2.0.16", "@types/chai": "^4.2.0", "@types/lodash": "^4.14.123", diff --git a/crates/tools/js/benchmark/src/solidity-tests.ts b/crates/tools/js/benchmark/src/solidity-tests.ts index c81d36343..3bc44ff8c 100644 --- a/crates/tools/js/benchmark/src/solidity-tests.ts +++ b/crates/tools/js/benchmark/src/solidity-tests.ts @@ -6,7 +6,7 @@ import fs from "fs"; import { execSync } from "child_process"; import path from "path"; import simpleGit from "simple-git"; -import { SuiteResult, runSolidityTests } from "@nomicfoundation/edr"; +import { runAllSolidityTests } from "@nomicfoundation/edr-helpers"; const EXCLUDED_TEST_SUITES = new Set([ "StdChainsTest", @@ -64,32 +64,14 @@ export async function runForgeStdTests(forgeStdRepoPath: string) { ) .map((a) => a.id); - const results = await new Promise((resolve, reject) => { - const resultsFromCallback: SuiteResult[] = []; - const configs = { - projectRoot: forgeStdRepoPath, - fuzz: { - failurePersistDir: path.join(forgeStdRepoPath, "failures"), - }, - }; - - runSolidityTests( - artifacts, - testSuiteIds, - configs, - (result) => { - console.error( - `${result.id.name} took ${computeElapsedSec(start)} seconds` - ); - - resultsFromCallback.push(result); - if (resultsFromCallback.length === artifacts.length) { - resolve(resultsFromCallback); - } - }, - reject - ); - }); + const configs = { + projectRoot: forgeStdRepoPath, + fuzz: { + failurePersistDir: path.join(forgeStdRepoPath, "failures"), + }, + }; + const results = await runAllSolidityTests(artifacts, testSuiteIds, configs); + console.error("elapsed (s)", computeElapsedSec(start)); if (results.length !== EXPECTED_RESULTS) { @@ -103,7 +85,7 @@ export async function runForgeStdTests(forgeStdRepoPath: string) { for (const res of results) { for (const r of res.testResults) { if (r.status !== "Success") { - failed.add(`${res.name} ${r.name} ${r.status}`); + failed.add(`${res.id.name} ${r.name} ${r.status}`); } } } diff --git a/hardhat-solidity-tests/package.json b/hardhat-solidity-tests/package.json index b33594352..734fc9146 100644 --- a/hardhat-solidity-tests/package.json +++ b/hardhat-solidity-tests/package.json @@ -4,6 +4,7 @@ "author": "Nomic Foundation", "devDependencies": { "@nomicfoundation/edr": "workspace:*", + "@nomicfoundation/edr-helpers": "workspace:*", "@tsconfig/node18": "^18.2.4", "@types/node": "^20.0.0", "hardhat": "2.22.9", diff --git a/hardhat-solidity-tests/src/index.ts b/hardhat-solidity-tests/src/index.ts index 4b147af12..4fd3df92d 100644 --- a/hardhat-solidity-tests/src/index.ts +++ b/hardhat-solidity-tests/src/index.ts @@ -1,14 +1,13 @@ import { - SuiteResult, Artifact, ArtifactId, ContractData, } from "@nomicfoundation/edr"; -const { task } = require("hardhat/config"); +import { task } from "hardhat/config"; task("test:solidity").setAction(async (_: any, hre: any) => { await hre.run("compile", { quiet: true }); - const { runSolidityTests } = await import("@nomicfoundation/edr"); + const { runAllSolidityTests } = await import("@nomicfoundation/edr-helpers"); const { spec } = require("node:test/reporters"); const specReporter = new spec(); @@ -52,43 +51,34 @@ task("test:solidity").setAction(async (_: any, hre: any) => { } } - await new Promise((resolve, reject) => { - const config = { - projectRoot: hre.config.paths.root, - }; - - runSolidityTests( - artifacts, - testSuiteIds, - config, - (suiteResult: SuiteResult) => { - for (const testResult of suiteResult.testResults) { - let name = suiteResult.id.name + " | " + testResult.name; - if ("runs" in testResult?.kind) { - name += ` (${testResult.kind.runs} runs)`; - } - - let failed = testResult.status === "Failure"; - totalTests++; - if (failed) { - failedTests++; - } - - specReporter.write({ - type: failed ? "test:fail" : "test:pass", - data: { - name, - }, - }); - } - - if (totalTests === artifacts.length) { - resolve(); - } - }, - reject, - ); - }); + const config = { + projectRoot: hre.config.paths.root, + }; + + await runAllSolidityTests( + artifacts, + testSuiteIds, + config, + (suiteResult, testResult) => { + let name = suiteResult.id.name + " | " + testResult.name; + if ("runs" in testResult?.kind) { + name += ` (${testResult.kind.runs} runs)`; + } + + let failed = testResult.status === "Failure"; + totalTests++; + if (failed) { + failedTests++; + } + + specReporter.write({ + type: failed ? "test:fail" : "test:pass", + data: { + name, + }, + }); + } + ); console.log(`\n${totalTests} tests found, ${failedTests} failed`); diff --git a/js/.gitignore b/js/.gitignore new file mode 100644 index 000000000..c2658d7d1 --- /dev/null +++ b/js/.gitignore @@ -0,0 +1 @@ +node_modules/ diff --git a/js/helpers/.gitignore b/js/helpers/.gitignore new file mode 100644 index 000000000..849ddff3b --- /dev/null +++ b/js/helpers/.gitignore @@ -0,0 +1 @@ +dist/ diff --git a/js/helpers/package.json b/js/helpers/package.json new file mode 100644 index 000000000..0bd00d24f --- /dev/null +++ b/js/helpers/package.json @@ -0,0 +1,28 @@ +{ + "name": "@nomicfoundation/edr-helpers", + "description": "", + "version": "1.0.0", + "author": "", + "devDependencies": { + "@nomicfoundation/edr": "workspace:*", + "@tsconfig/node20": "^20.1.4", + "@types/node": "^20.0.0", + "@typescript-eslint/eslint-plugin": "5.61.0", + "@typescript-eslint/parser": "5.61.0", + "eslint": "^8.44.0", + "eslint-config-prettier": "9.1.0", + "eslint-plugin-import": "2.27.5", + "eslint-plugin-mocha": "10.4.1", + "eslint-plugin-prettier": "5.2.1", + "typescript": "~5.5.3" + }, + "keywords": [], + "license": "MIT", + "main": "dist/index.js", + "private": true, + "scripts": { + "build": "tsc", + "eslint": "eslint 'src/**/*.ts'" + }, + "types": "dist/index.d.ts" +} diff --git a/js/helpers/src/index.ts b/js/helpers/src/index.ts new file mode 100644 index 000000000..a1fe51507 --- /dev/null +++ b/js/helpers/src/index.ts @@ -0,0 +1,42 @@ +import { + ArtifactId, + SuiteResult, + runSolidityTests, + Artifact, + SolidityTestRunnerConfigArgs, + TestResult, +} from "@nomicfoundation/edr"; + +/** + * Run all the given solidity tests and returns the whole results after finishing. + */ +export async function runAllSolidityTests( + artifacts: Artifact[], + testSuites: ArtifactId[], + configArgs: SolidityTestRunnerConfigArgs, + testResultCallback: ( + suiteResult: SuiteResult, + testResult: TestResult + ) => void = () => {} +): Promise { + return new Promise((resolve, reject) => { + const resultsFromCallback: SuiteResult[] = []; + + runSolidityTests( + artifacts, + testSuites, + configArgs, + (suiteResult: SuiteResult) => { + for (const testResult of suiteResult.testResults) { + testResultCallback(suiteResult, testResult); + } + + resultsFromCallback.push(suiteResult); + if (resultsFromCallback.length === artifacts.length) { + resolve(resultsFromCallback); + } + }, + reject + ); + }); +} diff --git a/js/helpers/tsconfig.json b/js/helpers/tsconfig.json new file mode 100644 index 000000000..7d5dfa56c --- /dev/null +++ b/js/helpers/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "@tsconfig/node20/tsconfig.json", + "compilerOptions": { + "outDir": "./dist", + "rootDir": "./src", + "declaration": true, + "sourceMap": true + } +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bd3b7d49e..ebb56b386 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -31,6 +31,9 @@ importers: '@napi-rs/cli': specifier: ^2.18.1 version: 2.18.1 + '@nomicfoundation/edr-helpers': + specifier: workspace:* + version: link:../../js/helpers '@types/chai': specifier: ^4.2.0 version: 4.3.12 @@ -91,6 +94,9 @@ importers: '@nomicfoundation/edr': specifier: workspace:* version: link:../../../edr_napi + '@nomicfoundation/edr-helpers': + specifier: workspace:* + version: link:../../../../js/helpers '@types/argparse': specifier: ^2.0.16 version: 2.0.16 @@ -154,6 +160,9 @@ importers: '@nomicfoundation/edr': specifier: workspace:* version: link:../crates/edr_napi + '@nomicfoundation/edr-helpers': + specifier: workspace:* + version: link:../js/helpers '@tsconfig/node18': specifier: ^18.2.4 version: 18.2.4 @@ -335,6 +344,78 @@ importers: specifier: ^10.0.0 version: 10.3.0 + js/helpers: + devDependencies: + '@nomicfoundation/edr': + specifier: workspace:* + version: link:../../crates/edr_napi + '@tsconfig/node20': + specifier: ^20.1.4 + version: 20.1.4 + '@types/node': + specifier: ^20.0.0 + version: 20.16.1 + '@typescript-eslint/eslint-plugin': + specifier: 5.61.0 + version: 5.61.0(@typescript-eslint/parser@5.61.0(eslint@8.57.0)(typescript@5.5.3))(eslint@8.57.0)(typescript@5.5.3) + '@typescript-eslint/parser': + specifier: 5.61.0 + version: 5.61.0(eslint@8.57.0)(typescript@5.5.3) + eslint: + specifier: ^8.44.0 + version: 8.57.0 + eslint-config-prettier: + specifier: 9.1.0 + version: 9.1.0(eslint@8.57.0) + eslint-plugin-import: + specifier: 2.27.5 + version: 2.27.5(@typescript-eslint/parser@5.61.0(eslint@8.57.0)(typescript@5.5.3))(eslint@8.57.0) + eslint-plugin-mocha: + specifier: 10.4.1 + version: 10.4.1(eslint@8.57.0) + eslint-plugin-prettier: + specifier: 5.2.1 + version: 5.2.1(eslint-config-prettier@9.1.0(eslint@8.57.0))(eslint@8.57.0)(prettier@3.2.5) + typescript: + specifier: ~5.5.3 + version: 5.5.3 + + js/integration-tests/solidity-tests-simple: + devDependencies: + '@nomicfoundation/edr': + specifier: workspace:* + version: link:../../../crates/edr_napi + '@nomicfoundation/edr-helpers': + specifier: workspace:* + version: link:../../helpers + '@tsconfig/node20': + specifier: ^20.1.4 + version: 20.1.4 + '@types/chai': + specifier: ^4.2.0 + version: 4.3.12 + '@types/mocha': + specifier: '>=9.1.0' + version: 10.0.6 + '@types/node': + specifier: ^20.0.0 + version: 20.16.1 + chai: + specifier: ^4.3.6 + version: 4.4.1 + hardhat: + specifier: 2.22.9 + version: 2.22.9(patch_hash=ixnneac56zlmammcmucrfcq4uu)(ts-node@10.9.2(typescript@5.5.3))(typescript@5.5.3) + prettier: + specifier: ^3.2.5 + version: 3.2.5 + ts-node: + specifier: ^10.8.0 + version: 10.9.2(@types/node@20.16.1)(typescript@5.5.3) + typescript: + specifier: ~5.5.3 + version: 5.5.3 + packages: '@aashutoshrathi/word-wrap@1.2.6': @@ -924,6 +1005,9 @@ packages: '@tsconfig/node18@18.2.4': resolution: {integrity: sha512-5xxU8vVs9/FNcvm3gE07fPbn9tl6tqGGWA9tSlwsUEkBxtRnTsNmwrV8gasZ9F/EobaSv9+nu8AxUKccw77JpQ==} + '@tsconfig/node20@20.1.4': + resolution: {integrity: sha512-sqgsT69YFeLWf5NtJ4Xq/xAF8p4ZQHlmGW74Nu2tD4+g5fAsposc4ZfaaPixVu4y01BEiDCWLRDCvDM5JOsRxg==} + '@types/argparse@2.0.16': resolution: {integrity: sha512-aMqBra2JlqpFeCWOinCtpRpiCkPIXH8hahW2+FkGzvWjfE5sAqtOcrjN5DRcMnTQqFDe6gb1CVYuGnBH0lhXwA==} @@ -1882,6 +1966,7 @@ packages: glob@7.2.0: resolution: {integrity: sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==} + deprecated: Glob versions prior to v9 are no longer supported glob@8.1.0: resolution: {integrity: sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==} @@ -4027,6 +4112,8 @@ snapshots: '@tsconfig/node18@18.2.4': {} + '@tsconfig/node20@20.1.4': {} + '@types/argparse@2.0.16': {} '@types/async-eventemitter@0.2.4': diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index ac7df6767..6092f407a 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -5,3 +5,4 @@ packages: - "hardhat-tests/integration/*" - "hardhat-solidity-tests" - "hardhat-solidity-tests/example" + - "js/helpers" From 0bacb6afef73d9f5c47a03cdb7786fdb82d3f93e Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Wed, 28 Aug 2024 10:03:08 +0200 Subject: [PATCH 02/19] Js deps fixes --- hardhat-solidity-tests/example/package.json | 5 +-- hardhat-solidity-tests/package.json | 2 +- pnpm-lock.yaml | 34 ++++++++++----------- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/hardhat-solidity-tests/example/package.json b/hardhat-solidity-tests/example/package.json index 41e575807..52e634abd 100644 --- a/hardhat-solidity-tests/example/package.json +++ b/hardhat-solidity-tests/example/package.json @@ -2,9 +2,10 @@ "name": "hardhat-solidity-tests-example", "version": "0.0.1", "author": "Nomic Foundation", - "dependencies": { + "devDependencies": { "hardhat": "2.22.9", - "hardhat-solidity-tests": "workspace:*" + "hardhat-solidity-tests": "workspace:*", + "ts-node": "^10.8.0" }, "license": "MIT", "private": true, diff --git a/hardhat-solidity-tests/package.json b/hardhat-solidity-tests/package.json index 734fc9146..dd3510f83 100644 --- a/hardhat-solidity-tests/package.json +++ b/hardhat-solidity-tests/package.json @@ -5,7 +5,7 @@ "devDependencies": { "@nomicfoundation/edr": "workspace:*", "@nomicfoundation/edr-helpers": "workspace:*", - "@tsconfig/node18": "^18.2.4", + "@tsconfig/node20": "^20.1.4", "@types/node": "^20.0.0", "hardhat": "2.22.9", "typescript": "~5.5.3" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ebb56b386..cf4d095e8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -138,7 +138,7 @@ importers: version: 5.2.1(eslint-config-prettier@9.1.0(eslint@8.57.0))(eslint@8.57.0)(prettier@3.2.5) hardhat: specifier: 2.22.9 - version: 2.22.9(patch_hash=ixnneac56zlmammcmucrfcq4uu)(ts-node@10.9.2(typescript@5.5.3))(typescript@5.5.3) + version: 2.22.9(patch_hash=ixnneac56zlmammcmucrfcq4uu)(ts-node@10.9.2(@types/node@20.16.1)(typescript@5.5.3))(typescript@5.5.3) lodash: specifier: ^4.17.11 version: 4.17.21 @@ -163,27 +163,30 @@ importers: '@nomicfoundation/edr-helpers': specifier: workspace:* version: link:../js/helpers - '@tsconfig/node18': - specifier: ^18.2.4 - version: 18.2.4 + '@tsconfig/node20': + specifier: ^20.1.4 + version: 20.1.4 '@types/node': specifier: ^20.0.0 version: 20.16.1 hardhat: specifier: 2.22.9 - version: 2.22.9(patch_hash=ixnneac56zlmammcmucrfcq4uu)(ts-node@10.9.2(typescript@5.5.3))(typescript@5.5.3) + version: 2.22.9(patch_hash=ixnneac56zlmammcmucrfcq4uu)(ts-node@10.9.2(@types/node@20.16.1)(typescript@5.5.3))(typescript@5.5.3) typescript: specifier: ~5.5.3 version: 5.5.3 hardhat-solidity-tests/example: - dependencies: + devDependencies: hardhat: specifier: 2.22.9 - version: 2.22.9(patch_hash=ixnneac56zlmammcmucrfcq4uu)(ts-node@10.9.2(typescript@5.5.3))(typescript@5.5.3) + version: 2.22.9(patch_hash=ixnneac56zlmammcmucrfcq4uu)(ts-node@10.9.2(@types/node@20.16.1)(typescript@5.5.3))(typescript@5.5.3) hardhat-solidity-tests: specifier: workspace:* version: link:.. + ts-node: + specifier: ^10.8.0 + version: 10.9.2(@types/node@20.16.1)(typescript@5.5.3) hardhat-tests: devDependencies: @@ -294,7 +297,7 @@ importers: version: 7.0.1 hardhat: specifier: 2.22.9 - version: 2.22.9(patch_hash=ixnneac56zlmammcmucrfcq4uu)(ts-node@10.9.2(typescript@5.5.3))(typescript@5.5.3) + version: 2.22.9(patch_hash=ixnneac56zlmammcmucrfcq4uu)(ts-node@10.9.2(@types/node@20.16.1)(typescript@5.5.3))(typescript@5.5.3) mocha: specifier: ^10.0.0 version: 10.3.0 @@ -339,7 +342,7 @@ importers: version: 5.7.2 hardhat: specifier: 2.22.9 - version: 2.22.9(patch_hash=ixnneac56zlmammcmucrfcq4uu)(ts-node@10.9.2(typescript@5.5.3))(typescript@5.5.3) + version: 2.22.9(patch_hash=ixnneac56zlmammcmucrfcq4uu)(ts-node@10.9.2(@types/node@20.16.1)(typescript@5.5.3))(typescript@5.5.3) mocha: specifier: ^10.0.0 version: 10.3.0 @@ -405,7 +408,7 @@ importers: version: 4.4.1 hardhat: specifier: 2.22.9 - version: 2.22.9(patch_hash=ixnneac56zlmammcmucrfcq4uu)(ts-node@10.9.2(typescript@5.5.3))(typescript@5.5.3) + version: 2.22.9(patch_hash=ixnneac56zlmammcmucrfcq4uu)(ts-node@10.9.2(@types/node@20.16.1)(typescript@5.5.3))(typescript@5.5.3) prettier: specifier: ^3.2.5 version: 3.2.5 @@ -1002,9 +1005,6 @@ packages: '@tsconfig/node16@1.0.4': resolution: {integrity: sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==} - '@tsconfig/node18@18.2.4': - resolution: {integrity: sha512-5xxU8vVs9/FNcvm3gE07fPbn9tl6tqGGWA9tSlwsUEkBxtRnTsNmwrV8gasZ9F/EobaSv9+nu8AxUKccw77JpQ==} - '@tsconfig/node20@20.1.4': resolution: {integrity: sha512-sqgsT69YFeLWf5NtJ4Xq/xAF8p4ZQHlmGW74Nu2tD4+g5fAsposc4ZfaaPixVu4y01BEiDCWLRDCvDM5JOsRxg==} @@ -3491,7 +3491,7 @@ snapshots: '@nomiclabs/hardhat-ethers': 2.2.3(ethers@5.7.2)(hardhat@2.22.9(patch_hash=ixnneac56zlmammcmucrfcq4uu)(ts-node@10.9.2(@types/node@20.16.1)(typescript@5.5.3))(typescript@5.5.3)) diff: 5.0.0 ethers: 5.7.2 - hardhat: 2.22.9(patch_hash=ixnneac56zlmammcmucrfcq4uu)(ts-node@10.9.2(typescript@5.5.3))(typescript@5.5.3) + hardhat: 2.22.9(patch_hash=ixnneac56zlmammcmucrfcq4uu)(ts-node@10.9.2(@types/node@20.16.1)(typescript@5.5.3))(typescript@5.5.3) lodash.isequal: 4.5.0 lodash.isequalwith: 4.4.0 rxjs: 7.8.1 @@ -4018,7 +4018,7 @@ snapshots: '@nomiclabs/hardhat-ethers@2.2.3(ethers@5.7.2)(hardhat@2.22.9(patch_hash=ixnneac56zlmammcmucrfcq4uu)(ts-node@10.9.2(@types/node@20.16.1)(typescript@5.5.3))(typescript@5.5.3))': dependencies: ethers: 5.7.2 - hardhat: 2.22.9(patch_hash=ixnneac56zlmammcmucrfcq4uu)(ts-node@10.9.2(typescript@5.5.3))(typescript@5.5.3) + hardhat: 2.22.9(patch_hash=ixnneac56zlmammcmucrfcq4uu)(ts-node@10.9.2(@types/node@20.16.1)(typescript@5.5.3))(typescript@5.5.3) '@pkgr/core@0.1.1': {} @@ -4110,8 +4110,6 @@ snapshots: '@tsconfig/node16@1.0.4': {} - '@tsconfig/node18@18.2.4': {} - '@tsconfig/node20@20.1.4': {} '@types/argparse@2.0.16': {} @@ -5348,7 +5346,7 @@ snapshots: hard-rejection@2.1.0: {} - hardhat@2.22.9(patch_hash=ixnneac56zlmammcmucrfcq4uu)(ts-node@10.9.2(typescript@5.5.3))(typescript@5.5.3): + hardhat@2.22.9(patch_hash=ixnneac56zlmammcmucrfcq4uu)(ts-node@10.9.2(@types/node@20.16.1)(typescript@5.5.3))(typescript@5.5.3): dependencies: '@ethersproject/abi': 5.7.0 '@metamask/eth-sig-util': 4.0.1 From 43fe9be3fff9d9cf17fe77551a57ea301b100071 Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Wed, 28 Aug 2024 10:08:17 +0200 Subject: [PATCH 03/19] Add basic solidity test runner integration test --- .../solidity-tests-simple/.gitignore | 2 + .../contracts/Simple.t.sol | 12 +++ .../solidity-tests-simple/hardhat.config.ts | 3 + .../solidity-tests-simple/package.json | 28 ++++++ .../solidity-tests-simple/test/test.ts | 91 +++++++++++++++++++ .../solidity-tests-simple/tsconfig.json | 9 ++ pnpm-workspace.yaml | 1 + 7 files changed, 146 insertions(+) create mode 100644 js/integration-tests/solidity-tests-simple/.gitignore create mode 100644 js/integration-tests/solidity-tests-simple/contracts/Simple.t.sol create mode 100644 js/integration-tests/solidity-tests-simple/hardhat.config.ts create mode 100644 js/integration-tests/solidity-tests-simple/package.json create mode 100644 js/integration-tests/solidity-tests-simple/test/test.ts create mode 100644 js/integration-tests/solidity-tests-simple/tsconfig.json diff --git a/js/integration-tests/solidity-tests-simple/.gitignore b/js/integration-tests/solidity-tests-simple/.gitignore new file mode 100644 index 000000000..e7f801166 --- /dev/null +++ b/js/integration-tests/solidity-tests-simple/.gitignore @@ -0,0 +1,2 @@ +artifacts/ +cache/ diff --git a/js/integration-tests/solidity-tests-simple/contracts/Simple.t.sol b/js/integration-tests/solidity-tests-simple/contracts/Simple.t.sol new file mode 100644 index 000000000..7d046989e --- /dev/null +++ b/js/integration-tests/solidity-tests-simple/contracts/Simple.t.sol @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +contract Simple { + function testThatSucceeds() public pure { + require(1 == 1, "1 is not equal to 1"); + } + + function testThatFails() public pure { + require(1 == 2, "1 is not equal to 2"); + } +} diff --git a/js/integration-tests/solidity-tests-simple/hardhat.config.ts b/js/integration-tests/solidity-tests-simple/hardhat.config.ts new file mode 100644 index 000000000..aa42eff95 --- /dev/null +++ b/js/integration-tests/solidity-tests-simple/hardhat.config.ts @@ -0,0 +1,3 @@ +export default { + solidity: "0.8.24", +}; diff --git a/js/integration-tests/solidity-tests-simple/package.json b/js/integration-tests/solidity-tests-simple/package.json new file mode 100644 index 000000000..28f220c56 --- /dev/null +++ b/js/integration-tests/solidity-tests-simple/package.json @@ -0,0 +1,28 @@ +{ + "name": "solidity-tests-simple", + "description": "", + "version": "1.0.0", + "author": "", + "devDependencies": { + "@nomicfoundation/edr": "workspace:*", + "@nomicfoundation/edr-helpers": "workspace:*", + "@tsconfig/node20": "^20.1.4", + "@types/chai": "^4.2.0", + "@types/mocha": ">=9.1.0", + "@types/node": "^20.0.0", + "chai": "^4.3.6", + "hardhat": "2.22.9", + "prettier": "^3.2.5", + "ts-node": "^10.8.0", + "typescript": "~5.5.3" + }, + "keywords": [], + "license": "MIT", + "main": "index.js", + "private": true, + "scripts": { + "build:edr": "cd ../../../crates/edr_napi && pnpm build:test", + "pretest": "pnpm build:edr && hardhat compile", + "test": "hardhat test" + } +} diff --git a/js/integration-tests/solidity-tests-simple/test/test.ts b/js/integration-tests/solidity-tests-simple/test/test.ts new file mode 100644 index 000000000..c9780258d --- /dev/null +++ b/js/integration-tests/solidity-tests-simple/test/test.ts @@ -0,0 +1,91 @@ +import type { + Artifact, + ArtifactId, + SolidityTestRunnerConfigArgs, +} from "@nomicfoundation/edr"; +import { runAllSolidityTests } from "@nomicfoundation/edr-helpers"; +import type { Artifacts } from "hardhat/types"; +import { assert } from "chai"; +import hre from "hardhat"; + +it("test", async function () { + const { artifacts, testSuiteIds } = await buildSolidityTestsInput( + hre.artifacts + ); + + const { totalTests, failedTests } = await runTestsWithStats( + artifacts, + testSuiteIds, + { + projectRoot: hre.config.paths.root, + } + ); + + assert.equal(failedTests, 1); + assert.equal(totalTests, 2); +}); + +interface SolidityTestsRunResult { + totalTests: number; + failedTests: number; +} + +async function runTestsWithStats( + artifacts: Artifact[], + testSuiteIds: ArtifactId[], + config: SolidityTestRunnerConfigArgs +): Promise { + let totalTests = 0; + let failedTests = 0; + + const suiteResults = await runAllSolidityTests( + artifacts, + testSuiteIds, + config + ); + + for (const suiteResult of suiteResults) { + for (const testResult of suiteResult.testResults) { + let failed = testResult.status === "Failure"; + totalTests++; + if (failed) { + failedTests++; + } + } + } + return { totalTests, failedTests }; +} + +async function buildSolidityTestsInput( + hardhatArtifacts: Artifacts +): Promise<{ artifacts: Artifact[]; testSuiteIds: ArtifactId[] }> { + const fqns = await hardhatArtifacts.getAllFullyQualifiedNames(); + const artifacts: Artifact[] = []; + const testSuiteIds: ArtifactId[] = []; + + for (const fqn of fqns) { + const artifact = hardhatArtifacts.readArtifactSync(fqn); + const buildInfo = hardhatArtifacts.getBuildInfoSync(fqn); + + if (buildInfo === undefined) { + throw new Error(`Build info not found for contract ${fqn}`); + } + + const id = { + name: artifact.contractName, + solcVersion: buildInfo.solcVersion, + source: artifact.sourceName, + }; + + const contract = { + abi: JSON.stringify(artifact.abi), + bytecode: artifact.bytecode, + deployedBytecode: artifact.deployedBytecode, + }; + + artifacts.push({ id, contract }); + testSuiteIds.push(id); + } + + return { artifacts, testSuiteIds }; +} diff --git a/js/integration-tests/solidity-tests-simple/tsconfig.json b/js/integration-tests/solidity-tests-simple/tsconfig.json new file mode 100644 index 000000000..7d5dfa56c --- /dev/null +++ b/js/integration-tests/solidity-tests-simple/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "@tsconfig/node20/tsconfig.json", + "compilerOptions": { + "outDir": "./dist", + "rootDir": "./src", + "declaration": true, + "sourceMap": true + } +} diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 6092f407a..0783f2f2f 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -6,3 +6,4 @@ packages: - "hardhat-solidity-tests" - "hardhat-solidity-tests/example" - "js/helpers" + - "js/integration-tests/*" From 2e2d4aa6b5aa886f5a9a8377742b0f270ec39c49 Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Wed, 28 Aug 2024 10:17:17 +0200 Subject: [PATCH 04/19] Add buildSolidityTestsInput function to edr-helpers --- hardhat-solidity-tests/src/index.ts | 53 ++++++------------- js/helpers/package.json | 1 + js/helpers/src/index.ts | 40 ++++++++++++++ .../solidity-tests-simple/test/test.ts | 40 ++------------ pnpm-lock.yaml | 3 ++ 5 files changed, 63 insertions(+), 74 deletions(-) diff --git a/hardhat-solidity-tests/src/index.ts b/hardhat-solidity-tests/src/index.ts index 4fd3df92d..9424f20ac 100644 --- a/hardhat-solidity-tests/src/index.ts +++ b/hardhat-solidity-tests/src/index.ts @@ -1,13 +1,10 @@ -import { - Artifact, - ArtifactId, - ContractData, -} from "@nomicfoundation/edr"; import { task } from "hardhat/config"; task("test:solidity").setAction(async (_: any, hre: any) => { await hre.run("compile", { quiet: true }); - const { runAllSolidityTests } = await import("@nomicfoundation/edr-helpers"); + const { buildSolidityTestsInput, runAllSolidityTests } = await import( + "@nomicfoundation/edr-helpers" + ); const { spec } = require("node:test/reporters"); const specReporter = new spec(); @@ -17,39 +14,19 @@ task("test:solidity").setAction(async (_: any, hre: any) => { let totalTests = 0; let failedTests = 0; - const artifacts: Artifact[] = []; - const testSuiteIds: ArtifactId[] = []; - const fqns = await hre.artifacts.getAllFullyQualifiedNames(); - - for (const fqn of fqns) { - const artifact = hre.artifacts.readArtifactSync(fqn); - const buildInfo = hre.artifacts.getBuildInfoSync(fqn); - - const id = { - name: artifact.contractName, - solcVersion: buildInfo.solcVersion, - source: artifact.sourceName, - }; - - const contract: ContractData = { - abi: JSON.stringify(artifact.abi), - bytecode: artifact.bytecode, - deployedBytecode: artifact.deployedBytecode, - }; - - artifacts.push({ id, contract }); - - const sourceName = artifact.sourceName; - const isTestFile = - sourceName.endsWith(".t.sol") && - sourceName.startsWith("contracts/") && - !sourceName.startsWith("contracts/forge-std/") && - !sourceName.startsWith("contracts/ds-test/"); - - if (isTestFile) { - testSuiteIds.push(id); + const { artifacts, testSuiteIds } = await buildSolidityTestsInput( + hre.artifacts, + (artifact) => { + const sourceName = artifact.id.source; + const isTestArtifact = + sourceName.endsWith(".t.sol") && + sourceName.startsWith("contracts/") && + !sourceName.startsWith("contracts/forge-std/") && + !sourceName.startsWith("contracts/ds-test/"); + + return isTestArtifact; } - } + ); const config = { projectRoot: hre.config.paths.root, diff --git a/js/helpers/package.json b/js/helpers/package.json index 0bd00d24f..7ab491aae 100644 --- a/js/helpers/package.json +++ b/js/helpers/package.json @@ -14,6 +14,7 @@ "eslint-plugin-import": "2.27.5", "eslint-plugin-mocha": "10.4.1", "eslint-plugin-prettier": "5.2.1", + "hardhat": "2.22.9", "typescript": "~5.5.3" }, "keywords": [], diff --git a/js/helpers/src/index.ts b/js/helpers/src/index.ts index a1fe51507..d28fc353d 100644 --- a/js/helpers/src/index.ts +++ b/js/helpers/src/index.ts @@ -1,3 +1,5 @@ +import type { Artifacts as HardhatArtifacts } from "hardhat/types"; + import { ArtifactId, SuiteResult, @@ -40,3 +42,41 @@ export async function runAllSolidityTests( ); }); } + +export async function buildSolidityTestsInput( + hardhatArtifacts: HardhatArtifacts, + isTestArtifact: (artifact: Artifact) => boolean = () => true, +): Promise<{ artifacts: Artifact[]; testSuiteIds: ArtifactId[] }> { + const fqns = await hardhatArtifacts.getAllFullyQualifiedNames(); + const artifacts: Artifact[] = []; + const testSuiteIds: ArtifactId[] = []; + + for (const fqn of fqns) { + const hardhatArtifact = hardhatArtifacts.readArtifactSync(fqn); + const buildInfo = hardhatArtifacts.getBuildInfoSync(fqn); + + if (buildInfo === undefined) { + throw new Error(`Build info not found for contract ${fqn}`); + } + + const id = { + name: hardhatArtifact.contractName, + solcVersion: buildInfo.solcVersion, + source: hardhatArtifact.sourceName, + }; + + const contract = { + abi: JSON.stringify(hardhatArtifact.abi), + bytecode: hardhatArtifact.bytecode, + deployedBytecode: hardhatArtifact.deployedBytecode, + }; + + const artifact = { id, contract } + artifacts.push(artifact); + if (isTestArtifact(artifact)) { + testSuiteIds.push(artifact.id); + } + } + + return { artifacts, testSuiteIds }; +} diff --git a/js/integration-tests/solidity-tests-simple/test/test.ts b/js/integration-tests/solidity-tests-simple/test/test.ts index c9780258d..02ec11e6d 100644 --- a/js/integration-tests/solidity-tests-simple/test/test.ts +++ b/js/integration-tests/solidity-tests-simple/test/test.ts @@ -3,8 +3,10 @@ import type { ArtifactId, SolidityTestRunnerConfigArgs, } from "@nomicfoundation/edr"; -import { runAllSolidityTests } from "@nomicfoundation/edr-helpers"; -import type { Artifacts } from "hardhat/types"; +import { + buildSolidityTestsInput, + runAllSolidityTests, +} from "@nomicfoundation/edr-helpers"; import { assert } from "chai"; import hre from "hardhat"; @@ -55,37 +57,3 @@ async function runTestsWithStats( } return { totalTests, failedTests }; } - -async function buildSolidityTestsInput( - hardhatArtifacts: Artifacts -): Promise<{ artifacts: Artifact[]; testSuiteIds: ArtifactId[] }> { - const fqns = await hardhatArtifacts.getAllFullyQualifiedNames(); - const artifacts: Artifact[] = []; - const testSuiteIds: ArtifactId[] = []; - - for (const fqn of fqns) { - const artifact = hardhatArtifacts.readArtifactSync(fqn); - const buildInfo = hardhatArtifacts.getBuildInfoSync(fqn); - - if (buildInfo === undefined) { - throw new Error(`Build info not found for contract ${fqn}`); - } - - const id = { - name: artifact.contractName, - solcVersion: buildInfo.solcVersion, - source: artifact.sourceName, - }; - - const contract = { - abi: JSON.stringify(artifact.abi), - bytecode: artifact.bytecode, - deployedBytecode: artifact.deployedBytecode, - }; - - artifacts.push({ id, contract }); - testSuiteIds.push(id); - } - - return { artifacts, testSuiteIds }; -} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index cf4d095e8..52d8d0d95 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -379,6 +379,9 @@ importers: eslint-plugin-prettier: specifier: 5.2.1 version: 5.2.1(eslint-config-prettier@9.1.0(eslint@8.57.0))(eslint@8.57.0)(prettier@3.2.5) + hardhat: + specifier: 2.22.9 + version: 2.22.9(patch_hash=ixnneac56zlmammcmucrfcq4uu)(ts-node@10.9.2(@types/node@20.16.1)(typescript@5.5.3))(typescript@5.5.3) typescript: specifier: ~5.5.3 version: 5.5.3 From a0160b14861dd8857930fec8e4c678ceb32d947e Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Wed, 28 Aug 2024 10:25:53 +0200 Subject: [PATCH 05/19] Add lint script to hardhat-solidity-tests --- hardhat-solidity-tests/.eslintrc.js | 10 ++++++ .../example/hardhat.config.js | 2 +- hardhat-solidity-tests/package.json | 18 +++++++++-- hardhat-solidity-tests/src/index.ts | 2 +- hardhat-solidity-tests/tsconfig.json | 2 +- pnpm-lock.yaml | 31 +++++++++++++++---- 6 files changed, 53 insertions(+), 12 deletions(-) create mode 100644 hardhat-solidity-tests/.eslintrc.js diff --git a/hardhat-solidity-tests/.eslintrc.js b/hardhat-solidity-tests/.eslintrc.js new file mode 100644 index 000000000..8ac0961e2 --- /dev/null +++ b/hardhat-solidity-tests/.eslintrc.js @@ -0,0 +1,10 @@ +module.exports = { + extends: [`${__dirname}/../config/eslint/eslintrc.js`], + parserOptions: { + project: `${__dirname}/tsconfig.json`, + sourceType: "module", + }, + rules: { + "prefer-template": "off", + }, +}; diff --git a/hardhat-solidity-tests/example/hardhat.config.js b/hardhat-solidity-tests/example/hardhat.config.js index 3d34ea1c3..d63cd9431 100644 --- a/hardhat-solidity-tests/example/hardhat.config.js +++ b/hardhat-solidity-tests/example/hardhat.config.js @@ -1,4 +1,4 @@ -require("hardhat-solidity-tests") +require("hardhat-solidity-tests"); /** @type import('hardhat/config').HardhatUserConfig */ module.exports = { diff --git a/hardhat-solidity-tests/package.json b/hardhat-solidity-tests/package.json index dd3510f83..f4b07378c 100644 --- a/hardhat-solidity-tests/package.json +++ b/hardhat-solidity-tests/package.json @@ -2,12 +2,21 @@ "name": "hardhat-solidity-tests", "version": "0.0.1", "author": "Nomic Foundation", + "dependencies": { + "@nomicfoundation/edr-helpers": "workspace:*" + }, "devDependencies": { - "@nomicfoundation/edr": "workspace:*", - "@nomicfoundation/edr-helpers": "workspace:*", "@tsconfig/node20": "^20.1.4", "@types/node": "^20.0.0", + "@typescript-eslint/eslint-plugin": "5.61.0", + "@typescript-eslint/parser": "5.61.0", + "eslint": "^8.44.0", + "eslint-config-prettier": "9.1.0", + "eslint-plugin-import": "2.27.5", + "eslint-plugin-mocha": "10.4.1", + "eslint-plugin-prettier": "5.2.1", "hardhat": "2.22.9", + "prettier": "^3.2.5", "typescript": "~5.5.3" }, "license": "MIT", @@ -17,6 +26,9 @@ }, "private": true, "scripts": { - "build": "tsc" + "build": "tsc", + "eslint": "eslint src/**/*.ts", + "lint": "pnpm prettier && pnpm eslint", + "prettier": "prettier --check \"**/*.{js,ts,md,json}\"" } } diff --git a/hardhat-solidity-tests/src/index.ts b/hardhat-solidity-tests/src/index.ts index 9424f20ac..54f8a1ba7 100644 --- a/hardhat-solidity-tests/src/index.ts +++ b/hardhat-solidity-tests/src/index.ts @@ -42,7 +42,7 @@ task("test:solidity").setAction(async (_: any, hre: any) => { name += ` (${testResult.kind.runs} runs)`; } - let failed = testResult.status === "Failure"; + const failed = testResult.status === "Failure"; totalTests++; if (failed) { failedTests++; diff --git a/hardhat-solidity-tests/tsconfig.json b/hardhat-solidity-tests/tsconfig.json index 3fbd1404c..3bd6d66ea 100644 --- a/hardhat-solidity-tests/tsconfig.json +++ b/hardhat-solidity-tests/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "@tsconfig/node18/tsconfig.json", + "extends": "@tsconfig/node20/tsconfig.json", "compilerOptions": { "outDir": "./dist", "rootDir": "./src" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 52d8d0d95..32abbd7a7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -156,19 +156,38 @@ importers: version: 4.7.1 hardhat-solidity-tests: - devDependencies: - '@nomicfoundation/edr': - specifier: workspace:* - version: link:../crates/edr_napi + dependencies: '@nomicfoundation/edr-helpers': specifier: workspace:* version: link:../js/helpers + devDependencies: '@tsconfig/node20': specifier: ^20.1.4 version: 20.1.4 '@types/node': specifier: ^20.0.0 version: 20.16.1 + '@typescript-eslint/eslint-plugin': + specifier: 5.61.0 + version: 5.61.0(@typescript-eslint/parser@5.61.0(eslint@8.57.0)(typescript@5.5.3))(eslint@8.57.0)(typescript@5.5.3) + '@typescript-eslint/parser': + specifier: 5.61.0 + version: 5.61.0(eslint@8.57.0)(typescript@5.5.3) + eslint: + specifier: ^8.44.0 + version: 8.57.0 + eslint-config-prettier: + specifier: 9.1.0 + version: 9.1.0(eslint@8.57.0) + eslint-plugin-import: + specifier: 2.27.5 + version: 2.27.5(@typescript-eslint/parser@5.61.0(eslint@8.57.0)(typescript@5.5.3))(eslint@8.57.0) + eslint-plugin-mocha: + specifier: 10.4.1 + version: 10.4.1(eslint@8.57.0) + eslint-plugin-prettier: + specifier: 5.2.1 + version: 5.2.1(eslint-config-prettier@9.1.0(eslint@8.57.0))(eslint@8.57.0)(prettier@3.2.5) hardhat: specifier: 2.22.9 version: 2.22.9(patch_hash=ixnneac56zlmammcmucrfcq4uu)(ts-node@10.9.2(@types/node@20.16.1)(typescript@5.5.3))(typescript@5.5.3) @@ -4239,7 +4258,7 @@ snapshots: '@typescript-eslint/scope-manager': 5.61.0 '@typescript-eslint/types': 5.61.0 '@typescript-eslint/typescript-estree': 5.61.0(typescript@5.5.3) - debug: 4.3.4(supports-color@8.1.1) + debug: 4.3.5 eslint: 8.57.0 optionalDependencies: typescript: 5.5.3 @@ -4269,7 +4288,7 @@ snapshots: dependencies: '@typescript-eslint/types': 5.61.0 '@typescript-eslint/visitor-keys': 5.61.0 - debug: 4.3.4(supports-color@8.1.1) + debug: 4.3.5 globby: 11.1.0 is-glob: 4.0.3 semver: 7.6.3 From eb55760fac3c084aef23c238d5c1830d02dfd870 Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Wed, 28 Aug 2024 10:29:18 +0200 Subject: [PATCH 06/19] Add lint script to edr-helpers --- js/helpers/.eslintrc.js | 7 +++++++ js/helpers/package.json | 9 +++++++-- js/helpers/src/index.ts | 4 ++-- pnpm-lock.yaml | 9 ++++++++- 4 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 js/helpers/.eslintrc.js diff --git a/js/helpers/.eslintrc.js b/js/helpers/.eslintrc.js new file mode 100644 index 000000000..889740f22 --- /dev/null +++ b/js/helpers/.eslintrc.js @@ -0,0 +1,7 @@ +module.exports = { + extends: [`${__dirname}/../../config/eslint/eslintrc.js`], + parserOptions: { + project: `${__dirname}/tsconfig.json`, + sourceType: "module", + }, +}; diff --git a/js/helpers/package.json b/js/helpers/package.json index 7ab491aae..4e9952c2d 100644 --- a/js/helpers/package.json +++ b/js/helpers/package.json @@ -3,8 +3,10 @@ "description": "", "version": "1.0.0", "author": "", + "dependencies": { + "@nomicfoundation/edr": "workspace:*" + }, "devDependencies": { - "@nomicfoundation/edr": "workspace:*", "@tsconfig/node20": "^20.1.4", "@types/node": "^20.0.0", "@typescript-eslint/eslint-plugin": "5.61.0", @@ -15,6 +17,7 @@ "eslint-plugin-mocha": "10.4.1", "eslint-plugin-prettier": "5.2.1", "hardhat": "2.22.9", + "prettier": "^3.2.5", "typescript": "~5.5.3" }, "keywords": [], @@ -23,7 +26,9 @@ "private": true, "scripts": { "build": "tsc", - "eslint": "eslint 'src/**/*.ts'" + "eslint": "eslint 'src/**/*.ts'", + "lint": "pnpm prettier && pnpm eslint", + "prettier": "prettier --check \"**/*.{js,ts,md,json}\"" }, "types": "dist/index.d.ts" } diff --git a/js/helpers/src/index.ts b/js/helpers/src/index.ts index d28fc353d..b04de1364 100644 --- a/js/helpers/src/index.ts +++ b/js/helpers/src/index.ts @@ -45,7 +45,7 @@ export async function runAllSolidityTests( export async function buildSolidityTestsInput( hardhatArtifacts: HardhatArtifacts, - isTestArtifact: (artifact: Artifact) => boolean = () => true, + isTestArtifact: (artifact: Artifact) => boolean = () => true ): Promise<{ artifacts: Artifact[]; testSuiteIds: ArtifactId[] }> { const fqns = await hardhatArtifacts.getAllFullyQualifiedNames(); const artifacts: Artifact[] = []; @@ -71,7 +71,7 @@ export async function buildSolidityTestsInput( deployedBytecode: hardhatArtifact.deployedBytecode, }; - const artifact = { id, contract } + const artifact = { id, contract }; artifacts.push(artifact); if (isTestArtifact(artifact)) { testSuiteIds.push(artifact.id); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 32abbd7a7..60660f4ff 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -191,6 +191,9 @@ importers: hardhat: specifier: 2.22.9 version: 2.22.9(patch_hash=ixnneac56zlmammcmucrfcq4uu)(ts-node@10.9.2(@types/node@20.16.1)(typescript@5.5.3))(typescript@5.5.3) + prettier: + specifier: ^3.2.5 + version: 3.2.5 typescript: specifier: ~5.5.3 version: 5.5.3 @@ -367,10 +370,11 @@ importers: version: 10.3.0 js/helpers: - devDependencies: + dependencies: '@nomicfoundation/edr': specifier: workspace:* version: link:../../crates/edr_napi + devDependencies: '@tsconfig/node20': specifier: ^20.1.4 version: 20.1.4 @@ -401,6 +405,9 @@ importers: hardhat: specifier: 2.22.9 version: 2.22.9(patch_hash=ixnneac56zlmammcmucrfcq4uu)(ts-node@10.9.2(@types/node@20.16.1)(typescript@5.5.3))(typescript@5.5.3) + prettier: + specifier: ^3.2.5 + version: 3.2.5 typescript: specifier: ~5.5.3 version: 5.5.3 From 7ce760e26453119d3fc014466f0581d5ed8fbdd1 Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Wed, 28 Aug 2024 10:50:44 +0200 Subject: [PATCH 07/19] Add root build script --- crates/edr_napi/package.json | 6 +++--- crates/tools/js/benchmark/.gitignore | 1 + crates/tools/js/benchmark/package.json | 4 ++-- crates/tools/js/benchmark/tsconfig.json | 1 + hardhat-solidity-tests/package.json | 2 +- hardhat-tests/package.json | 6 +++--- js/helpers/package.json | 2 +- js/integration-tests/solidity-tests-simple/.gitignore | 1 + js/integration-tests/solidity-tests-simple/package.json | 4 ++-- js/integration-tests/solidity-tests-simple/tsconfig.json | 4 ++-- package.json | 2 +- 11 files changed, 18 insertions(+), 15 deletions(-) diff --git a/crates/edr_napi/package.json b/crates/edr_napi/package.json index b387089c3..28ec5b277 100644 --- a/crates/edr_napi/package.json +++ b/crates/edr_napi/package.json @@ -53,17 +53,17 @@ "repository": "NomicFoundation/edr.git", "scripts": { "artifacts": "napi artifacts", - "build": "napi build --platform --profile napi-publish", + "build": "napi build --platform --release", "build:debug": "napi build --platform", + "build:publish": "napi build --platform --profile napi-publish", "build:scenarios": "napi build --platform --release --features scenarios", - "build:test": "napi build --platform --release", "build:tracing": "napi build --platform --release --features tracing", "clean": "rm -rf @nomicfoundation/edr.node", "eslint": "eslint 'test/**/*.ts'", "lint": "pnpm run prettier && pnpm run eslint", "lint:fix": "pnpm run prettier --write", "prepublishOnly": "bash scripts/prepublish.sh", - "pretest": "pnpm build:test", + "pretest": "cd ../.. && pnpm build", "prettier": "prettier --check \"test/**.ts\"", "test": "pnpm tsc && node --max-old-space-size=8192 node_modules/mocha/bin/_mocha --recursive \"test/**/*.ts\"", "testNoBuild": "pnpm tsc && node --max-old-space-size=8192 node_modules/mocha/bin/_mocha --recursive \"test/**/*.ts\"", diff --git a/crates/tools/js/benchmark/.gitignore b/crates/tools/js/benchmark/.gitignore index e1a0096e0..778f8b2fa 100644 --- a/crates/tools/js/benchmark/.gitignore +++ b/crates/tools/js/benchmark/.gitignore @@ -1,2 +1,3 @@ node_modules forge-std +dist/ diff --git a/crates/tools/js/benchmark/package.json b/crates/tools/js/benchmark/package.json index 4995ae404..7d0aa2738 100644 --- a/crates/tools/js/benchmark/package.json +++ b/crates/tools/js/benchmark/package.json @@ -31,9 +31,10 @@ "private": true, "scripts": { "benchmark": "node --noconcurrent_sweeping --noconcurrent_recompilation --max-old-space-size=28000 --import tsx src/index.ts benchmark", + "build": "tsc --build --incremental .", "eslint": "eslint \"**/*.ts\"", "help": "tsx src/index.ts -h", - "lint": "pnpm run typecheck && pnpm run prettier && pnpm run eslint", + "lint": "pnpm run prettier && pnpm run eslint", "lint:fix": "pnpm run prettier --write", "prebenchmark": "cd ../../../edr_napi/ && pnpm build", "presoltests": "cd ../../../edr_napi/ && pnpm build", @@ -41,7 +42,6 @@ "report": "tsx src/index.ts report", "soltests": "node --noconcurrent_sweeping --noconcurrent_recompilation --max-old-space-size=28000 --import tsx src/index.ts solidity-tests", "test": "mocha --recursive --require tsx/cjs \"test/**/*.ts\"", - "typecheck": "tsc --noEmit", "verify": "tsx src/index.ts verify" } } diff --git a/crates/tools/js/benchmark/tsconfig.json b/crates/tools/js/benchmark/tsconfig.json index f0076dfb4..a1b306f16 100644 --- a/crates/tools/js/benchmark/tsconfig.json +++ b/crates/tools/js/benchmark/tsconfig.json @@ -4,6 +4,7 @@ "module": "commonjs", "esModuleInterop": true, "forceConsistentCasingInFileNames": true, + "outDir": "dist", "strict": true, "skipLibCheck": true, "resolveJsonModule": true diff --git a/hardhat-solidity-tests/package.json b/hardhat-solidity-tests/package.json index f4b07378c..a0e57d45c 100644 --- a/hardhat-solidity-tests/package.json +++ b/hardhat-solidity-tests/package.json @@ -26,7 +26,7 @@ }, "private": true, "scripts": { - "build": "tsc", + "build": "tsc --build --incremental .", "eslint": "eslint src/**/*.ts", "lint": "pnpm prettier && pnpm eslint", "prettier": "prettier --check \"**/*.{js,ts,md,json}\"" diff --git a/hardhat-tests/package.json b/hardhat-tests/package.json index 5b6fe4439..402f037f0 100644 --- a/hardhat-tests/package.json +++ b/hardhat-tests/package.json @@ -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", @@ -52,13 +53,12 @@ "license": "MIT", "repository": "github:NomicFoundation/edr", "scripts": { - "build": "tsc --build --force --incremental . && pnpm run build:edr", - "build:edr": "cd ../crates/edr_napi && pnpm build:test", + "build": "tsc --build --incremental .", "clean": "rimraf build-test tsconfig.tsbuildinfo test/internal/hardhat-network/provider/.hardhat_node_test_cache test/internal/hardhat-network/stack-traces/test-files/artifacts", "eslint": "eslint '**/*.ts'", "lint": "pnpm prettier && pnpm eslint", "lint:fix": "pnpm prettier --write && pnpm eslint --fix", - "pretest": "pnpm build", + "pretest": "cd .. && pnpm build", "prettier": "prettier --check \"**/*.{js,ts,md,json}\"", "test": "mocha --recursive \"test/**/*.ts\"", "test:ci": "pnpm test && pnpm test:integration", diff --git a/js/helpers/package.json b/js/helpers/package.json index 4e9952c2d..81d224e72 100644 --- a/js/helpers/package.json +++ b/js/helpers/package.json @@ -25,7 +25,7 @@ "main": "dist/index.js", "private": true, "scripts": { - "build": "tsc", + "build": "tsc --build --incremental .", "eslint": "eslint 'src/**/*.ts'", "lint": "pnpm prettier && pnpm eslint", "prettier": "prettier --check \"**/*.{js,ts,md,json}\"" diff --git a/js/integration-tests/solidity-tests-simple/.gitignore b/js/integration-tests/solidity-tests-simple/.gitignore index e7f801166..b83e07e2b 100644 --- a/js/integration-tests/solidity-tests-simple/.gitignore +++ b/js/integration-tests/solidity-tests-simple/.gitignore @@ -1,2 +1,3 @@ artifacts/ cache/ +dist/ diff --git a/js/integration-tests/solidity-tests-simple/package.json b/js/integration-tests/solidity-tests-simple/package.json index 28f220c56..8b72ab7ce 100644 --- a/js/integration-tests/solidity-tests-simple/package.json +++ b/js/integration-tests/solidity-tests-simple/package.json @@ -21,8 +21,8 @@ "main": "index.js", "private": true, "scripts": { - "build:edr": "cd ../../../crates/edr_napi && pnpm build:test", - "pretest": "pnpm build:edr && hardhat compile", + "build": "tsc --build --incremental .", + "pretest": "cd ../../.. && pnpm build", "test": "hardhat test" } } diff --git a/js/integration-tests/solidity-tests-simple/tsconfig.json b/js/integration-tests/solidity-tests-simple/tsconfig.json index 7d5dfa56c..b906c200c 100644 --- a/js/integration-tests/solidity-tests-simple/tsconfig.json +++ b/js/integration-tests/solidity-tests-simple/tsconfig.json @@ -2,8 +2,8 @@ "extends": "@tsconfig/node20/tsconfig.json", "compilerOptions": { "outDir": "./dist", - "rootDir": "./src", "declaration": true, "sourceMap": true - } + }, + "include": ["hardhat.config.ts", "./test/**/*.ts"] } diff --git a/package.json b/package.json index c1e018ca9..7d25178d5 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ }, "private": true, "scripts": { - "build": "cd crates/edr_napi && pnpm build", + "build": "pnpm run --recursive build", "lint": "syncpack lint && pnpm run prettier && pnpm run --recursive lint", "lint:fix": "syncpack format && pnpm run prettier:fix && pnpm run --recursive lint:fix", "prettier": "prettier --check \".github/**/*.{yml,ts,js}\" \"**/*.md\"", From 952dd4025542784b15aed764d98ab42e047a36cf Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Wed, 28 Aug 2024 10:51:33 +0200 Subject: [PATCH 08/19] Run root build script in edr-ci --- .github/workflows/edr-ci.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/edr-ci.yml b/.github/workflows/edr-ci.yml index d8d78af80..227ec7e65 100644 --- a/.github/workflows/edr-ci.yml +++ b/.github/workflows/edr-ci.yml @@ -144,8 +144,8 @@ jobs: ./.github/scripts/cargo-doc.sh shell: bash - lint: - name: Run Prettier + build-and-lint: + name: Build and lint runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -153,6 +153,8 @@ jobs: - name: Install package run: pnpm install --frozen-lockfile --prefer-offline + - name: Run build script + run: pnpm run build - name: Run lint script run: pnpm run lint From 5da60797bd3bddc0d796db86aba20e63c9b7fbf2 Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Wed, 28 Aug 2024 10:54:13 +0200 Subject: [PATCH 09/19] Use build:publish in edr-npm-release --- .github/workflows/edr-npm-release.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/edr-npm-release.yml b/.github/workflows/edr-npm-release.yml index 63daf5399..c7b3ae238 100644 --- a/.github/workflows/edr-npm-release.yml +++ b/.github/workflows/edr-npm-release.yml @@ -33,17 +33,17 @@ jobs: - host: macos-12 target: x86_64-apple-darwin build: | - pnpm build + pnpm run build:publish strip -x *.node - host: windows-2022 - build: pnpm build + build: pnpm run build:publish target: x86_64-pc-windows-msvc - host: ubuntu-22.04 target: x86_64-unknown-linux-gnu docker: ghcr.io/napi-rs/napi-rs/nodejs-rust@sha256:4b2638c0987845c4ab3488574a215a2a866b99fb28588788786f2b8cbcb40e71 build: |- set -e && - pnpm run build --target x86_64-unknown-linux-gnu && + pnpm run build:publish --target x86_64-unknown-linux-gnu && strip *.node - host: ubuntu-22.04 target: x86_64-unknown-linux-musl @@ -51,12 +51,12 @@ jobs: build: |- apk add perl; set -e && - pnpm run build && + pnpm run build:publish && strip *.node - host: macos-12 target: aarch64-apple-darwin build: | - pnpm build --target aarch64-apple-darwin + pnpm run build:publish --target aarch64-apple-darwin strip -x *.node - host: ubuntu-22.04 target: aarch64-unknown-linux-gnu @@ -70,7 +70,7 @@ jobs: export LDFLAGS="-L/usr/aarch64-unknown-linux-gnu/lib/gcc/aarch64-unknown-linux-gnu/4.8.5" && export CFLAGS="-B/usr/aarch64-unknown-linux-gnu/lib/gcc/aarch64-unknown-linux-gnu/4.8.5 --sysroot=/usr/aarch64-unknown-linux-gnu/aarch64-unknown-linux-gnu/sysroot" && export CXXFLAGS="-B/usr/aarch64-unknown-linux-gnu/lib/gcc/aarch64-unknown-linux-gnu/4.8.5 --sysroot=/usr/aarch64-unknown-linux-gnu/aarch64-unknown-linux-gnu/sysroot" && - pnpm run build --target aarch64-unknown-linux-gnu && + pnpm run build:publish --target aarch64-unknown-linux-gnu && aarch64-unknown-linux-gnu-strip *.node - host: ubuntu-22.04 target: aarch64-unknown-linux-musl @@ -79,7 +79,7 @@ jobs: apk add perl; set -e && rustup target add aarch64-unknown-linux-musl && - pnpm run build --target aarch64-unknown-linux-musl && + pnpm run build:publish --target aarch64-unknown-linux-musl && /aarch64-linux-musl-cross/bin/aarch64-linux-musl-strip *.node name: stable - ${{ matrix.settings.target }} - node@18 runs-on: ${{ matrix.settings.host }} From 18484e30d40d904537a1b7856a602212bec9b3e8 Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Wed, 28 Aug 2024 10:55:32 +0200 Subject: [PATCH 10/19] Update pnpm-lock.yaml --- pnpm-lock.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 60660f4ff..613c35490 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -215,6 +215,9 @@ importers: '@metamask/eth-sig-util': specifier: ^4.0.0 version: 4.0.1 + '@nomicfoundation/edr': + specifier: workspace:* + version: link:../crates/edr_napi '@nomicfoundation/ethereumjs-block': specifier: 5.0.4 version: 5.0.4 From bdab4076b2e1d389599be79249465304778291b7 Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Wed, 28 Aug 2024 11:43:47 +0200 Subject: [PATCH 11/19] Fix run-integration-tests script --- hardhat-tests/run-integration-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hardhat-tests/run-integration-tests.sh b/hardhat-tests/run-integration-tests.sh index 11c1a3202..3ae97d04b 100755 --- a/hardhat-tests/run-integration-tests.sh +++ b/hardhat-tests/run-integration-tests.sh @@ -2,7 +2,7 @@ set -e -pnpm build:edr +(cd .. && pnpm build) cd integration for i in *; do From 271112fdff467f7a02eee50b90abd587ab58d75b Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Wed, 28 Aug 2024 11:47:52 +0200 Subject: [PATCH 12/19] Remove circular dependency between edr and edr-helpers --- crates/edr_napi/package.json | 1 - crates/edr_napi/test/solidity-tests.ts | 33 ++++++++++++++++++++++++-- pnpm-lock.yaml | 3 --- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/crates/edr_napi/package.json b/crates/edr_napi/package.json index 28ec5b277..09b51f436 100644 --- a/crates/edr_napi/package.json +++ b/crates/edr_napi/package.json @@ -3,7 +3,6 @@ "version": "0.5.2", "devDependencies": { "@napi-rs/cli": "^2.18.1", - "@nomicfoundation/edr-helpers": "workspace:*", "@types/chai": "^4.2.0", "@types/chai-as-promised": "^7.1.8", "@types/mocha": ">=9.1.0", diff --git a/crates/edr_napi/test/solidity-tests.ts b/crates/edr_napi/test/solidity-tests.ts index c74aff1be..da39d150e 100644 --- a/crates/edr_napi/test/solidity-tests.ts +++ b/crates/edr_napi/test/solidity-tests.ts @@ -1,7 +1,13 @@ import { assert } from "chai"; -import { runAllSolidityTests } from "@nomicfoundation/edr-helpers"; -import { ArtifactId, ContractData, Artifact } from ".."; +import { + ArtifactId, + ContractData, + Artifact, + runSolidityTests, + SolidityTestRunnerConfigArgs, + SuiteResult, +} from ".."; describe("Solidity Tests", () => { it("executes basic tests", async function () { @@ -73,3 +79,26 @@ function loadContract(artifactPath: string): Artifact { contract, }; } + +async function runAllSolidityTests( + artifacts: Artifact[], + testSuites: ArtifactId[], + configArgs: SolidityTestRunnerConfigArgs +): Promise { + return new Promise((resolve, reject) => { + const resultsFromCallback: SuiteResult[] = []; + + runSolidityTests( + artifacts, + testSuites, + configArgs, + (suiteResult: SuiteResult) => { + resultsFromCallback.push(suiteResult); + if (resultsFromCallback.length === artifacts.length) { + resolve(resultsFromCallback); + } + }, + reject + ); + }); +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 613c35490..15811b20f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -31,9 +31,6 @@ importers: '@napi-rs/cli': specifier: ^2.18.1 version: 2.18.1 - '@nomicfoundation/edr-helpers': - specifier: workspace:* - version: link:../../js/helpers '@types/chai': specifier: ^4.2.0 version: 4.3.12 From 12457842ac8d6717d91b9f2c67c603d119411426 Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Wed, 28 Aug 2024 14:17:06 +0200 Subject: [PATCH 13/19] Fix pre-scripts in benchmark --- crates/tools/js/benchmark/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/tools/js/benchmark/package.json b/crates/tools/js/benchmark/package.json index 7d0aa2738..fc3d38a5d 100644 --- a/crates/tools/js/benchmark/package.json +++ b/crates/tools/js/benchmark/package.json @@ -36,8 +36,8 @@ "help": "tsx src/index.ts -h", "lint": "pnpm run prettier && pnpm run eslint", "lint:fix": "pnpm run prettier --write", - "prebenchmark": "cd ../../../edr_napi/ && pnpm build", - "presoltests": "cd ../../../edr_napi/ && pnpm build", + "prebenchmark": "cd ../../../.. && pnpm build", + "presoltests": "cd ../../../.. && pnpm build", "prettier": "prettier --check \"**/*.{js,ts}\"", "report": "tsx src/index.ts report", "soltests": "node --noconcurrent_sweeping --noconcurrent_recompilation --max-old-space-size=28000 --import tsx src/index.ts solidity-tests", From 3944a9e76dd4256725abaa301f2e57a092f57d13 Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Wed, 28 Aug 2024 14:36:41 +0200 Subject: [PATCH 14/19] Install typescript in benchmark package --- crates/tools/js/benchmark/package.json | 3 ++- pnpm-lock.yaml | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/tools/js/benchmark/package.json b/crates/tools/js/benchmark/package.json index fc3d38a5d..6974c95a5 100644 --- a/crates/tools/js/benchmark/package.json +++ b/crates/tools/js/benchmark/package.json @@ -24,7 +24,8 @@ "mocha": "^10.0.0", "prettier": "^3.2.5", "simple-git": "^3.25.0", - "tsx": "^4.7.1" + "tsx": "^4.7.1", + "typescript": "~5.5.3" }, "keywords": [], "license": "ISC", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 15811b20f..01f05caef 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -151,6 +151,9 @@ importers: tsx: specifier: ^4.7.1 version: 4.7.1 + typescript: + specifier: ~5.5.3 + version: 5.5.3 hardhat-solidity-tests: dependencies: From 87ba0b1ba46092a355fc6fed9270e494ef0034f4 Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Wed, 28 Aug 2024 14:43:01 +0200 Subject: [PATCH 15/19] Remove `--silent` flag where it's not needed --- .github/workflows/edr-benchmark-feat-solidity-tests.yml | 6 +++--- .github/workflows/edr-benchmark.yml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/edr-benchmark-feat-solidity-tests.yml b/.github/workflows/edr-benchmark-feat-solidity-tests.yml index 70aa23b6e..3d2c9ee0f 100644 --- a/.github/workflows/edr-benchmark-feat-solidity-tests.yml +++ b/.github/workflows/edr-benchmark-feat-solidity-tests.yml @@ -50,13 +50,13 @@ jobs: run: pnpm test - name: Run benchmark - run: pnpm run -s benchmark + run: pnpm run benchmark - name: Validate regressions - run: pnpm run -s verify + run: pnpm run verify - name: Generate report for github-action-benchmark - run: pnpm run -s report | tee report.json + run: pnpm run --silent report | tee report.json - name: Store benchmark result uses: benchmark-action/github-action-benchmark@v1 diff --git a/.github/workflows/edr-benchmark.yml b/.github/workflows/edr-benchmark.yml index 0b21f72c2..484fdb525 100644 --- a/.github/workflows/edr-benchmark.yml +++ b/.github/workflows/edr-benchmark.yml @@ -37,13 +37,13 @@ jobs: run: pnpm test - name: Run benchmark - run: pnpm run -s benchmark + run: pnpm run benchmark - name: Validate regressions - run: pnpm run -s verify + run: pnpm run verify - name: Generate report for github-action-benchmark - run: pnpm run -s report | tee report.json + run: pnpm run --silent report | tee report.json - name: Store benchmark result uses: benchmark-action/github-action-benchmark@v1 From d6d1fd3d1e5eeb743efbde0c65b92e6a8e10e02d Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Wed, 28 Aug 2024 15:19:04 +0200 Subject: [PATCH 16/19] Use edr_napi's build:publish in prebenchmark script --- crates/tools/js/benchmark/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/tools/js/benchmark/package.json b/crates/tools/js/benchmark/package.json index 6974c95a5..33bc00173 100644 --- a/crates/tools/js/benchmark/package.json +++ b/crates/tools/js/benchmark/package.json @@ -37,8 +37,8 @@ "help": "tsx src/index.ts -h", "lint": "pnpm run prettier && pnpm run eslint", "lint:fix": "pnpm run prettier --write", - "prebenchmark": "cd ../../../.. && pnpm build", - "presoltests": "cd ../../../.. && pnpm build", + "prebenchmark": "cd ../../../.. && pnpm build && cd crates/edr_napi && pnpm build:publish", + "presoltests": "pnpm run prebenchmark", "prettier": "prettier --check \"**/*.{js,ts}\"", "report": "tsx src/index.ts report", "soltests": "node --noconcurrent_sweeping --noconcurrent_recompilation --max-old-space-size=28000 --import tsx src/index.ts solidity-tests", From c72eec934928be185d5c80058515e7c93eb1d179 Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Mon, 2 Sep 2024 10:05:32 +0200 Subject: [PATCH 17/19] Use build:publish as default build script in edr_napi --- .github/workflows/edr-ci.yml | 4 ++-- .github/workflows/edr-npm-release.yml | 14 +++++++------- crates/edr_napi/package.json | 5 +++-- crates/tools/js/benchmark/package.json | 5 +++-- hardhat-solidity-tests/package.json | 3 ++- hardhat-tests/package.json | 5 +++-- js/helpers/package.json | 3 ++- .../solidity-tests-simple/package.json | 5 +++-- package.json | 3 ++- 9 files changed, 27 insertions(+), 20 deletions(-) diff --git a/.github/workflows/edr-ci.yml b/.github/workflows/edr-ci.yml index 227ec7e65..456e4945c 100644 --- a/.github/workflows/edr-ci.yml +++ b/.github/workflows/edr-ci.yml @@ -154,7 +154,7 @@ jobs: - name: Install package run: pnpm install --frozen-lockfile --prefer-offline - name: Run build script - run: pnpm run build + run: pnpm run build:dev - name: Run lint script run: pnpm run lint @@ -169,7 +169,7 @@ jobs: run: pnpm install --frozen-lockfile --prefer-offline - name: Build edr_napi - run: cd crates/edr_napi && pnpm build + run: cd crates/edr_napi && pnpm build:dev - name: Check that there are no uncommitted changes run: git diff --exit-code diff --git a/.github/workflows/edr-npm-release.yml b/.github/workflows/edr-npm-release.yml index c7b3ae238..a169b22e4 100644 --- a/.github/workflows/edr-npm-release.yml +++ b/.github/workflows/edr-npm-release.yml @@ -33,17 +33,17 @@ jobs: - host: macos-12 target: x86_64-apple-darwin build: | - pnpm run build:publish + pnpm run build strip -x *.node - host: windows-2022 - build: pnpm run build:publish + build: pnpm run build target: x86_64-pc-windows-msvc - host: ubuntu-22.04 target: x86_64-unknown-linux-gnu docker: ghcr.io/napi-rs/napi-rs/nodejs-rust@sha256:4b2638c0987845c4ab3488574a215a2a866b99fb28588788786f2b8cbcb40e71 build: |- set -e && - pnpm run build:publish --target x86_64-unknown-linux-gnu && + pnpm run build --target x86_64-unknown-linux-gnu && strip *.node - host: ubuntu-22.04 target: x86_64-unknown-linux-musl @@ -51,12 +51,12 @@ jobs: build: |- apk add perl; set -e && - pnpm run build:publish && + pnpm run build && strip *.node - host: macos-12 target: aarch64-apple-darwin build: | - pnpm run build:publish --target aarch64-apple-darwin + pnpm run build --target aarch64-apple-darwin strip -x *.node - host: ubuntu-22.04 target: aarch64-unknown-linux-gnu @@ -70,7 +70,7 @@ jobs: export LDFLAGS="-L/usr/aarch64-unknown-linux-gnu/lib/gcc/aarch64-unknown-linux-gnu/4.8.5" && export CFLAGS="-B/usr/aarch64-unknown-linux-gnu/lib/gcc/aarch64-unknown-linux-gnu/4.8.5 --sysroot=/usr/aarch64-unknown-linux-gnu/aarch64-unknown-linux-gnu/sysroot" && export CXXFLAGS="-B/usr/aarch64-unknown-linux-gnu/lib/gcc/aarch64-unknown-linux-gnu/4.8.5 --sysroot=/usr/aarch64-unknown-linux-gnu/aarch64-unknown-linux-gnu/sysroot" && - pnpm run build:publish --target aarch64-unknown-linux-gnu && + pnpm run build --target aarch64-unknown-linux-gnu && aarch64-unknown-linux-gnu-strip *.node - host: ubuntu-22.04 target: aarch64-unknown-linux-musl @@ -79,7 +79,7 @@ jobs: apk add perl; set -e && rustup target add aarch64-unknown-linux-musl && - pnpm run build:publish --target aarch64-unknown-linux-musl && + pnpm run build --target aarch64-unknown-linux-musl && /aarch64-linux-musl-cross/bin/aarch64-linux-musl-strip *.node name: stable - ${{ matrix.settings.target }} - node@18 runs-on: ${{ matrix.settings.host }} diff --git a/crates/edr_napi/package.json b/crates/edr_napi/package.json index 09b51f436..7913cd7f0 100644 --- a/crates/edr_napi/package.json +++ b/crates/edr_napi/package.json @@ -52,8 +52,9 @@ "repository": "NomicFoundation/edr.git", "scripts": { "artifacts": "napi artifacts", - "build": "napi build --platform --release", + "build": "pnpm run build:publish", "build:debug": "napi build --platform", + "build:dev": "napi build --platform --release", "build:publish": "napi build --platform --profile napi-publish", "build:scenarios": "napi build --platform --release --features scenarios", "build:tracing": "napi build --platform --release --features tracing", @@ -62,7 +63,7 @@ "lint": "pnpm run prettier && pnpm run eslint", "lint:fix": "pnpm run prettier --write", "prepublishOnly": "bash scripts/prepublish.sh", - "pretest": "cd ../.. && pnpm build", + "pretest": "cd ../.. && pnpm build:dev", "prettier": "prettier --check \"test/**.ts\"", "test": "pnpm tsc && node --max-old-space-size=8192 node_modules/mocha/bin/_mocha --recursive \"test/**/*.ts\"", "testNoBuild": "pnpm tsc && node --max-old-space-size=8192 node_modules/mocha/bin/_mocha --recursive \"test/**/*.ts\"", diff --git a/crates/tools/js/benchmark/package.json b/crates/tools/js/benchmark/package.json index 33bc00173..3b2d99962 100644 --- a/crates/tools/js/benchmark/package.json +++ b/crates/tools/js/benchmark/package.json @@ -32,12 +32,13 @@ "private": true, "scripts": { "benchmark": "node --noconcurrent_sweeping --noconcurrent_recompilation --max-old-space-size=28000 --import tsx src/index.ts benchmark", - "build": "tsc --build --incremental .", + "build": "pnpm run build:dev", + "build:dev": "tsc --build --incremental .", "eslint": "eslint \"**/*.ts\"", "help": "tsx src/index.ts -h", "lint": "pnpm run prettier && pnpm run eslint", "lint:fix": "pnpm run prettier --write", - "prebenchmark": "cd ../../../.. && pnpm build && cd crates/edr_napi && pnpm build:publish", + "prebenchmark": "cd ../../../.. && pnpm build", "presoltests": "pnpm run prebenchmark", "prettier": "prettier --check \"**/*.{js,ts}\"", "report": "tsx src/index.ts report", diff --git a/hardhat-solidity-tests/package.json b/hardhat-solidity-tests/package.json index a0e57d45c..5a0202f58 100644 --- a/hardhat-solidity-tests/package.json +++ b/hardhat-solidity-tests/package.json @@ -26,7 +26,8 @@ }, "private": true, "scripts": { - "build": "tsc --build --incremental .", + "build": "pnpm run build:dev", + "build:dev": "tsc --build --incremental .", "eslint": "eslint src/**/*.ts", "lint": "pnpm prettier && pnpm eslint", "prettier": "prettier --check \"**/*.{js,ts,md,json}\"" diff --git a/hardhat-tests/package.json b/hardhat-tests/package.json index 402f037f0..4579ab540 100644 --- a/hardhat-tests/package.json +++ b/hardhat-tests/package.json @@ -53,12 +53,13 @@ "license": "MIT", "repository": "github:NomicFoundation/edr", "scripts": { - "build": "tsc --build --incremental .", + "build": "pnpm run build:dev", + "build:dev": "tsc --build --incremental .", "clean": "rimraf build-test tsconfig.tsbuildinfo test/internal/hardhat-network/provider/.hardhat_node_test_cache test/internal/hardhat-network/stack-traces/test-files/artifacts", "eslint": "eslint '**/*.ts'", "lint": "pnpm prettier && pnpm eslint", "lint:fix": "pnpm prettier --write && pnpm eslint --fix", - "pretest": "cd .. && pnpm build", + "pretest": "cd .. && pnpm build:dev", "prettier": "prettier --check \"**/*.{js,ts,md,json}\"", "test": "mocha --recursive \"test/**/*.ts\"", "test:ci": "pnpm test && pnpm test:integration", diff --git a/js/helpers/package.json b/js/helpers/package.json index 81d224e72..1324245cc 100644 --- a/js/helpers/package.json +++ b/js/helpers/package.json @@ -25,7 +25,8 @@ "main": "dist/index.js", "private": true, "scripts": { - "build": "tsc --build --incremental .", + "build": "pnpm run build:dev", + "build:dev": "tsc --build --incremental .", "eslint": "eslint 'src/**/*.ts'", "lint": "pnpm prettier && pnpm eslint", "prettier": "prettier --check \"**/*.{js,ts,md,json}\"" diff --git a/js/integration-tests/solidity-tests-simple/package.json b/js/integration-tests/solidity-tests-simple/package.json index 8b72ab7ce..da7e887ee 100644 --- a/js/integration-tests/solidity-tests-simple/package.json +++ b/js/integration-tests/solidity-tests-simple/package.json @@ -21,8 +21,9 @@ "main": "index.js", "private": true, "scripts": { - "build": "tsc --build --incremental .", - "pretest": "cd ../../.. && pnpm build", + "build": "pnpm run build:dev", + "build:dev": "tsc --build --incremental .", + "pretest": "cd ../../.. && pnpm build:dev", "test": "hardhat test" } } diff --git a/package.json b/package.json index 7d25178d5..683788af2 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,8 @@ }, "private": true, "scripts": { - "build": "pnpm run --recursive build", + "build": "pnpm run build:dev", + "build:dev": "pnpm run --recursive build:dev", "lint": "syncpack lint && pnpm run prettier && pnpm run --recursive lint", "lint:fix": "syncpack format && pnpm run prettier:fix && pnpm run --recursive lint:fix", "prettier": "prettier --check \".github/**/*.{yml,ts,js}\" \"**/*.md\"", From 2061ab24cf289c5ecb6dee5333b466b283a28ec0 Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Mon, 2 Sep 2024 10:14:19 +0200 Subject: [PATCH 18/19] Run integration tests in CI --- .github/workflows/edr-ci.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.github/workflows/edr-ci.yml b/.github/workflows/edr-ci.yml index 456e4945c..687653159 100644 --- a/.github/workflows/edr-ci.yml +++ b/.github/workflows/edr-ci.yml @@ -173,3 +173,16 @@ jobs: - name: Check that there are no uncommitted changes run: git diff --exit-code + + edr-integration-tests: + name: Run integration tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: ./.github/actions/setup-node + + - name: Install package + run: pnpm install --frozen-lockfile --prefer-offline + + - name: Run integration tests + run: pnpm run --recursive --filter './js/integration-tests/*' test From d725d4f008c2f45b5fd23b9e320b382b8aa8bbf3 Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Mon, 2 Sep 2024 10:49:38 +0200 Subject: [PATCH 19/19] Fix build script in root package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 683788af2..021bb1fd0 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ }, "private": true, "scripts": { - "build": "pnpm run build:dev", + "build": "pnpm run --recursive build", "build:dev": "pnpm run --recursive build:dev", "lint": "syncpack lint && pnpm run prettier && pnpm run --recursive lint", "lint:fix": "syncpack format && pnpm run prettier:fix && pnpm run --recursive lint:fix",