Add verbosity for all hh tasks#7983
Conversation
🦋 Changeset detectedLatest commit: 96b785c The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
hardhatTotal size of the bundle: List of dependencies (sorted by size) |
| @@ -0,0 +1,203 @@ | |||
| import type { Colorizer } from "../../../../utils/colorizer.js"; | |||
There was a problem hiding this comment.
These functions have been moved from hardhat/src/internal/builtin-plugins/solidity-test/formatters.ts, except for verbosityToIncludeTraces, which is a newly added function.
| ); | ||
| } | ||
|
|
||
| function formatInputs( |
There was a problem hiding this comment.
These functions starting from this one have been moved to v-next/hardhat/src/internal/builtin-plugins/network-manager/edr/utils/trace-formatters.ts because this logic is no longer limited to solidity tests
| return `${sourceName}:${artifactId.name}`; | ||
| } | ||
|
|
||
| export function formatLogs( |
There was a problem hiding this comment.
removed as it is not used anywhere
| import { bytesToHexString } from "@nomicfoundation/hardhat-utils/hex"; | ||
| import chalk from "chalk"; | ||
|
|
||
| export interface Colorizer { |
There was a problem hiding this comment.
moved to file v-next/hardhat/src/internal/utils/colorizer.ts because this logic is no longer limited to solidity tests
v-next/hardhat/src/internal/builtin-plugins/network-manager/edr/edr-provider.ts
Outdated
Show resolved
Hide resolved
| task(["task4"]).addLevel({ | ||
| name: "verbosity", | ||
| shortName: "v", | ||
| name: "logLevel", |
There was a problem hiding this comment.
verbosity custom param used in these tests clashes with the ne added global flag verbosity, so I replaced the custom param with logLevel
| failed: false, | ||
| gas: 21000, | ||
| returnValue: "", | ||
| returnValue: "0x", |
There was a problem hiding this comment.
Before hardhat used edrRpcDebugTraceToHardhat that was converting to "", now we use EDR response directly
|
@ChristopherDedominici can you add an explanation about how this works from the user POV? When are the traces printed? How? Some screenshots would also help. Thanks! |
v-next/hardhat/src/internal/builtin-plugins/network-manager/edr/utils/trace-formatters.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
This PR introduces a new global --verbosity/-v level that controls trace output across Hardhat tasks that interact with EDR, and wires that verbosity into both Solidity test output and the EDR-backed network provider (including upgrading to EDR’s new call trace plumbing).
Changes:
- Add
verbosityas a built-in global option and propagate it through HRE/network initialization. - Centralize trace formatting + verbosity→trace-inclusion mapping under the network-manager EDR utilities, and update Solidity test reporter/helpers accordingly.
- Enable provider-side call trace collection/printing by passing
includeCallTracesinto EDR provider config based on global verbosity.
Reviewed changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| v-next/hardhat/src/internal/builtin-global-options.ts | Adds global verbosity level option (-v/--verbosity) with default. |
| v-next/hardhat/src/types/global-options.ts | Extends GlobalOptions with verbosity: number. |
| v-next/hardhat/src/internal/utils/colorizer.ts | Introduces shared Colorizer interface for trace formatting/reporting. |
| v-next/hardhat/src/internal/builtin-plugins/network-manager/network-manager.ts | Threads verbosity into network manager and maps it to includeCallTraces. |
| v-next/hardhat/src/internal/builtin-plugins/network-manager/hook-handlers/hre.ts | Passes hre.globalOptions.verbosity into NetworkManagerImplementation. |
| v-next/hardhat/src/internal/builtin-plugins/network-manager/edr/utils/trace-formatters.ts | New shared formatTraces + verbosityToIncludeTraces. |
| v-next/hardhat/src/internal/builtin-plugins/network-manager/edr/edr-provider.ts | Adds includeCallTraces to provider config and prints call traces from responses. |
| v-next/hardhat/src/internal/builtin-plugins/solidity-test/helpers.ts | Uses shared verbosity→IncludeTraces mapping. |
| v-next/hardhat/src/internal/builtin-plugins/solidity-test/reporter.ts | Imports shared formatTraces and updates trace printing thresholds. |
| v-next/hardhat/src/internal/builtin-plugins/solidity-test/task-action.ts | Reads verbosity from hre.globalOptions instead of task args. |
| v-next/hardhat/src/internal/builtin-plugins/test/index.ts | Removes per-task verbosity level (now global). |
| v-next/hardhat/src/internal/builtin-plugins/test/task-action.ts | Stops forwarding task-level verbosity option (now global). |
| v-next/hardhat-utils/src/env.ts | Allows numeric global options to be set as env vars. |
| v-next/hardhat/test/internal/hre-initialization.ts | Updates expected resolved global options to include verbosity. |
| v-next/hardhat/test/internal/cli/main.ts | Updates CLI help expectations + avoids name collision by renaming a test level arg. |
| v-next/hardhat/test/internal/cli/help/get-global-help-string.ts | Updates global help string expectations to include verbosity. |
| v-next/hardhat/test/internal/builtin-plugins/solidity-test/helpers.ts | Updates IncludeTraces expectations for new verbosity thresholds. |
| v-next/hardhat/test/internal/builtin-plugins/network-manager/network-manager.ts | Updates NetworkManager tests for the new verbosity constructor param. |
| v-next/hardhat/test/internal/builtin-plugins/network-manager/edr/utils/trace-formatters.ts | Updates/extends tests for shared trace utilities. |
| .changeset/cyan-drinks-beg.md | Changeset entry announcing global verbosity support. |
You can also share your feedback on Copilot code review. Take the survey.
| #outputCallTraces(edrResponse: Response): void { | ||
| try { | ||
| const callTraces = edrResponse.callTraces(); | ||
|
|
||
| if (callTraces.length > 0) { | ||
| const formatted = formatTraces(callTraces, " ", chalk); | ||
| this.#printLineFn(" Call Traces:"); | ||
| this.#printLineFn(formatted); | ||
| } | ||
| } catch (e) { | ||
| log("Failed to get call traces: %O", e); | ||
| } | ||
| } |
There was a problem hiding this comment.
#handleEdrResponse calls #outputCallTraces for every JSON-RPC response, and #outputCallTraces always calls edrResponse.callTraces(). Consider storing the configured includeCallTraces on the provider instance and returning early when it’s IncludeTraces.None/undefined to avoid unnecessary per-request work (and potential debug spam if callTraces() throws when disabled).
There was a problem hiding this comment.
This piece of feedback is valuable, for performance reasons. So that we don't call callTraces if not needed, which goes through the FFI barrier.
There was a problem hiding this comment.
This is already fixed in the PR on top of this one, see here: https://github.com/NomicFoundation/hardhat/pull/8031/changes#r3000654383
v-next/hardhat/src/internal/builtin-plugins/network-manager/edr/edr-provider.ts
Outdated
Show resolved
Hide resolved
alcuadrado
left a comment
There was a problem hiding this comment.
Looks good, but we should address this comment: https://github.com/NomicFoundation/hardhat/pull/7983/changes#r3000591649
.changeset/cyan-drinks-beg.md
Outdated
| "hardhat": patch | ||
| --- | ||
|
|
||
| Added `-v` verbosity support for all tasks ([7983](https://github.com/NomicFoundation/hardhat/pull/7983)), ([7963](https://github.com/NomicFoundation/hardhat/issues/7963)). |
There was a problem hiding this comment.
| Added `-v` verbosity support for all tasks ([7983](https://github.com/NomicFoundation/hardhat/pull/7983)), ([7963](https://github.com/NomicFoundation/hardhat/issues/7963)). | |
| Added `--verbosity` (and `-v`, `-vv`, and the other shorthands) to all tasks, including TypeScript tests. |
|
Actually, this comment can be better address in the second PR |
This PR implements part of the changes of this PR. See the PR for more details on the changes related to EDR.
Changes
It also implements this issue, as
verbosityis now a global flag covering all Hardhat logic, and the scope is no longer limited to Solidity tests, but to all tasks that interact with EDR.Links to website docs
PR: NomicFoundation/hardhat-website#225
How to use
Use
-vto control the level of detail in Hardhat's output. Stack multiplevs to increase verbosity.Levels
-vvv-vvvv-vvvvvFor non-test tasks (
hardhat run,hardhat ignition deploy, etc.):-vvv-vvvv/-vvvvvUsage
The flag works with any Hardhat command:
You can also use the long form:
--verbosity 3.Output examples
Examples for the same solidity tests:
Verbosity Manual Tests Scenarios
All commands run from
v-next/example-project/.Solidity tests
Mocha tests
Node.js tests
All runners combined
Non-test: scripts
Non-test: ignition deploy
Non-test: tasks