hardhat 3.2.0 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/dist/src/internal/builtin-global-options.d.ts.map +1 -1
- package/dist/src/internal/builtin-global-options.js +14 -1
- package/dist/src/internal/builtin-global-options.js.map +1 -1
- package/dist/src/internal/builtin-plugins/gas-analytics/helpers.d.ts +0 -5
- package/dist/src/internal/builtin-plugins/gas-analytics/helpers.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/gas-analytics/helpers.js +12 -3
- package/dist/src/internal/builtin-plugins/gas-analytics/helpers.js.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/accounts/derive-private-keys.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/accounts/derive-private-keys.js +12 -2
- package/dist/src/internal/builtin-plugins/network-manager/accounts/derive-private-keys.js.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/edr/edr-provider.d.ts +9 -3
- package/dist/src/internal/builtin-plugins/network-manager/edr/edr-provider.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/edr/edr-provider.js +65 -42
- package/dist/src/internal/builtin-plugins/network-manager/edr/edr-provider.js.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/edr/genesis-state.d.ts +11 -0
- package/dist/src/internal/builtin-plugins/network-manager/edr/genesis-state.d.ts.map +1 -0
- package/dist/src/internal/builtin-plugins/network-manager/edr/genesis-state.js +104 -0
- package/dist/src/internal/builtin-plugins/network-manager/edr/genesis-state.js.map +1 -0
- package/dist/src/internal/builtin-plugins/network-manager/edr/utils/trace-formatters.d.ts +6 -0
- package/dist/src/internal/builtin-plugins/network-manager/edr/utils/trace-formatters.d.ts.map +1 -0
- package/dist/src/internal/builtin-plugins/network-manager/edr/utils/trace-formatters.js +152 -0
- package/dist/src/internal/builtin-plugins/network-manager/edr/utils/trace-formatters.js.map +1 -0
- package/dist/src/internal/builtin-plugins/network-manager/edr/utils/trace-output.d.ts +19 -0
- package/dist/src/internal/builtin-plugins/network-manager/edr/utils/trace-output.d.ts.map +1 -0
- package/dist/src/internal/builtin-plugins/network-manager/edr/utils/trace-output.js +104 -0
- package/dist/src/internal/builtin-plugins/network-manager/edr/utils/trace-output.js.map +1 -0
- package/dist/src/internal/builtin-plugins/network-manager/hook-handlers/hre.js +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/hook-handlers/hre.js.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/hook-handlers/network.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/hook-handlers/network.js +8 -8
- package/dist/src/internal/builtin-plugins/network-manager/hook-handlers/network.js.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/http-provider.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/http-provider.js +1 -0
- package/dist/src/internal/builtin-plugins/network-manager/http-provider.js.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/network-manager.d.ts +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/network-manager.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/network-manager.js +63 -7
- package/dist/src/internal/builtin-plugins/network-manager/network-manager.js.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/request-handlers/handlers/accounts/local-accounts.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/request-handlers/handlers/accounts/local-accounts.js +56 -33
- package/dist/src/internal/builtin-plugins/network-manager/request-handlers/handlers/accounts/local-accounts.js.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/request-handlers/handlers-array.d.ts +0 -3
- package/dist/src/internal/builtin-plugins/network-manager/request-handlers/handlers-array.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/request-handlers/handlers-array.js +9 -12
- package/dist/src/internal/builtin-plugins/network-manager/request-handlers/handlers-array.js.map +1 -1
- package/dist/src/internal/builtin-plugins/node/artifacts/build-info-watcher.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/node/artifacts/build-info-watcher.js +1 -1
- package/dist/src/internal/builtin-plugins/node/artifacts/build-info-watcher.js.map +1 -1
- package/dist/src/internal/builtin-plugins/node/helpers.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/node/helpers.js +6 -2
- package/dist/src/internal/builtin-plugins/node/helpers.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/artifacts.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/artifacts.js +4 -0
- package/dist/src/internal/builtin-plugins/solidity/build-system/artifacts.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/build-system.d.ts +5 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/build-system.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/build-system.js +86 -47
- package/dist/src/internal/builtin-plugins/solidity/build-system/build-system.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/cache.d.ts +1 -0
- package/dist/src/internal/builtin-plugins/solidity/build-system/cache.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/cache.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/compilation-job.d.ts +3 -3
- package/dist/src/internal/builtin-plugins/solidity/build-system/compilation-job.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/compilation-job.js +24 -4
- package/dist/src/internal/builtin-plugins/solidity/build-system/compilation-job.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/compiler/compiler.d.ts +16 -0
- package/dist/src/internal/builtin-plugins/solidity/build-system/compiler/compiler.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/compiler/compiler.js +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/compiler/compiler.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/compiler/downloader.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/compiler/downloader.js +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/compiler/downloader.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/solc-config-selection.d.ts +2 -2
- package/dist/src/internal/builtin-plugins/solidity/build-system/solc-config-selection.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/solc-config-selection.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/config.d.ts +4 -2
- package/dist/src/internal/builtin-plugins/solidity/config.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/config.js +247 -68
- package/dist/src/internal/builtin-plugins/solidity/config.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/exports.d.ts +3 -0
- package/dist/src/internal/builtin-plugins/solidity/exports.d.ts.map +1 -0
- package/dist/src/internal/builtin-plugins/solidity/exports.js +3 -0
- package/dist/src/internal/builtin-plugins/solidity/exports.js.map +1 -0
- package/dist/src/internal/builtin-plugins/solidity/hook-handlers/config.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/hook-handlers/config.js +2 -1
- package/dist/src/internal/builtin-plugins/solidity/hook-handlers/config.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/hook-handlers/solidity.d.ts +4 -0
- package/dist/src/internal/builtin-plugins/solidity/hook-handlers/solidity.d.ts.map +1 -0
- package/dist/src/internal/builtin-plugins/solidity/hook-handlers/solidity.js +7 -0
- package/dist/src/internal/builtin-plugins/solidity/hook-handlers/solidity.js.map +1 -0
- package/dist/src/internal/builtin-plugins/solidity/index.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/index.js +1 -0
- package/dist/src/internal/builtin-plugins/solidity/index.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/solidity-hooks.d.ts +18 -0
- package/dist/src/internal/builtin-plugins/solidity/solidity-hooks.d.ts.map +1 -0
- package/dist/src/internal/builtin-plugins/solidity/solidity-hooks.js +33 -0
- package/dist/src/internal/builtin-plugins/solidity/solidity-hooks.js.map +1 -0
- package/dist/src/internal/builtin-plugins/solidity/type-extensions.d.ts +201 -28
- package/dist/src/internal/builtin-plugins/solidity/type-extensions.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/type-extensions.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/edr-artifacts.d.ts +12 -6
- package/dist/src/internal/builtin-plugins/solidity-test/edr-artifacts.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/edr-artifacts.js +9 -7
- package/dist/src/internal/builtin-plugins/solidity-test/edr-artifacts.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/formatters.d.ts +1 -12
- package/dist/src/internal/builtin-plugins/solidity-test/formatters.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/formatters.js +0 -150
- package/dist/src/internal/builtin-plugins/solidity-test/formatters.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/helpers.d.ts +4 -3
- package/dist/src/internal/builtin-plugins/solidity-test/helpers.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/helpers.js +5 -9
- package/dist/src/internal/builtin-plugins/solidity-test/helpers.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/index.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/index.js +0 -7
- package/dist/src/internal/builtin-plugins/solidity-test/index.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/inline-config/constants.d.ts +7 -0
- package/dist/src/internal/builtin-plugins/solidity-test/inline-config/constants.d.ts.map +1 -0
- package/dist/src/internal/builtin-plugins/solidity-test/inline-config/constants.js +20 -0
- package/dist/src/internal/builtin-plugins/solidity-test/inline-config/constants.js.map +1 -0
- package/dist/src/internal/builtin-plugins/solidity-test/inline-config/helpers.d.ts +24 -0
- package/dist/src/internal/builtin-plugins/solidity-test/inline-config/helpers.d.ts.map +1 -0
- package/dist/src/internal/builtin-plugins/solidity-test/inline-config/helpers.js +68 -0
- package/dist/src/internal/builtin-plugins/solidity-test/inline-config/helpers.js.map +1 -0
- package/dist/src/internal/builtin-plugins/solidity-test/inline-config/index.d.ts +13 -0
- package/dist/src/internal/builtin-plugins/solidity-test/inline-config/index.d.ts.map +1 -0
- package/dist/src/internal/builtin-plugins/solidity-test/inline-config/index.js +136 -0
- package/dist/src/internal/builtin-plugins/solidity-test/inline-config/index.js.map +1 -0
- package/dist/src/internal/builtin-plugins/solidity-test/inline-config/parsing.d.ts +19 -0
- package/dist/src/internal/builtin-plugins/solidity-test/inline-config/parsing.d.ts.map +1 -0
- package/dist/src/internal/builtin-plugins/solidity-test/inline-config/parsing.js +133 -0
- package/dist/src/internal/builtin-plugins/solidity-test/inline-config/parsing.js.map +1 -0
- package/dist/src/internal/builtin-plugins/solidity-test/inline-config/types.d.ts +10 -0
- package/dist/src/internal/builtin-plugins/solidity-test/inline-config/types.d.ts.map +1 -0
- package/dist/src/internal/builtin-plugins/solidity-test/inline-config/types.js +2 -0
- package/dist/src/internal/builtin-plugins/solidity-test/inline-config/types.js.map +1 -0
- package/dist/src/internal/builtin-plugins/solidity-test/inline-config/validation.d.ts +12 -0
- package/dist/src/internal/builtin-plugins/solidity-test/inline-config/validation.d.ts.map +1 -0
- package/dist/src/internal/builtin-plugins/solidity-test/inline-config/validation.js +81 -0
- package/dist/src/internal/builtin-plugins/solidity-test/inline-config/validation.js.map +1 -0
- package/dist/src/internal/builtin-plugins/solidity-test/reporter.d.ts +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/reporter.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/reporter.js +5 -2
- package/dist/src/internal/builtin-plugins/solidity-test/reporter.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/task-action.d.ts +0 -1
- package/dist/src/internal/builtin-plugins/solidity-test/task-action.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/task-action.js +21 -14
- package/dist/src/internal/builtin-plugins/solidity-test/task-action.js.map +1 -1
- package/dist/src/internal/builtin-plugins/test/index.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/test/index.js +0 -7
- package/dist/src/internal/builtin-plugins/test/index.js.map +1 -1
- package/dist/src/internal/builtin-plugins/test/task-action.d.ts +0 -1
- package/dist/src/internal/builtin-plugins/test/task-action.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/test/task-action.js +1 -4
- package/dist/src/internal/builtin-plugins/test/task-action.js.map +1 -1
- package/dist/src/internal/cli/help/get-help-string.d.ts.map +1 -1
- package/dist/src/internal/cli/help/get-help-string.js +1 -1
- package/dist/src/internal/cli/help/get-help-string.js.map +1 -1
- package/dist/src/internal/cli/init/init.d.ts.map +1 -1
- package/dist/src/internal/cli/init/init.js +1 -1
- package/dist/src/internal/cli/init/init.js.map +1 -1
- package/dist/src/internal/cli/init/prompt.d.ts.map +1 -1
- package/dist/src/internal/cli/init/prompt.js +1 -7
- package/dist/src/internal/cli/init/prompt.js.map +1 -1
- package/dist/src/internal/core/hre.d.ts +2 -1
- package/dist/src/internal/core/hre.d.ts.map +1 -1
- package/dist/src/internal/core/hre.js +18 -0
- package/dist/src/internal/core/hre.js.map +1 -1
- package/dist/src/internal/core/plugins/detect-plugin-npm-dependency-problems.d.ts.map +1 -1
- package/dist/src/internal/core/plugins/detect-plugin-npm-dependency-problems.js +6 -1
- package/dist/src/internal/core/plugins/detect-plugin-npm-dependency-problems.js.map +1 -1
- package/dist/src/internal/core/user-interruptions.d.ts.map +1 -1
- package/dist/src/internal/core/user-interruptions.js +2 -5
- package/dist/src/internal/core/user-interruptions.js.map +1 -1
- package/dist/src/internal/utils/colorizer.d.ts +10 -0
- package/dist/src/internal/utils/colorizer.d.ts.map +1 -0
- package/dist/src/internal/utils/colorizer.js +2 -0
- package/dist/src/internal/utils/colorizer.js.map +1 -0
- package/dist/src/internal/utils/package.d.ts.map +1 -1
- package/dist/src/internal/utils/package.js +1 -1
- package/dist/src/internal/utils/package.js.map +1 -1
- package/dist/src/types/global-options.d.ts +1 -0
- package/dist/src/types/global-options.d.ts.map +1 -1
- package/dist/src/types/hooks.d.ts +32 -0
- package/dist/src/types/hooks.d.ts.map +1 -1
- package/dist/src/types/solidity/compilation-job.d.ts +5 -5
- package/dist/src/types/solidity/compilation-job.d.ts.map +1 -1
- package/dist/src/types/solidity/solidity-artifacts.d.ts +15 -0
- package/dist/src/types/solidity/solidity-artifacts.d.ts.map +1 -1
- package/package.json +6 -5
- package/src/internal/builtin-global-options.ts +15 -1
- package/src/internal/builtin-plugins/gas-analytics/helpers.ts +13 -3
- package/src/internal/builtin-plugins/network-manager/accounts/derive-private-keys.ts +25 -3
- package/src/internal/builtin-plugins/network-manager/edr/edr-provider.ts +107 -56
- package/src/internal/builtin-plugins/network-manager/edr/genesis-state.ts +179 -0
- package/src/internal/builtin-plugins/network-manager/edr/utils/trace-formatters.ts +197 -0
- package/src/internal/builtin-plugins/network-manager/edr/utils/trace-output.ts +137 -0
- package/src/internal/builtin-plugins/network-manager/hook-handlers/hre.ts +1 -0
- package/src/internal/builtin-plugins/network-manager/hook-handlers/network.ts +8 -11
- package/src/internal/builtin-plugins/network-manager/http-provider.ts +1 -0
- package/src/internal/builtin-plugins/network-manager/network-manager.ts +83 -10
- package/src/internal/builtin-plugins/network-manager/request-handlers/handlers/accounts/local-accounts.ts +98 -34
- package/src/internal/builtin-plugins/network-manager/request-handlers/handlers-array.ts +10 -30
- package/src/internal/builtin-plugins/node/artifacts/build-info-watcher.ts +1 -2
- package/src/internal/builtin-plugins/node/helpers.ts +9 -2
- package/src/internal/builtin-plugins/solidity/build-system/artifacts.ts +7 -2
- package/src/internal/builtin-plugins/solidity/build-system/build-system.ts +141 -65
- package/src/internal/builtin-plugins/solidity/build-system/cache.ts +1 -0
- package/src/internal/builtin-plugins/solidity/build-system/compilation-job.ts +34 -7
- package/src/internal/builtin-plugins/solidity/build-system/compiler/compiler.ts +1 -1
- package/src/internal/builtin-plugins/solidity/build-system/compiler/downloader.ts +1 -2
- package/src/internal/builtin-plugins/solidity/build-system/solc-config-selection.ts +4 -2
- package/src/internal/builtin-plugins/solidity/config.ts +335 -110
- package/src/internal/builtin-plugins/solidity/exports.ts +2 -0
- package/src/internal/builtin-plugins/solidity/hook-handlers/config.ts +3 -0
- package/src/internal/builtin-plugins/solidity/hook-handlers/solidity.ts +9 -0
- package/src/internal/builtin-plugins/solidity/index.ts +1 -0
- package/src/internal/builtin-plugins/solidity/solidity-hooks.ts +53 -0
- package/src/internal/builtin-plugins/solidity/type-extensions.ts +258 -31
- package/src/internal/builtin-plugins/solidity-test/edr-artifacts.ts +22 -10
- package/src/internal/builtin-plugins/solidity-test/formatters.ts +1 -213
- package/src/internal/builtin-plugins/solidity-test/helpers.ts +8 -8
- package/src/internal/builtin-plugins/solidity-test/index.ts +0 -7
- package/src/internal/builtin-plugins/solidity-test/inline-config/constants.ts +21 -0
- package/src/internal/builtin-plugins/solidity-test/inline-config/helpers.ts +99 -0
- package/src/internal/builtin-plugins/solidity-test/inline-config/index.ts +272 -0
- package/src/internal/builtin-plugins/solidity-test/inline-config/parsing.ts +186 -0
- package/src/internal/builtin-plugins/solidity-test/inline-config/types.ts +9 -0
- package/src/internal/builtin-plugins/solidity-test/inline-config/validation.ts +122 -0
- package/src/internal/builtin-plugins/solidity-test/reporter.ts +6 -6
- package/src/internal/builtin-plugins/solidity-test/task-action.ts +42 -25
- package/src/internal/builtin-plugins/test/index.ts +0 -7
- package/src/internal/builtin-plugins/test/task-action.ts +1 -6
- package/src/internal/cli/help/get-help-string.ts +2 -2
- package/src/internal/cli/init/init.ts +1 -1
- package/src/internal/cli/init/prompt.ts +1 -14
- package/src/internal/core/hre.ts +33 -0
- package/src/internal/core/plugins/detect-plugin-npm-dependency-problems.ts +8 -1
- package/src/internal/core/user-interruptions.ts +3 -5
- package/src/internal/utils/colorizer.ts +9 -0
- package/src/internal/utils/package.ts +1 -2
- package/src/types/global-options.ts +1 -0
- package/src/types/hooks.ts +37 -0
- package/src/types/solidity/compilation-job.ts +5 -5
- package/src/types/solidity/solidity-artifacts.ts +16 -0
- package/templates/hardhat-3/01-node-test-runner-viem/package.json +5 -5
- package/templates/hardhat-3/02-mocha-ethers/package.json +11 -11
- package/templates/hardhat-3/03-minimal/package.json +1 -1
|
@@ -1,26 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
LogTrace,
|
|
3
|
-
ArtifactId,
|
|
4
|
-
CallTrace,
|
|
5
|
-
DecodedTraceParameters,
|
|
6
|
-
} from "@nomicfoundation/edr";
|
|
7
|
-
|
|
8
|
-
import { LogKind, CallKind } from "@nomicfoundation/edr";
|
|
9
|
-
import { assertHardhatInvariant } from "@nomicfoundation/hardhat-errors";
|
|
10
|
-
import { bytesToHexString } from "@nomicfoundation/hardhat-utils/hex";
|
|
11
|
-
import chalk from "chalk";
|
|
12
|
-
|
|
13
|
-
export interface Colorizer {
|
|
14
|
-
blue: (text: string) => string;
|
|
15
|
-
green: (text: string) => string;
|
|
16
|
-
red: (text: string) => string;
|
|
17
|
-
cyan: (text: string) => string;
|
|
18
|
-
yellow: (text: string) => string;
|
|
19
|
-
grey: (text: string) => string;
|
|
20
|
-
dim: (text: string) => string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
type NestedArray<T> = Array<T | NestedArray<T>>;
|
|
1
|
+
import type { ArtifactId } from "@nomicfoundation/edr";
|
|
24
2
|
|
|
25
3
|
export function formatArtifactId(
|
|
26
4
|
artifactId: ArtifactId,
|
|
@@ -31,193 +9,3 @@ export function formatArtifactId(
|
|
|
31
9
|
|
|
32
10
|
return `${sourceName}:${artifactId.name}`;
|
|
33
11
|
}
|
|
34
|
-
|
|
35
|
-
export function formatLogs(
|
|
36
|
-
logs: string[],
|
|
37
|
-
indent: number,
|
|
38
|
-
colorizer: Colorizer,
|
|
39
|
-
): string {
|
|
40
|
-
return colorizer.grey(
|
|
41
|
-
logs.map((log) => `${" ".repeat(indent)}${log}`).join("\n"),
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function formatInputs(
|
|
46
|
-
inputs: DecodedTraceParameters | Uint8Array,
|
|
47
|
-
color?: (text: string) => string,
|
|
48
|
-
): string | undefined {
|
|
49
|
-
if (inputs instanceof Uint8Array) {
|
|
50
|
-
return inputs.length > 0 ? bytesToHexString(inputs) : undefined;
|
|
51
|
-
} else {
|
|
52
|
-
const formattedName =
|
|
53
|
-
color !== undefined ? color(inputs.name) : inputs.name;
|
|
54
|
-
return `${formattedName}(${inputs.arguments.join(", ")})`;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function formatOutputs(outputs: string | Uint8Array): string | undefined {
|
|
59
|
-
if (outputs instanceof Uint8Array) {
|
|
60
|
-
return outputs.length > 0 ? bytesToHexString(outputs) : undefined;
|
|
61
|
-
} else {
|
|
62
|
-
return outputs;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function formatLog(log: LogTrace, colorizer: Colorizer = chalk): string[] {
|
|
67
|
-
const { parameters } = log;
|
|
68
|
-
const lines = [];
|
|
69
|
-
if (Array.isArray(parameters)) {
|
|
70
|
-
const topics = parameters.map((topic) => bytesToHexString(topic));
|
|
71
|
-
if (topics.length > 0) {
|
|
72
|
-
lines.push(`emit topic 0: ${colorizer.cyan(topics[0])}`);
|
|
73
|
-
}
|
|
74
|
-
for (let i = 1; i < topics.length - 1; i++) {
|
|
75
|
-
lines.push(` topic ${i}: ${colorizer.cyan(topics[i])}`);
|
|
76
|
-
}
|
|
77
|
-
if (topics.length > 1) {
|
|
78
|
-
lines.push(` data: ${colorizer.cyan(topics[topics.length - 1])}`);
|
|
79
|
-
}
|
|
80
|
-
} else {
|
|
81
|
-
lines.push(
|
|
82
|
-
`emit ${parameters.name}(${colorizer.cyan(parameters.arguments.join(", "))})`,
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
return lines;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function formatKind(kind: CallKind): string | undefined {
|
|
89
|
-
assertHardhatInvariant(
|
|
90
|
-
kind !== CallKind.Create,
|
|
91
|
-
"Unexpected call kind 'Create'",
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
switch (kind) {
|
|
95
|
-
case CallKind.Call:
|
|
96
|
-
return undefined;
|
|
97
|
-
case CallKind.CallCode:
|
|
98
|
-
return "callcode";
|
|
99
|
-
case CallKind.DelegateCall:
|
|
100
|
-
return "delegatecall";
|
|
101
|
-
case CallKind.StaticCall:
|
|
102
|
-
return "staticcall";
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function formatTrace(
|
|
107
|
-
trace: CallTrace,
|
|
108
|
-
colorizer: Colorizer,
|
|
109
|
-
): NestedArray<string> {
|
|
110
|
-
const {
|
|
111
|
-
success,
|
|
112
|
-
address,
|
|
113
|
-
contract,
|
|
114
|
-
inputs,
|
|
115
|
-
gasUsed,
|
|
116
|
-
value,
|
|
117
|
-
kind,
|
|
118
|
-
isCheatcode,
|
|
119
|
-
outputs,
|
|
120
|
-
} = trace;
|
|
121
|
-
let color;
|
|
122
|
-
if (isCheatcode) {
|
|
123
|
-
color = colorizer.blue;
|
|
124
|
-
} else if (success) {
|
|
125
|
-
color = colorizer.green;
|
|
126
|
-
} else {
|
|
127
|
-
color = colorizer.red;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const formattedInputs = formatInputs(inputs, color);
|
|
131
|
-
const formattedOutputs = formatOutputs(outputs);
|
|
132
|
-
|
|
133
|
-
let openingLine: string;
|
|
134
|
-
let closingLine: string | undefined;
|
|
135
|
-
if (kind === CallKind.Create) {
|
|
136
|
-
openingLine = `[${gasUsed}] ${colorizer.yellow("→ new")} ${contract ?? "<unknown>"}@${address}`;
|
|
137
|
-
// TODO: Uncomment this when the formattedInputs starts containing
|
|
138
|
-
// the address of where the contract was deployed instead of the code.
|
|
139
|
-
// if (formattedInputs !== undefined) {
|
|
140
|
-
// openingLine = `${openingLine}@${formattedInputs}`;
|
|
141
|
-
// }
|
|
142
|
-
} else {
|
|
143
|
-
const formattedKind = formatKind(kind);
|
|
144
|
-
openingLine = `[${gasUsed}] ${color(contract ?? address)}`;
|
|
145
|
-
if (formattedInputs !== undefined) {
|
|
146
|
-
openingLine = `${openingLine}::${formattedInputs}`;
|
|
147
|
-
}
|
|
148
|
-
if (value !== BigInt(0)) {
|
|
149
|
-
openingLine = `${openingLine} {value: ${value}}`;
|
|
150
|
-
}
|
|
151
|
-
if (formattedKind !== undefined) {
|
|
152
|
-
openingLine = `${openingLine} ${colorizer.yellow(`[${formattedKind}]`)}`;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
if (formattedOutputs !== undefined) {
|
|
156
|
-
if (
|
|
157
|
-
formattedOutputs === "EvmError: Revert" ||
|
|
158
|
-
formattedOutputs.startsWith("revert:")
|
|
159
|
-
) {
|
|
160
|
-
closingLine = `${color("←")} ${color("[Revert]")} ${formattedOutputs}`;
|
|
161
|
-
} else {
|
|
162
|
-
closingLine = `${color("←")} ${formattedOutputs}`;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
const lines = [];
|
|
167
|
-
lines.push(openingLine);
|
|
168
|
-
for (const child of trace.children) {
|
|
169
|
-
if (child.kind === LogKind.Log) {
|
|
170
|
-
lines.push(formatLog(child));
|
|
171
|
-
} else {
|
|
172
|
-
lines.push(formatTrace(child, colorizer));
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
if (closingLine !== undefined) {
|
|
176
|
-
lines.push([closingLine]);
|
|
177
|
-
}
|
|
178
|
-
return lines;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
function formatNestedArray(
|
|
182
|
-
data: NestedArray<string>,
|
|
183
|
-
prefix = "",
|
|
184
|
-
isTopLevel = true,
|
|
185
|
-
): string {
|
|
186
|
-
let output = "";
|
|
187
|
-
|
|
188
|
-
for (let i = 0; i < data.length; i++) {
|
|
189
|
-
const item = data[i];
|
|
190
|
-
|
|
191
|
-
if (Array.isArray(item) && typeof item[0] === "string") {
|
|
192
|
-
const [label, ...children] = item;
|
|
193
|
-
|
|
194
|
-
if (isTopLevel) {
|
|
195
|
-
output += `${prefix}${label}\n`;
|
|
196
|
-
output += formatNestedArray(children, prefix, false);
|
|
197
|
-
} else {
|
|
198
|
-
const isLast = i === data.length - 1;
|
|
199
|
-
const connector = isLast ? " └─ " : " ├─ ";
|
|
200
|
-
const childPrefix = isLast ? " " : " │ ";
|
|
201
|
-
output += `${prefix}${connector}${label}\n`;
|
|
202
|
-
output += formatNestedArray(children, prefix + childPrefix, false);
|
|
203
|
-
}
|
|
204
|
-
} else if (typeof item === "string") {
|
|
205
|
-
const isLast = i === data.length - 1;
|
|
206
|
-
const connector = isLast ? " └─ " : " ├─ ";
|
|
207
|
-
output += `${prefix}${connector}${item}\n`;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
return output;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
export function formatTraces(
|
|
215
|
-
traces: CallTrace[],
|
|
216
|
-
prefix: string,
|
|
217
|
-
colorizer: Colorizer,
|
|
218
|
-
): string {
|
|
219
|
-
const lines = traces.map((trace) => formatTrace(trace, colorizer));
|
|
220
|
-
const formattedTraces = formatNestedArray(lines, prefix);
|
|
221
|
-
// Remove the trailing newline
|
|
222
|
-
return formattedTraces.slice(0, -1);
|
|
223
|
-
}
|
|
@@ -2,17 +2,18 @@ import type { RunOptions } from "./runner.js";
|
|
|
2
2
|
import type { Abi } from "../../../types/artifacts.js";
|
|
3
3
|
import type { ChainType } from "../../../types/network.js";
|
|
4
4
|
import type { SolidityTestConfig } from "../../../types/test.js";
|
|
5
|
+
import type { Colorizer } from "../../utils/colorizer.js";
|
|
5
6
|
import type {
|
|
6
7
|
SolidityTestRunnerConfigArgs,
|
|
7
8
|
PathPermission,
|
|
8
9
|
Artifact,
|
|
9
10
|
ObservabilityConfig,
|
|
11
|
+
TestFunctionOverride,
|
|
10
12
|
} from "@nomicfoundation/edr";
|
|
11
13
|
|
|
12
14
|
import {
|
|
13
15
|
opGenesisState,
|
|
14
16
|
l1GenesisState,
|
|
15
|
-
IncludeTraces,
|
|
16
17
|
FsAccessPermission,
|
|
17
18
|
CollectStackTraces,
|
|
18
19
|
opHardforkFromString,
|
|
@@ -24,8 +25,9 @@ import chalk from "chalk";
|
|
|
24
25
|
import { DEFAULT_VERBOSITY, OPTIMISM_CHAIN_TYPE } from "../../constants.js";
|
|
25
26
|
import { resolveHardfork } from "../network-manager/config-resolution.js";
|
|
26
27
|
import { hardhatHardforkToEdrSpecId } from "../network-manager/edr/utils/convert-to-edr.js";
|
|
28
|
+
import { verbosityToIncludeTraces } from "../network-manager/edr/utils/trace-formatters.js";
|
|
27
29
|
|
|
28
|
-
import {
|
|
30
|
+
import { formatArtifactId } from "./formatters.js";
|
|
29
31
|
|
|
30
32
|
interface SolidityTestConfigParams {
|
|
31
33
|
chainType: ChainType;
|
|
@@ -36,6 +38,7 @@ interface SolidityTestConfigParams {
|
|
|
36
38
|
observability?: ObservabilityConfig;
|
|
37
39
|
testPattern?: string;
|
|
38
40
|
generateGasReport: boolean;
|
|
41
|
+
testFunctionOverrides?: TestFunctionOverride[];
|
|
39
42
|
}
|
|
40
43
|
|
|
41
44
|
export function solidityTestConfigToRunOptions(
|
|
@@ -53,6 +56,7 @@ export async function solidityTestConfigToSolidityTestRunnerConfigArgs({
|
|
|
53
56
|
observability,
|
|
54
57
|
testPattern,
|
|
55
58
|
generateGasReport,
|
|
59
|
+
testFunctionOverrides,
|
|
56
60
|
}: SolidityTestConfigParams): Promise<SolidityTestRunnerConfigArgs> {
|
|
57
61
|
const fsPermissions: PathPermission[] | undefined = [
|
|
58
62
|
config.fsPermissions?.readWriteFile?.map((p) => ({
|
|
@@ -98,12 +102,7 @@ export async function solidityTestConfigToSolidityTestRunnerConfigArgs({
|
|
|
98
102
|
? opGenesisState(opHardforkFromString(resolvedHardfork))
|
|
99
103
|
: l1GenesisState(l1HardforkFromString(resolvedHardfork));
|
|
100
104
|
|
|
101
|
-
|
|
102
|
-
if (verbosity >= 5) {
|
|
103
|
-
includeTraces = IncludeTraces.All;
|
|
104
|
-
} else if (verbosity >= 3) {
|
|
105
|
-
includeTraces = IncludeTraces.Failing;
|
|
106
|
-
}
|
|
105
|
+
const includeTraces = verbosityToIncludeTraces(verbosity);
|
|
107
106
|
|
|
108
107
|
const blockGasLimit =
|
|
109
108
|
config.blockGasLimit === false ? undefined : config.blockGasLimit;
|
|
@@ -152,6 +151,7 @@ export async function solidityTestConfigToSolidityTestRunnerConfigArgs({
|
|
|
152
151
|
collectStackTraces: shouldAlwaysCollectStackTraces
|
|
153
152
|
? CollectStackTraces.Always
|
|
154
153
|
: CollectStackTraces.OnFailure,
|
|
154
|
+
testFunctionOverrides,
|
|
155
155
|
};
|
|
156
156
|
}
|
|
157
157
|
|
|
@@ -2,7 +2,6 @@ import type { HardhatPlugin } from "../../../types/plugins.js";
|
|
|
2
2
|
|
|
3
3
|
import { ArgumentType } from "hardhat/types/arguments";
|
|
4
4
|
|
|
5
|
-
import { DEFAULT_VERBOSITY } from "../../constants.js";
|
|
6
5
|
import { task } from "../../core/config.js";
|
|
7
6
|
|
|
8
7
|
import "./type-extensions.js";
|
|
@@ -35,12 +34,6 @@ const hardhatPlugin: HardhatPlugin = {
|
|
|
35
34
|
name: "noCompile",
|
|
36
35
|
description: "Don't compile the project before running the tests",
|
|
37
36
|
})
|
|
38
|
-
.addLevel({
|
|
39
|
-
name: "verbosity",
|
|
40
|
-
shortName: "v",
|
|
41
|
-
description: "Verbosity level of the test output",
|
|
42
|
-
defaultValue: DEFAULT_VERBOSITY,
|
|
43
|
-
})
|
|
44
37
|
.addOption({
|
|
45
38
|
name: "testSummaryIndex",
|
|
46
39
|
description:
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export const HARDHAT_CONFIG_PREFIX = "hardhat-config:";
|
|
2
|
+
export const FORGE_CONFIG_PREFIX = "forge-config:";
|
|
3
|
+
|
|
4
|
+
/** All supported inline config keys and their expected value types. */
|
|
5
|
+
export const KEY_TYPES: Record<string, "number" | "boolean"> = {
|
|
6
|
+
"fuzz.runs": "number",
|
|
7
|
+
"fuzz.maxTestRejects": "number",
|
|
8
|
+
"fuzz.showLogs": "boolean",
|
|
9
|
+
"fuzz.timeout": "number",
|
|
10
|
+
"invariant.runs": "number",
|
|
11
|
+
"invariant.depth": "number",
|
|
12
|
+
"invariant.failOnRevert": "boolean",
|
|
13
|
+
"invariant.callOverride": "boolean",
|
|
14
|
+
"invariant.timeout": "number",
|
|
15
|
+
allowInternalExpectRevert: "boolean",
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/** Top-level key categories (e.g. "fuzz", "invariant", "allowInternalExpectRevert"). */
|
|
19
|
+
export const TOP_LEVEL_KEYS: string[] = [
|
|
20
|
+
...new Set(Object.keys(KEY_TYPES).map((k) => k.split(".")[0])),
|
|
21
|
+
];
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { RawInlineOverride } from "./types.js";
|
|
2
|
+
import type { TestFunctionConfigOverride } from "@nomicfoundation/edr";
|
|
3
|
+
|
|
4
|
+
import { bytesIncludesUtf8String } from "@nomicfoundation/hardhat-utils/bytes";
|
|
5
|
+
|
|
6
|
+
import { getFullyQualifiedName } from "../../../../utils/contract-names.js";
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
HARDHAT_CONFIG_PREFIX,
|
|
10
|
+
FORGE_CONFIG_PREFIX,
|
|
11
|
+
KEY_TYPES,
|
|
12
|
+
} from "./constants.js";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Returns true if the build info bytes contain either of the inline config
|
|
16
|
+
* prefixes.
|
|
17
|
+
*/
|
|
18
|
+
export function buildInfoContainsInlineConfig(
|
|
19
|
+
buildInfoBytes: Uint8Array,
|
|
20
|
+
): boolean {
|
|
21
|
+
return (
|
|
22
|
+
bytesIncludesUtf8String(buildInfoBytes, HARDHAT_CONFIG_PREFIX) ||
|
|
23
|
+
bytesIncludesUtf8String(buildInfoBytes, FORGE_CONFIG_PREFIX)
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Finds the function selector for a given function name in the methodIdentifiers
|
|
29
|
+
* map. Matches the first entry whose signature starts with `functionName(`.
|
|
30
|
+
* Returns the selector prefixed with "0x".
|
|
31
|
+
*/
|
|
32
|
+
export function resolveFunctionSelector(
|
|
33
|
+
methodIdentifiers: Record<string, string>,
|
|
34
|
+
functionName: string,
|
|
35
|
+
): string | undefined {
|
|
36
|
+
const prefix = `${functionName}(`;
|
|
37
|
+
|
|
38
|
+
for (const [signature, selector] of Object.entries(methodIdentifiers)) {
|
|
39
|
+
if (signature.startsWith(prefix)) {
|
|
40
|
+
return `0x${selector}`;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Converts a validated set of raw overrides into a TestFunctionConfigOverride
|
|
49
|
+
* object.
|
|
50
|
+
*/
|
|
51
|
+
export function buildConfigOverride(
|
|
52
|
+
overrides: RawInlineOverride[],
|
|
53
|
+
): TestFunctionConfigOverride {
|
|
54
|
+
const config: Record<string, unknown> = {};
|
|
55
|
+
const fuzz: Record<string, unknown> = {};
|
|
56
|
+
const invariant: Record<string, unknown> = {};
|
|
57
|
+
|
|
58
|
+
for (const override of overrides) {
|
|
59
|
+
const expectedType = KEY_TYPES[override.key];
|
|
60
|
+
const parsed =
|
|
61
|
+
expectedType === "number"
|
|
62
|
+
? Number(override.rawValue)
|
|
63
|
+
: override.rawValue.toLowerCase() === "true";
|
|
64
|
+
|
|
65
|
+
const dotIndex = override.key.indexOf(".");
|
|
66
|
+
if (dotIndex === -1) {
|
|
67
|
+
// Top-level key, like "allowInternalExpectRevert"
|
|
68
|
+
config[override.key] = parsed;
|
|
69
|
+
} else {
|
|
70
|
+
const section = override.key.slice(0, dotIndex);
|
|
71
|
+
const field = override.key.slice(dotIndex + 1);
|
|
72
|
+
const target = section === "fuzz" ? fuzz : invariant;
|
|
73
|
+
target[field] = field === "timeout" ? { time: parsed } : parsed;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (Object.keys(fuzz).length > 0) {
|
|
78
|
+
config.fuzz = fuzz;
|
|
79
|
+
}
|
|
80
|
+
if (Object.keys(invariant).length > 0) {
|
|
81
|
+
config.invariant = invariant;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions --
|
|
85
|
+
Cast is safe because we have validated all keys and value types in the previous step. */
|
|
86
|
+
return config as TestFunctionConfigOverride;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Constructs a fully qualified function name, in the format
|
|
91
|
+
* "source.sol:ContractName#functionName".
|
|
92
|
+
*/
|
|
93
|
+
export function getFunctionFqn(
|
|
94
|
+
inputSourceName: string,
|
|
95
|
+
contractName: string,
|
|
96
|
+
functionName: string,
|
|
97
|
+
): string {
|
|
98
|
+
return `${getFullyQualifiedName(inputSourceName, contractName)}#${functionName}`;
|
|
99
|
+
}
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import type { SolidityBuildInfoOutput } from "../../../../types/solidity/solidity-artifacts.js";
|
|
2
|
+
import type {
|
|
3
|
+
BuildInfoAndOutput,
|
|
4
|
+
EdrArtifactWithMetadata,
|
|
5
|
+
} from "../edr-artifacts.js";
|
|
6
|
+
import type { RawInlineOverride } from "./types.js";
|
|
7
|
+
import type { ArtifactId, TestFunctionOverride } from "@nomicfoundation/edr";
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
HardhatError,
|
|
11
|
+
assertHardhatInvariant,
|
|
12
|
+
} from "@nomicfoundation/hardhat-errors";
|
|
13
|
+
import { bytesToUtf8String } from "@nomicfoundation/hardhat-utils/bytes";
|
|
14
|
+
|
|
15
|
+
import { getFullyQualifiedName } from "../../../../utils/contract-names.js";
|
|
16
|
+
|
|
17
|
+
import {
|
|
18
|
+
buildInfoContainsInlineConfig,
|
|
19
|
+
resolveFunctionSelector,
|
|
20
|
+
buildConfigOverride,
|
|
21
|
+
getFunctionFqn,
|
|
22
|
+
} from "./helpers.js";
|
|
23
|
+
import { extractInlineConfigFromAst } from "./parsing.js";
|
|
24
|
+
import { validateInlineOverrides } from "./validation.js";
|
|
25
|
+
|
|
26
|
+
export type { RawInlineOverride } from "./types.js";
|
|
27
|
+
export {
|
|
28
|
+
buildInfoContainsInlineConfig,
|
|
29
|
+
resolveFunctionSelector,
|
|
30
|
+
buildConfigOverride,
|
|
31
|
+
getFunctionFqn,
|
|
32
|
+
} from "./helpers.js";
|
|
33
|
+
export {
|
|
34
|
+
extractInlineConfigFromAst,
|
|
35
|
+
extractDocText,
|
|
36
|
+
parseInlineConfigLine,
|
|
37
|
+
} from "./parsing.js";
|
|
38
|
+
export { validateInlineOverrides } from "./validation.js";
|
|
39
|
+
|
|
40
|
+
interface CollectedOverrides {
|
|
41
|
+
overrides: RawInlineOverride[];
|
|
42
|
+
artifactIdsByFqn: Map<string, ArtifactId>;
|
|
43
|
+
methodIdentifiersByContract: Map<string, Record<string, string>>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Extracts per-test inline configuration overrides from the NatSpec comments
|
|
48
|
+
* in the solc AST. It only extracts them from the build info where each
|
|
49
|
+
* test artifact's file was compiled as a root file.
|
|
50
|
+
*/
|
|
51
|
+
export function getTestFunctionOverrides(
|
|
52
|
+
testSuiteArtifacts: EdrArtifactWithMetadata[],
|
|
53
|
+
buildInfosAndOutputs: BuildInfoAndOutput[],
|
|
54
|
+
): TestFunctionOverride[] {
|
|
55
|
+
const allRawOverrides = collectRawOverrides(
|
|
56
|
+
testSuiteArtifacts,
|
|
57
|
+
buildInfosAndOutputs,
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
validateInlineOverrides(allRawOverrides.overrides);
|
|
61
|
+
|
|
62
|
+
return buildTestFunctionOverrides(allRawOverrides);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function collectRawOverrides(
|
|
66
|
+
testSuiteArtifacts: EdrArtifactWithMetadata[],
|
|
67
|
+
buildInfosAndOutputs: BuildInfoAndOutput[],
|
|
68
|
+
): CollectedOverrides {
|
|
69
|
+
const overrides: RawInlineOverride[] = [];
|
|
70
|
+
const methodIdentifiersByContract = new Map<string, Record<string, string>>();
|
|
71
|
+
|
|
72
|
+
// Note: We group the artifacts by their build info, so that we only process
|
|
73
|
+
// the relevant build infos, and only the root files of each of them.
|
|
74
|
+
//
|
|
75
|
+
// The last part is important, as a test file can be present in multiple build
|
|
76
|
+
// infos in the presence of partial recompilations
|
|
77
|
+
//
|
|
78
|
+
// At the same time, the same root file could have produced multiple test
|
|
79
|
+
// artifacts, so we need a two-level map to avoid processing the root files
|
|
80
|
+
// multiple times.
|
|
81
|
+
|
|
82
|
+
// Build lookup structures for fast access
|
|
83
|
+
const artifactsGroupedByBuildInfo = new Map<
|
|
84
|
+
/* buildInfoId */ string,
|
|
85
|
+
Map</* inputSourceName */ string, EdrArtifactWithMetadata[]>
|
|
86
|
+
>();
|
|
87
|
+
|
|
88
|
+
const artifactIdsByFqn = new Map<string, ArtifactId>();
|
|
89
|
+
const buildInfoAndOutputById: Map<string, BuildInfoAndOutput> = new Map(
|
|
90
|
+
buildInfosAndOutputs.map((bio) => [bio.buildInfoId, bio]),
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
for (const edrArtifactWithMetadata of testSuiteArtifacts) {
|
|
94
|
+
const fqn = getFullyQualifiedName(
|
|
95
|
+
edrArtifactWithMetadata.edrArtifact.id.source,
|
|
96
|
+
edrArtifactWithMetadata.edrArtifact.id.name,
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
const buildInfoId = edrArtifactWithMetadata.buildInfoId;
|
|
100
|
+
let artifactsBySource = artifactsGroupedByBuildInfo.get(buildInfoId);
|
|
101
|
+
|
|
102
|
+
if (artifactsBySource === undefined) {
|
|
103
|
+
artifactsBySource = new Map();
|
|
104
|
+
artifactsGroupedByBuildInfo.set(buildInfoId, artifactsBySource);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
let artifacts = artifactsBySource.get(
|
|
108
|
+
edrArtifactWithMetadata.edrArtifact.id.source,
|
|
109
|
+
);
|
|
110
|
+
if (artifacts === undefined) {
|
|
111
|
+
artifacts = [];
|
|
112
|
+
artifactsBySource.set(
|
|
113
|
+
edrArtifactWithMetadata.edrArtifact.id.source,
|
|
114
|
+
artifacts,
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
artifacts.push(edrArtifactWithMetadata);
|
|
119
|
+
artifactIdsByFqn.set(fqn, edrArtifactWithMetadata.edrArtifact.id);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
for (const [
|
|
123
|
+
buildInfoId,
|
|
124
|
+
artifactsBySource,
|
|
125
|
+
] of artifactsGroupedByBuildInfo.entries()) {
|
|
126
|
+
const buildInfoAndOutput = buildInfoAndOutputById.get(buildInfoId);
|
|
127
|
+
if (buildInfoAndOutput === undefined) {
|
|
128
|
+
// We can throw for this error for the first artifact with this build info
|
|
129
|
+
// as all of them have the same problem.
|
|
130
|
+
const artifacts = artifactsBySource.values().next().value;
|
|
131
|
+
|
|
132
|
+
assertHardhatInvariant(
|
|
133
|
+
artifacts !== undefined && artifacts.length > 0,
|
|
134
|
+
"An artifact must be present for the build info",
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
const anyArtifact = artifacts[0];
|
|
138
|
+
|
|
139
|
+
const fqn = getFullyQualifiedName(
|
|
140
|
+
anyArtifact.userSourceName,
|
|
141
|
+
anyArtifact.edrArtifact.id.name,
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
throw new HardhatError(
|
|
145
|
+
HardhatError.ERRORS.CORE.SOLIDITY_TESTS.BUILD_INFO_NOT_FOUND_FOR_CONTRACT,
|
|
146
|
+
{
|
|
147
|
+
fqn,
|
|
148
|
+
},
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (!buildInfoContainsInlineConfig(buildInfoAndOutput.buildInfo)) {
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const buildInfoOutput: SolidityBuildInfoOutput = JSON.parse(
|
|
157
|
+
bytesToUtf8String(buildInfoAndOutput.output),
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
for (const [
|
|
161
|
+
inputSourceName,
|
|
162
|
+
sourceArtifacts,
|
|
163
|
+
] of artifactsBySource.entries()) {
|
|
164
|
+
const contractNames = new Set(
|
|
165
|
+
sourceArtifacts.map((a) => a.edrArtifact.id.name),
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
const source = buildInfoOutput.output.sources[inputSourceName];
|
|
169
|
+
const extracted = extractInlineConfigFromAst(
|
|
170
|
+
source.ast,
|
|
171
|
+
inputSourceName,
|
|
172
|
+
contractNames,
|
|
173
|
+
);
|
|
174
|
+
overrides.push(...extracted);
|
|
175
|
+
|
|
176
|
+
for (const artifact of sourceArtifacts) {
|
|
177
|
+
const contractName = artifact.edrArtifact.id.name;
|
|
178
|
+
const fqn = getFullyQualifiedName(inputSourceName, contractName);
|
|
179
|
+
|
|
180
|
+
const methodIdentifiers =
|
|
181
|
+
buildInfoOutput.output.contracts?.[inputSourceName][contractName]?.evm
|
|
182
|
+
?.methodIdentifiers;
|
|
183
|
+
|
|
184
|
+
methodIdentifiersByContract.set(fqn, methodIdentifiers ?? {});
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return { overrides, artifactIdsByFqn, methodIdentifiersByContract };
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function buildTestFunctionOverrides(
|
|
193
|
+
collected: CollectedOverrides,
|
|
194
|
+
): TestFunctionOverride[] {
|
|
195
|
+
const { overrides, artifactIdsByFqn, methodIdentifiersByContract } =
|
|
196
|
+
collected;
|
|
197
|
+
|
|
198
|
+
// Group overrides by function. When the AST provides a functionSelector
|
|
199
|
+
// (public/external functions in solc >= 0.6.0), use it to distinguish
|
|
200
|
+
// overloaded functions. Otherwise fall back to function name only.
|
|
201
|
+
const overridesByFunction = new Map<string, RawInlineOverride[]>();
|
|
202
|
+
for (const override of overrides) {
|
|
203
|
+
const functionFqn = getFunctionFqn(
|
|
204
|
+
override.inputSourceName,
|
|
205
|
+
override.contractName,
|
|
206
|
+
override.functionName,
|
|
207
|
+
);
|
|
208
|
+
const groupKey =
|
|
209
|
+
override.functionSelector !== undefined
|
|
210
|
+
? `${functionFqn}#${override.functionSelector}`
|
|
211
|
+
: functionFqn;
|
|
212
|
+
const existing = overridesByFunction.get(groupKey);
|
|
213
|
+
if (existing === undefined) {
|
|
214
|
+
overridesByFunction.set(groupKey, [override]);
|
|
215
|
+
} else {
|
|
216
|
+
existing.push(override);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Build TestFunctionOverride objects
|
|
221
|
+
const testFunctionOverrides: TestFunctionOverride[] = [];
|
|
222
|
+
for (const [_groupKey, groupOverrides] of overridesByFunction.entries()) {
|
|
223
|
+
const firstOverride = groupOverrides[0];
|
|
224
|
+
const functionFqn = getFunctionFqn(
|
|
225
|
+
firstOverride.inputSourceName,
|
|
226
|
+
firstOverride.contractName,
|
|
227
|
+
firstOverride.functionName,
|
|
228
|
+
);
|
|
229
|
+
const contractFqn = `${firstOverride.inputSourceName}:${firstOverride.contractName}`;
|
|
230
|
+
|
|
231
|
+
const artifactId = artifactIdsByFqn.get(contractFqn);
|
|
232
|
+
assertHardhatInvariant(
|
|
233
|
+
artifactId !== undefined,
|
|
234
|
+
`Missing artifact id for "${contractFqn}"`,
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
// Use the AST-provided selector when available, otherwise fall back to
|
|
238
|
+
// resolving via methodIdentifiers.
|
|
239
|
+
let selector: string | undefined;
|
|
240
|
+
if (firstOverride.functionSelector !== undefined) {
|
|
241
|
+
selector = `0x${firstOverride.functionSelector}`;
|
|
242
|
+
} else {
|
|
243
|
+
const methodIdentifiers = methodIdentifiersByContract.get(contractFqn);
|
|
244
|
+
assertHardhatInvariant(
|
|
245
|
+
methodIdentifiers !== undefined,
|
|
246
|
+
`Missing method identifiers for "${contractFqn}"`,
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
selector = resolveFunctionSelector(
|
|
250
|
+
methodIdentifiers,
|
|
251
|
+
firstOverride.functionName,
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (selector === undefined) {
|
|
256
|
+
throw new HardhatError(
|
|
257
|
+
HardhatError.ERRORS.CORE.SOLIDITY_TESTS.INLINE_CONFIG_UNRESOLVED_SELECTOR,
|
|
258
|
+
{ functionFqn },
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
testFunctionOverrides.push({
|
|
263
|
+
identifier: {
|
|
264
|
+
contractArtifact: artifactId,
|
|
265
|
+
functionSelector: selector,
|
|
266
|
+
},
|
|
267
|
+
config: buildConfigOverride(groupOverrides),
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
return testFunctionOverrides;
|
|
272
|
+
}
|