Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
dce7149
add verbosity for all hh tasks
ChristopherDedominici Feb 20, 2026
8e194d0
Create cyan-drinks-beg.md
ChristopherDedominici Feb 20, 2026
05bd623
set verbosity to have max logs from level 4
ChristopherDedominici Feb 24, 2026
18eb2f9
Merge branch 'edr-upgrade-25' of github.com:NomicFoundation/hardhat i…
ChristopherDedominici Feb 24, 2026
722cb9b
minor improvements
ChristopherDedominici Feb 24, 2026
71b8f0b
fix failing tests
ChristopherDedominici Feb 24, 2026
6d8c8a2
Merge branch 'main' of github.com:NomicFoundation/hardhat into edr-up…
ChristopherDedominici Feb 26, 2026
3f78af7
Merge branch 'main' of github.com:NomicFoundation/hardhat into edr-up…
ChristopherDedominici Mar 2, 2026
593a016
Merge branch 'main' of github.com:NomicFoundation/hardhat into edr-up…
ChristopherDedominici Mar 12, 2026
c917a3c
Merge branch 'main' of github.com:NomicFoundation/hardhat into edr-up…
ChristopherDedominici Mar 16, 2026
564d509
Merge branch 'main' of github.com:NomicFoundation/hardhat into edr-up…
ChristopherDedominici Mar 30, 2026
1141434
Merge branch 'edr-upgrade-25' of github.com:NomicFoundation/hardhat i…
ChristopherDedominici Mar 30, 2026
273318b
fix building error after merge
ChristopherDedominici Mar 30, 2026
7a9a64c
update changeset
ChristopherDedominici Mar 30, 2026
96b785c
Verbosity (-vvv) improve style (#8031)
ChristopherDedominici Mar 30, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/cyan-drinks-beg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@nomicfoundation/hardhat-utils": patch
"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)).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done here (I kept the links): 7a9a64c

2 changes: 1 addition & 1 deletion v-next/hardhat-utils/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { camelToSnakeCase } from "./string.js";
* with each option adhering to its definition in the globalOptionDefinitions.
*/
export function setGlobalOptionsAsEnvVariables<
T extends Record<keyof T, string | boolean>,
T extends Record<keyof T, string | boolean | number>,
>(globalOptions: T): void {
for (const [name, value] of Object.entries(globalOptions)) {
const envName = getEnvVariableNameFromGlobalOption(name);
Expand Down
16 changes: 15 additions & 1 deletion v-next/hardhat/src/internal/builtin-global-options.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import type { GlobalOptionDefinitions } from "../types/global-options.js";

import { globalFlag, globalOption } from "../config.js";
import { globalFlag, globalLevel, globalOption } from "../config.js";
import { ArgumentType } from "../types/arguments.js";

import { DEFAULT_VERBOSITY } from "./constants.js";

export const BUILTIN_GLOBAL_OPTIONS_DEFINITIONS: GlobalOptionDefinitions =
new Map([
[
Expand Down Expand Up @@ -49,6 +51,18 @@ export const BUILTIN_GLOBAL_OPTIONS_DEFINITIONS: GlobalOptionDefinitions =
}),
},
],
[
"verbosity",
{
pluginId: "builtin",
option: globalLevel({
name: "verbosity",
shortName: "v",
description: "Verbosity level of the output.",
defaultValue: DEFAULT_VERBOSITY,
}),
},
],
[
"version",
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import type {
TracingConfigWithBuffers,
AccountOverride,
GasReportConfig,
IncludeTraces,
} from "@nomicfoundation/edr";

import {
Expand All @@ -40,6 +41,7 @@ import { toSeconds } from "@nomicfoundation/hardhat-utils/date";
import { ensureError } from "@nomicfoundation/hardhat-utils/error";
import { numberToHexString } from "@nomicfoundation/hardhat-utils/hex";
import { deepEqual } from "@nomicfoundation/hardhat-utils/lang";
import chalk from "chalk";
import debug from "debug";
import { hexToBytes } from "ethereum-cryptography/utils";
import { addr } from "micro-eth-signer";
Expand Down Expand Up @@ -73,6 +75,7 @@ import {
hardhatForkingConfigToEdrForkConfig,
} from "./utils/convert-to-edr.js";
import { printLine, replaceLastLine } from "./utils/logger.js";
import { formatTraces } from "./utils/trace-formatters.js";

const log = debug("hardhat:core:hardhat-network:provider");

Expand Down Expand Up @@ -139,13 +142,15 @@ interface EdrProviderConfig {
jsonRpcRequestWrapper?: JsonRpcRequestWrapperFunction;
coverageConfig?: CoverageConfig;
gasReportConfig?: GasReportConfig;
includeCallTraces?: IncludeTraces;
}

export class EdrProvider extends BaseProvider {
readonly #jsonRpcRequestWrapper?: JsonRpcRequestWrapperFunction;

#provider: Provider | undefined;
#nextRequestId = 1;
readonly #printLineFn: (line: string) => void;

/**
* Creates a new instance of `EdrProvider`.
Expand All @@ -158,6 +163,7 @@ export class EdrProvider extends BaseProvider {
jsonRpcRequestWrapper,
coverageConfig,
gasReportConfig,
includeCallTraces,
}: EdrProviderConfig): Promise<EdrProvider> {
const printLineFn = loggerConfig.printLineFn ?? printLine;
const replaceLastLineFn = loggerConfig.replaceLastLineFn ?? replaceLastLine;
Expand All @@ -167,6 +173,7 @@ export class EdrProvider extends BaseProvider {
coverageConfig,
gasReportConfig,
chainDescriptors,
includeCallTraces,
);

let edrProvider: EdrProvider;
Expand Down Expand Up @@ -205,7 +212,11 @@ export class EdrProvider extends BaseProvider {
contractDecoder,
);

edrProvider = new EdrProvider(provider, jsonRpcRequestWrapper);
edrProvider = new EdrProvider(
provider,
printLineFn,
jsonRpcRequestWrapper,
);
} catch (error) {
ensureError(error);

Expand All @@ -225,11 +236,13 @@ export class EdrProvider extends BaseProvider {
*/
private constructor(
provider: Provider,
printLineFn: (line: string) => void,
jsonRpcRequestWrapper?: JsonRpcRequestWrapperFunction,
) {
super();

this.#provider = provider;
this.#printLineFn = printLineFn;
this.#jsonRpcRequestWrapper = jsonRpcRequestWrapper;
}

Expand Down Expand Up @@ -310,6 +323,20 @@ export class EdrProvider extends BaseProvider {
);
}

#outputCallTraces(edrResponse: Response): void {
Comment thread
ChristopherDedominici marked this conversation as resolved.
Outdated
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);
}
}

Copilot AI Mar 12, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#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).

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already fixed in the PR on top of this one, see here: https://github.com/NomicFoundation/hardhat/pull/8031/changes#r3000654383

Comment thread
ChristopherDedominici marked this conversation as resolved.
Outdated

async #handleEdrResponse(
edrResponse: Response,
): Promise<SuccessfulJsonRpcResponse> {
Expand Down Expand Up @@ -365,11 +392,15 @@ export class EdrProvider extends BaseProvider {
error.data = responseError.data;
}

this.#outputCallTraces(edrResponse);

/* eslint-disable-next-line no-restricted-syntax -- we may throw
non-Hardhat errors inside of an EthereumProvider */
throw error;
}

this.#outputCallTraces(edrResponse);

return jsonRpcResponse;
}

Expand Down Expand Up @@ -430,6 +461,7 @@ export async function getProviderConfig(
coverageConfig: CoverageConfig | undefined,
gasReportConfig: GasReportConfig | undefined,
chainDescriptors: ChainDescriptorsConfig,
includeCallTraces?: IncludeTraces,
): Promise<ProviderConfig> {
const specId = hardhatHardforkToEdrSpecId(
networkConfig.hardfork,
Expand Down Expand Up @@ -506,6 +538,7 @@ export async function getProviderConfig(
observability: {
codeCoverage: coverageConfig,
gasReport: gasReportConfig,
includeCallTraces,
},
ownedAccounts: ownedAccounts.map((account) => account.secretKey),
precompileOverrides: [],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
import type { Colorizer } from "../../../../utils/colorizer.js";

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These functions have been moved from hardhat/src/internal/builtin-plugins/solidity-test/formatters.ts, except for verbosityToIncludeTraces, which is a newly added function.

import type {
LogTrace,
CallTrace,
DecodedTraceParameters,
} from "@nomicfoundation/edr";

import { LogKind, CallKind, IncludeTraces } from "@nomicfoundation/edr";
import { assertHardhatInvariant } from "@nomicfoundation/hardhat-errors";
import { bytesToHexString } from "@nomicfoundation/hardhat-utils/hex";

type NestedArray<T> = Array<T | NestedArray<T>>;

export function verbosityToIncludeTraces(verbosity: number): IncludeTraces {
if (verbosity >= 4) {
return IncludeTraces.All;
} else if (verbosity >= 3) {
return IncludeTraces.Failing;
}

return IncludeTraces.None;
}

export function formatTraces(
traces: CallTrace[],
prefix: string,
colorizer: Colorizer,
): string {
const lines = traces.map((trace) => formatTrace(trace, colorizer));
const formattedTraces = formatNestedArray(lines, prefix);
// Remove the trailing newline
return formattedTraces.slice(0, -1);
}

function formatInputs(
inputs: DecodedTraceParameters | Uint8Array,
color?: (text: string) => string,
): string | undefined {
if (inputs instanceof Uint8Array) {
return inputs.length > 0 ? bytesToHexString(inputs) : undefined;
} else {
const formattedName =
color !== undefined ? color(inputs.name) : inputs.name;
return `${formattedName}(${inputs.arguments.join(", ")})`;
}
}

function formatOutputs(outputs: string | Uint8Array): string | undefined {
if (outputs instanceof Uint8Array) {
return outputs.length > 0 ? bytesToHexString(outputs) : undefined;
} else {
return outputs;
}
}

function formatLog(log: LogTrace, colorizer: Colorizer): string[] {
const { parameters } = log;
const lines = [];
if (Array.isArray(parameters)) {
const topics = parameters.map((topic) => bytesToHexString(topic));
if (topics.length > 0) {
lines.push(`emit topic 0: ${colorizer.cyan(topics[0])}`);
}
for (let i = 1; i < topics.length - 1; i++) {
lines.push(` topic ${i}: ${colorizer.cyan(topics[i])}`);
}
if (topics.length > 1) {
lines.push(` data: ${colorizer.cyan(topics[topics.length - 1])}`);
}
} else {
lines.push(
`emit ${parameters.name}(${colorizer.cyan(parameters.arguments.join(", "))})`,
);
}
return lines;
}

function formatKind(kind: CallKind): string | undefined {
assertHardhatInvariant(
kind !== CallKind.Create,
"Unexpected call kind 'Create'",
);

switch (kind) {
case CallKind.Call:
return undefined;
case CallKind.CallCode:
return "callcode";
case CallKind.DelegateCall:
return "delegatecall";
case CallKind.StaticCall:
return "staticcall";
}
}

function formatTrace(
trace: CallTrace,
colorizer: Colorizer,
): NestedArray<string> {
const {
success,
address,
contract,
inputs,
gasUsed,
value,
kind,
isCheatcode,
outputs,
} = trace;
let color;
if (isCheatcode) {
color = colorizer.blue;
} else if (success) {
color = colorizer.green;
} else {
color = colorizer.red;
}

const formattedInputs = formatInputs(inputs, color);
const formattedOutputs = formatOutputs(outputs);

let openingLine: string;
let closingLine: string | undefined;
if (kind === CallKind.Create) {
openingLine = `[${gasUsed}] ${colorizer.yellow("→ new")} ${contract ?? "<unknown>"}@${address}`;
// TODO: Uncomment this when the formattedInputs starts containing
// the address of where the contract was deployed instead of the code.
// if (formattedInputs !== undefined) {
// openingLine = `${openingLine}@${formattedInputs}`;
// }
} else {
const formattedKind = formatKind(kind);
openingLine = `[${gasUsed}] ${color(contract ?? address)}`;
if (formattedInputs !== undefined) {
openingLine = `${openingLine}::${formattedInputs}`;
}
if (value !== 0n) {
openingLine = `${openingLine} {value: ${value}}`;
}
if (formattedKind !== undefined) {
openingLine = `${openingLine} ${colorizer.yellow(`[${formattedKind}]`)}`;
}
}
if (formattedOutputs !== undefined) {
if (
formattedOutputs === "EvmError: Revert" ||
formattedOutputs.startsWith("revert:")
) {
closingLine = `${color("←")} ${color("[Revert]")} ${formattedOutputs}`;
} else {
closingLine = `${color("←")} ${formattedOutputs}`;
}
}

const lines = [];
lines.push(openingLine);
for (const child of trace.children) {
if (child.kind === LogKind.Log) {
lines.push(formatLog(child, colorizer));
} else {
lines.push(formatTrace(child, colorizer));
}
}
if (closingLine !== undefined) {
lines.push([closingLine]);
}
return lines;
}

function formatNestedArray(
data: NestedArray<string>,
prefix = "",
isTopLevel = true,
): string {
let output = "";

for (let i = 0; i < data.length; i++) {
const item = data[i];

if (Array.isArray(item) && typeof item[0] === "string") {
const [label, ...children] = item;

if (isTopLevel) {
output += `${prefix}${label}\n`;
output += formatNestedArray(children, prefix, false);
} else {
const isLast = i === data.length - 1;
const connector = isLast ? " └─ " : " ├─ ";
const childPrefix = isLast ? " " : " │ ";
output += `${prefix}${connector}${label}\n`;
output += formatNestedArray(children, prefix + childPrefix, false);
}
} else if (typeof item === "string") {
const isLast = i === data.length - 1;
const connector = isLast ? " └─ " : " ├─ ";
output += `${prefix}${connector}${item}\n`;
}
}

return output;
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@ async function createNetworkManager(
hre.config.chainDescriptors,
hre.globalOptions.config,
hre.config.paths.root,
hre.globalOptions.verbosity,
);
}
Loading
Loading