hardhat 3.0.5 → 3.0.7
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 +22 -0
- package/dist/src/internal/builtin-plugins/coverage/hook-handlers/solidity.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/coverage/hook-handlers/solidity.js +1 -2
- package/dist/src/internal/builtin-plugins/coverage/hook-handlers/solidity.js.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/edr/edr-provider.d.ts +1 -0
- 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 +9 -2
- package/dist/src/internal/builtin-plugins/network-manager/edr/edr-provider.js.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/hook-handlers/hre.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/hook-handlers/hre.js +13 -5
- 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.js +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/hook-handlers/network.js.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/network-manager.d.ts +4 -3
- 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 +79 -37
- package/dist/src/internal/builtin-plugins/network-manager/network-manager.js.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/type-validation.js +2 -2
- package/dist/src/internal/builtin-plugins/network-manager/type-validation.js.map +1 -1
- package/dist/src/internal/builtin-plugins/node/artifacts/build-info-watcher.d.ts +25 -0
- package/dist/src/internal/builtin-plugins/node/artifacts/build-info-watcher.d.ts.map +1 -0
- package/dist/src/internal/builtin-plugins/node/artifacts/build-info-watcher.js +56 -0
- package/dist/src/internal/builtin-plugins/node/artifacts/build-info-watcher.js.map +1 -0
- package/dist/src/internal/builtin-plugins/node/helpers.d.ts +12 -0
- package/dist/src/internal/builtin-plugins/node/helpers.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/node/helpers.js +32 -0
- package/dist/src/internal/builtin-plugins/node/helpers.js.map +1 -1
- package/dist/src/internal/builtin-plugins/node/json-rpc/server.d.ts +3 -10
- package/dist/src/internal/builtin-plugins/node/json-rpc/server.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/node/json-rpc/server.js +1 -1
- package/dist/src/internal/builtin-plugins/node/json-rpc/server.js.map +1 -1
- package/dist/src/internal/builtin-plugins/node/task-action.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/node/task-action.js +14 -4
- package/dist/src/internal/builtin-plugins/node/task-action.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/build-system.d.ts +13 -5
- 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 +126 -58
- 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 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/cache.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/hook-handlers/hre.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/hook-handlers/hre.js +14 -6
- package/dist/src/internal/builtin-plugins/solidity/hook-handlers/hre.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/index.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/index.js +8 -0
- package/dist/src/internal/builtin-plugins/solidity/index.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/tasks/build.d.ts +4 -2
- package/dist/src/internal/builtin-plugins/solidity/tasks/build.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/tasks/build.js +37 -10
- package/dist/src/internal/builtin-plugins/solidity/tasks/build.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/config.d.ts +4 -2
- package/dist/src/internal/builtin-plugins/solidity-test/config.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/config.js +24 -4
- package/dist/src/internal/builtin-plugins/solidity-test/config.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/helpers.d.ts +3 -1
- package/dist/src/internal/builtin-plugins/solidity-test/helpers.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/helpers.js +26 -3
- package/dist/src/internal/builtin-plugins/solidity-test/helpers.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/hook-handlers/config.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/hook-handlers/config.js +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/hook-handlers/config.js.map +1 -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 +26 -43
- package/dist/src/internal/builtin-plugins/solidity-test/task-action.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/type-extensions.d.ts +17 -7
- package/dist/src/internal/builtin-plugins/solidity-test/type-extensions.d.ts.map +1 -1
- package/dist/src/internal/core/hre.d.ts +29 -1
- package/dist/src/internal/core/hre.d.ts.map +1 -1
- package/dist/src/internal/core/hre.js +57 -20
- package/dist/src/internal/core/hre.js.map +1 -1
- package/dist/src/internal/core/plugins/resolve-plugin-list.js +40 -3
- package/dist/src/internal/core/plugins/resolve-plugin-list.js.map +1 -1
- package/dist/src/internal/utils/package.d.ts +1 -0
- package/dist/src/internal/utils/package.d.ts.map +1 -1
- package/dist/src/internal/utils/package.js +17 -1
- package/dist/src/internal/utils/package.js.map +1 -1
- package/dist/src/types/hre.d.ts +4 -0
- package/dist/src/types/hre.d.ts.map +1 -1
- package/dist/src/types/network.d.ts +40 -0
- package/dist/src/types/network.d.ts.map +1 -1
- package/dist/src/types/plugins.d.ts +8 -0
- package/dist/src/types/plugins.d.ts.map +1 -1
- package/dist/src/types/solidity/build-system.d.ts +23 -8
- package/dist/src/types/solidity/build-system.d.ts.map +1 -1
- package/package.json +5 -4
- package/src/internal/builtin-plugins/coverage/hook-handlers/solidity.ts +2 -3
- package/src/internal/builtin-plugins/network-manager/edr/edr-provider.ts +20 -1
- package/src/internal/builtin-plugins/network-manager/hook-handlers/hre.ts +36 -18
- package/src/internal/builtin-plugins/network-manager/hook-handlers/network.ts +1 -1
- package/src/internal/builtin-plugins/network-manager/network-manager.ts +137 -60
- package/src/internal/builtin-plugins/network-manager/type-validation.ts +2 -2
- package/src/internal/builtin-plugins/node/artifacts/build-info-watcher.ts +82 -0
- package/src/internal/builtin-plugins/node/helpers.ts +64 -0
- package/src/internal/builtin-plugins/node/json-rpc/server.ts +3 -10
- package/src/internal/builtin-plugins/node/task-action.ts +31 -5
- package/src/internal/builtin-plugins/solidity/build-system/build-system.ts +203 -98
- package/src/internal/builtin-plugins/solidity/build-system/cache.ts +1 -1
- package/src/internal/builtin-plugins/solidity/hook-handlers/hre.ts +22 -5
- package/src/internal/builtin-plugins/solidity/index.ts +8 -0
- package/src/internal/builtin-plugins/solidity/tasks/build.ts +59 -16
- package/src/internal/builtin-plugins/solidity-test/config.ts +46 -3
- package/src/internal/builtin-plugins/solidity-test/helpers.ts +44 -4
- package/src/internal/builtin-plugins/solidity-test/hook-handlers/config.ts +5 -1
- package/src/internal/builtin-plugins/solidity-test/task-action.ts +39 -54
- package/src/internal/builtin-plugins/solidity-test/type-extensions.ts +23 -9
- package/src/internal/core/hre.ts +102 -32
- package/src/internal/core/plugins/resolve-plugin-list.ts +57 -3
- package/src/internal/utils/package.ts +31 -1
- package/src/types/hre.ts +4 -0
- package/src/types/network.ts +45 -0
- package/src/types/plugins.ts +5 -0
- package/src/types/solidity/build-system.ts +23 -7
- package/templates/hardhat-3/01-node-test-runner-viem/package.json +3 -3
- package/templates/hardhat-3/02-mocha-ethers/package.json +4 -4
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { HardhatRuntimeEnvironment } from "../../../../types/hre.js";
|
|
2
|
+
import type { BuildScope } from "../../../../types/solidity.js";
|
|
1
3
|
import type { NewTaskActionFunction } from "../../../../types/tasks.js";
|
|
2
4
|
|
|
3
5
|
import { resolveFromRoot } from "@nomicfoundation/hardhat-utils/path";
|
|
@@ -5,27 +7,65 @@ import { resolveFromRoot } from "@nomicfoundation/hardhat-utils/path";
|
|
|
5
7
|
import { throwIfSolidityBuildFailed } from "../build-results.js";
|
|
6
8
|
import { isNpmRootPath } from "../build-system/root-paths-utils.js";
|
|
7
9
|
|
|
8
|
-
interface
|
|
10
|
+
interface BuildActionArguments {
|
|
9
11
|
force: boolean;
|
|
10
12
|
files: string[];
|
|
11
13
|
quiet: boolean;
|
|
12
14
|
defaultBuildProfile: string | undefined;
|
|
15
|
+
noTests: boolean;
|
|
16
|
+
noContracts: boolean;
|
|
13
17
|
}
|
|
14
18
|
|
|
15
|
-
const buildAction: NewTaskActionFunction<
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
const buildAction: NewTaskActionFunction<BuildActionArguments> = async (
|
|
20
|
+
args: BuildActionArguments,
|
|
21
|
+
hre,
|
|
18
22
|
) => {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
? await solidity.getRootFilePaths()
|
|
22
|
-
: files.map((file) => {
|
|
23
|
-
if (isNpmRootPath(file)) {
|
|
24
|
-
return file;
|
|
25
|
-
}
|
|
23
|
+
const contractRootPaths = [];
|
|
24
|
+
const testRootPaths = [];
|
|
26
25
|
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
if (args.noContracts === false) {
|
|
27
|
+
contractRootPaths.push(...(await buildForScope("contracts", args, hre)));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (args.noTests === false) {
|
|
31
|
+
testRootPaths.push(...(await buildForScope("tests", args, hre)));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return { contractRootPaths, testRootPaths };
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
async function buildForScope(
|
|
38
|
+
scope: BuildScope,
|
|
39
|
+
{ force, files, quiet, defaultBuildProfile }: BuildActionArguments,
|
|
40
|
+
{ solidity, globalOptions }: HardhatRuntimeEnvironment,
|
|
41
|
+
) {
|
|
42
|
+
// If no specific files are passed, it means a full compilation, i.e. all source files
|
|
43
|
+
const isFullCompilation = files.length === 0;
|
|
44
|
+
|
|
45
|
+
const rootPaths = [];
|
|
46
|
+
|
|
47
|
+
if (isFullCompilation) {
|
|
48
|
+
rootPaths.push(...(await solidity.getRootFilePaths({ scope })));
|
|
49
|
+
} else {
|
|
50
|
+
for (const file of files) {
|
|
51
|
+
if (isNpmRootPath(file)) {
|
|
52
|
+
rootPaths.push(file);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const rootPath = resolveFromRoot(process.cwd(), file);
|
|
56
|
+
|
|
57
|
+
if ((await solidity.getScope(rootPath)) !== scope) {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
rootPaths.push(rootPath);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// If a file list has been passed but none match this scope, we don't run the build
|
|
65
|
+
if (rootPaths.length === 0) {
|
|
66
|
+
return [];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
29
69
|
|
|
30
70
|
const buildProfile = globalOptions.buildProfile ?? defaultBuildProfile;
|
|
31
71
|
|
|
@@ -33,14 +73,17 @@ const buildAction: NewTaskActionFunction<CompileActionArguments> = async (
|
|
|
33
73
|
force,
|
|
34
74
|
buildProfile,
|
|
35
75
|
quiet,
|
|
76
|
+
scope,
|
|
36
77
|
});
|
|
37
78
|
|
|
38
79
|
throwIfSolidityBuildFailed(results);
|
|
39
80
|
|
|
40
81
|
// If we recompiled the entire project we cleanup the artifacts
|
|
41
|
-
if (
|
|
42
|
-
await solidity.cleanupArtifacts(rootPaths);
|
|
82
|
+
if (isFullCompilation) {
|
|
83
|
+
await solidity.cleanupArtifacts(rootPaths, { scope });
|
|
43
84
|
}
|
|
44
|
-
|
|
85
|
+
|
|
86
|
+
return rootPaths;
|
|
87
|
+
}
|
|
45
88
|
|
|
46
89
|
export default buildAction;
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import type { HardhatUserConfig } from "../../../config.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
ConfigurationVariableResolver,
|
|
4
|
+
HardhatConfig,
|
|
5
|
+
ResolvedConfigurationVariable,
|
|
6
|
+
} from "../../../types/config.js";
|
|
3
7
|
import type { HardhatUserConfigValidationError } from "../../../types/hooks.js";
|
|
8
|
+
import type {
|
|
9
|
+
SolidityTestForkingConfig,
|
|
10
|
+
SolidityTestUserConfig,
|
|
11
|
+
} from "../../../types/test.js";
|
|
4
12
|
|
|
5
13
|
import path from "node:path";
|
|
6
14
|
|
|
@@ -8,6 +16,8 @@ import { isObject } from "@nomicfoundation/hardhat-utils/lang";
|
|
|
8
16
|
import { resolveFromRoot } from "@nomicfoundation/hardhat-utils/path";
|
|
9
17
|
import {
|
|
10
18
|
conditionalUnionType,
|
|
19
|
+
sensitiveStringSchema,
|
|
20
|
+
sensitiveUrlSchema,
|
|
11
21
|
validateUserConfigZodType,
|
|
12
22
|
} from "@nomicfoundation/hardhat-zod-utils";
|
|
13
23
|
import { z } from "zod";
|
|
@@ -49,9 +59,9 @@ const solidityTestUserConfigType = z.object({
|
|
|
49
59
|
.optional(),
|
|
50
60
|
forking: z
|
|
51
61
|
.object({
|
|
52
|
-
url: z.
|
|
62
|
+
url: z.optional(sensitiveUrlSchema),
|
|
53
63
|
blockNumber: z.bigint().optional(),
|
|
54
|
-
rpcEndpoints: z.record(
|
|
64
|
+
rpcEndpoints: z.record(sensitiveStringSchema).optional(),
|
|
55
65
|
})
|
|
56
66
|
.optional(),
|
|
57
67
|
invariant: z
|
|
@@ -88,6 +98,32 @@ const userConfigType = z.object({
|
|
|
88
98
|
.optional(),
|
|
89
99
|
});
|
|
90
100
|
|
|
101
|
+
export function resolveSolidityTestForkingConfig(
|
|
102
|
+
forkingUserConfig: SolidityTestUserConfig["forking"],
|
|
103
|
+
resolveConfigurationVariable: ConfigurationVariableResolver,
|
|
104
|
+
): SolidityTestForkingConfig | undefined {
|
|
105
|
+
if (forkingUserConfig === undefined) {
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const resolvedRpcEndpoints: Record<string, ResolvedConfigurationVariable> =
|
|
110
|
+
{};
|
|
111
|
+
if (forkingUserConfig.rpcEndpoints !== undefined) {
|
|
112
|
+
for (const [name, url] of Object.entries(forkingUserConfig.rpcEndpoints)) {
|
|
113
|
+
resolvedRpcEndpoints[name] = resolveConfigurationVariable(url);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return {
|
|
118
|
+
...forkingUserConfig,
|
|
119
|
+
url:
|
|
120
|
+
forkingUserConfig.url !== undefined
|
|
121
|
+
? resolveConfigurationVariable(forkingUserConfig.url)
|
|
122
|
+
: undefined,
|
|
123
|
+
rpcEndpoints: resolvedRpcEndpoints,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
91
127
|
export function validateSolidityTestUserConfig(
|
|
92
128
|
userConfig: unknown,
|
|
93
129
|
): HardhatUserConfigValidationError[] {
|
|
@@ -97,6 +133,7 @@ export function validateSolidityTestUserConfig(
|
|
|
97
133
|
export async function resolveSolidityTestUserConfig(
|
|
98
134
|
userConfig: HardhatUserConfig,
|
|
99
135
|
resolvedConfig: HardhatConfig,
|
|
136
|
+
resolveConfigurationVariable: ConfigurationVariableResolver,
|
|
100
137
|
): Promise<HardhatConfig> {
|
|
101
138
|
let testsPath = userConfig.paths?.tests;
|
|
102
139
|
|
|
@@ -106,9 +143,15 @@ export async function resolveSolidityTestUserConfig(
|
|
|
106
143
|
|
|
107
144
|
const defaultRpcCachePath = path.join(resolvedConfig.paths.cache, "edr");
|
|
108
145
|
|
|
146
|
+
const resolvedForking = resolveSolidityTestForkingConfig(
|
|
147
|
+
userConfig.test?.solidity?.forking,
|
|
148
|
+
resolveConfigurationVariable,
|
|
149
|
+
);
|
|
150
|
+
|
|
109
151
|
const solidityTest = {
|
|
110
152
|
rpcCachePath: defaultRpcCachePath,
|
|
111
153
|
...userConfig.test?.solidity,
|
|
154
|
+
forking: resolvedForking,
|
|
112
155
|
};
|
|
113
156
|
|
|
114
157
|
return {
|
|
@@ -18,9 +18,12 @@ import {
|
|
|
18
18
|
FsAccessPermission,
|
|
19
19
|
} from "@nomicfoundation/edr";
|
|
20
20
|
import { hexStringToBytes } from "@nomicfoundation/hardhat-utils/hex";
|
|
21
|
+
import chalk from "chalk";
|
|
21
22
|
|
|
22
23
|
import { OPTIMISM_CHAIN_TYPE } from "../../constants.js";
|
|
23
24
|
|
|
25
|
+
import { type Colorizer, formatArtifactId } from "./formatters.js";
|
|
26
|
+
|
|
24
27
|
function hexStringToBuffer(hexString: string): Buffer {
|
|
25
28
|
return Buffer.from(hexStringToBytes(hexString));
|
|
26
29
|
}
|
|
@@ -31,14 +34,14 @@ export function solidityTestConfigToRunOptions(
|
|
|
31
34
|
return config;
|
|
32
35
|
}
|
|
33
36
|
|
|
34
|
-
export function solidityTestConfigToSolidityTestRunnerConfigArgs(
|
|
37
|
+
export async function solidityTestConfigToSolidityTestRunnerConfigArgs(
|
|
35
38
|
chainType: ChainType,
|
|
36
39
|
projectRoot: string,
|
|
37
40
|
config: SolidityTestConfig,
|
|
38
41
|
verbosity: number,
|
|
39
42
|
observability?: ObservabilityConfig,
|
|
40
43
|
testPattern?: string,
|
|
41
|
-
): SolidityTestRunnerConfigArgs {
|
|
44
|
+
): Promise<SolidityTestRunnerConfigArgs> {
|
|
42
45
|
const fsPermissions: PathPermission[] | undefined = [
|
|
43
46
|
config.fsPermissions?.readWriteFile?.map((p) => ({
|
|
44
47
|
access: FsAccessPermission.ReadWriteFile,
|
|
@@ -95,9 +98,22 @@ export function solidityTestConfigToSolidityTestRunnerConfigArgs(
|
|
|
95
98
|
|
|
96
99
|
const blockDifficulty = config.prevRandao;
|
|
97
100
|
|
|
98
|
-
|
|
101
|
+
let ethRpcUrl: string | undefined;
|
|
102
|
+
if (config.forking?.url !== undefined) {
|
|
103
|
+
ethRpcUrl = await config.forking.url.get();
|
|
104
|
+
}
|
|
105
|
+
|
|
99
106
|
const forkBlockNumber = config.forking?.blockNumber;
|
|
100
|
-
|
|
107
|
+
|
|
108
|
+
let rpcEndpoints: Record<string, string> | undefined;
|
|
109
|
+
if (config.forking?.rpcEndpoints !== undefined) {
|
|
110
|
+
rpcEndpoints = {};
|
|
111
|
+
for (const [name, configValue] of Object.entries(
|
|
112
|
+
config.forking.rpcEndpoints,
|
|
113
|
+
)) {
|
|
114
|
+
rpcEndpoints[name] = await configValue.get();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
101
117
|
|
|
102
118
|
return {
|
|
103
119
|
projectRoot,
|
|
@@ -128,3 +144,27 @@ export function isTestSuiteArtifact(artifact: Artifact): boolean {
|
|
|
128
144
|
return false;
|
|
129
145
|
});
|
|
130
146
|
}
|
|
147
|
+
|
|
148
|
+
export function warnDeprecatedTestFail(
|
|
149
|
+
artifact: Artifact,
|
|
150
|
+
sourceNameToUserSourceName: Map<string, string>,
|
|
151
|
+
colorizer: Colorizer = chalk,
|
|
152
|
+
): void {
|
|
153
|
+
const abi: Abi = JSON.parse(artifact.contract.abi);
|
|
154
|
+
|
|
155
|
+
abi.forEach(({ type, name }) => {
|
|
156
|
+
if (
|
|
157
|
+
type === "function" &&
|
|
158
|
+
typeof name === "string" &&
|
|
159
|
+
name.startsWith("testFail")
|
|
160
|
+
) {
|
|
161
|
+
const formattedLocation = formatArtifactId(
|
|
162
|
+
artifact.id,
|
|
163
|
+
sourceNameToUserSourceName,
|
|
164
|
+
);
|
|
165
|
+
const warningMessage = `${colorizer.yellow("Warning")}: ${name} The support for the prefix \`testFail*\` has been removed. Consider using \`vm.expectRevert()\` for testing reverts in ${formattedLocation}\n`;
|
|
166
|
+
|
|
167
|
+
console.warn(warningMessage);
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}
|
|
@@ -19,7 +19,11 @@ export default async (): Promise<Partial<ConfigHooks>> => {
|
|
|
19
19
|
resolveConfigurationVariable,
|
|
20
20
|
);
|
|
21
21
|
|
|
22
|
-
return resolveSolidityTestUserConfig(
|
|
22
|
+
return resolveSolidityTestUserConfig(
|
|
23
|
+
userConfig,
|
|
24
|
+
resolvedConfig,
|
|
25
|
+
resolveConfigurationVariable,
|
|
26
|
+
);
|
|
23
27
|
},
|
|
24
28
|
};
|
|
25
29
|
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { RunOptions } from "./runner.js";
|
|
2
2
|
import type { TestEvent } from "./types.js";
|
|
3
|
-
import type { BuildOptions } from "../../../types/solidity/build-system.js";
|
|
4
3
|
import type { NewTaskActionFunction } from "../../../types/tasks.js";
|
|
5
4
|
import type {
|
|
6
5
|
ObservabilityConfig,
|
|
@@ -14,22 +13,22 @@ import {
|
|
|
14
13
|
assertHardhatInvariant,
|
|
15
14
|
HardhatError,
|
|
16
15
|
} from "@nomicfoundation/hardhat-errors";
|
|
17
|
-
import { getAllFilesMatching } from "@nomicfoundation/hardhat-utils/fs";
|
|
18
16
|
import { resolveFromRoot } from "@nomicfoundation/hardhat-utils/path";
|
|
19
17
|
import { createNonClosingWriter } from "@nomicfoundation/hardhat-utils/stream";
|
|
20
18
|
|
|
21
19
|
import { HardhatRuntimeEnvironmentImplementation } from "../../core/hre.js";
|
|
22
20
|
import { isSupportedChainType } from "../../edr/chain-type.js";
|
|
21
|
+
import { ArtifactManagerImplementation } from "../artifacts/artifact-manager.js";
|
|
23
22
|
import {
|
|
24
23
|
markTestRunDone,
|
|
25
24
|
markTestRunStart,
|
|
26
25
|
markTestWorkerDone,
|
|
27
26
|
} from "../coverage/helpers.js";
|
|
28
|
-
import { throwIfSolidityBuildFailed } from "../solidity/build-results.js";
|
|
29
27
|
|
|
30
28
|
import { getEdrArtifacts, getBuildInfos } from "./edr-artifacts.js";
|
|
31
29
|
import {
|
|
32
30
|
isTestSuiteArtifact,
|
|
31
|
+
warnDeprecatedTestFail,
|
|
33
32
|
solidityTestConfigToRunOptions,
|
|
34
33
|
solidityTestConfigToSolidityTestRunnerConfigArgs,
|
|
35
34
|
} from "./helpers.js";
|
|
@@ -48,8 +47,6 @@ const runSolidityTests: NewTaskActionFunction<TestActionArguments> = async (
|
|
|
48
47
|
{ testFiles, chainType, grep, noCompile, verbosity },
|
|
49
48
|
hre,
|
|
50
49
|
) => {
|
|
51
|
-
let rootFilePaths: string[];
|
|
52
|
-
|
|
53
50
|
if (!isSupportedChainType(chainType)) {
|
|
54
51
|
throw new HardhatError(
|
|
55
52
|
HardhatError.ERRORS.CORE.ARGUMENTS.INVALID_VALUE_FOR_TYPE,
|
|
@@ -61,52 +58,47 @@ const runSolidityTests: NewTaskActionFunction<TestActionArguments> = async (
|
|
|
61
58
|
);
|
|
62
59
|
}
|
|
63
60
|
|
|
64
|
-
//
|
|
65
|
-
// Then, we compile just the test sources. We don't do it in one go because the user
|
|
66
|
-
// is likely to use different compilation options for the tests and the sources.
|
|
67
|
-
if (noCompile === false) {
|
|
68
|
-
await hre.tasks.getTask("compile").run();
|
|
69
|
-
}
|
|
61
|
+
// Run the compile task for test files
|
|
70
62
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
// TODO: Allow users to run test compilation outside of the test task.
|
|
96
|
-
const buildOptions: BuildOptions = {
|
|
97
|
-
force: false,
|
|
98
|
-
buildProfile: hre.globalOptions.buildProfile ?? "default",
|
|
99
|
-
quiet: true,
|
|
100
|
-
};
|
|
101
|
-
const results = await hre.solidity.build(rootFilePaths, buildOptions);
|
|
102
|
-
throwIfSolidityBuildFailed(results);
|
|
63
|
+
const { testRootPaths }: { testRootPaths: string[] } = await hre.tasks
|
|
64
|
+
.getTask("compile")
|
|
65
|
+
.run({
|
|
66
|
+
quiet: true,
|
|
67
|
+
force: false,
|
|
68
|
+
files: testFiles,
|
|
69
|
+
noContracts: noCompile,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const artifactsDirectory = await hre.solidity.getArtifactsDirectory("tests");
|
|
73
|
+
|
|
74
|
+
const artifactsManager = new ArtifactManagerImplementation(
|
|
75
|
+
artifactsDirectory,
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
const buildInfos = await getBuildInfos(artifactsManager);
|
|
79
|
+
const edrArtifacts = await getEdrArtifacts(artifactsManager);
|
|
80
|
+
|
|
81
|
+
const sourceNameToUserSourceName = new Map(
|
|
82
|
+
edrArtifacts.map(({ userSourceName, edrAtifact }) => [
|
|
83
|
+
edrAtifact.id.source,
|
|
84
|
+
userSourceName,
|
|
85
|
+
]),
|
|
86
|
+
);
|
|
103
87
|
|
|
104
|
-
|
|
105
|
-
|
|
88
|
+
edrArtifacts.forEach(({ userSourceName, edrAtifact }) => {
|
|
89
|
+
if (
|
|
90
|
+
testRootPaths.includes(
|
|
91
|
+
resolveFromRoot(hre.config.paths.root, userSourceName),
|
|
92
|
+
) &&
|
|
93
|
+
isTestSuiteArtifact(edrAtifact)
|
|
94
|
+
) {
|
|
95
|
+
warnDeprecatedTestFail(edrAtifact, sourceNameToUserSourceName);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
106
98
|
|
|
107
99
|
const testSuiteIds = edrArtifacts
|
|
108
100
|
.filter(({ userSourceName }) =>
|
|
109
|
-
|
|
101
|
+
testRootPaths.includes(
|
|
110
102
|
resolveFromRoot(hre.config.paths.root, userSourceName),
|
|
111
103
|
),
|
|
112
104
|
)
|
|
@@ -141,7 +133,7 @@ const runSolidityTests: NewTaskActionFunction<TestActionArguments> = async (
|
|
|
141
133
|
}
|
|
142
134
|
|
|
143
135
|
const config: SolidityTestRunnerConfigArgs =
|
|
144
|
-
solidityTestConfigToSolidityTestRunnerConfigArgs(
|
|
136
|
+
await solidityTestConfigToSolidityTestRunnerConfigArgs(
|
|
145
137
|
chainType,
|
|
146
138
|
hre.config.paths.root,
|
|
147
139
|
solidityTestConfig,
|
|
@@ -156,13 +148,6 @@ const runSolidityTests: NewTaskActionFunction<TestActionArguments> = async (
|
|
|
156
148
|
const options: RunOptions =
|
|
157
149
|
solidityTestConfigToRunOptions(solidityTestConfig);
|
|
158
150
|
|
|
159
|
-
const sourceNameToUserSourceName = new Map(
|
|
160
|
-
edrArtifacts.map(({ userSourceName, edrAtifact }) => [
|
|
161
|
-
edrAtifact.id.source,
|
|
162
|
-
userSourceName,
|
|
163
|
-
]),
|
|
164
|
-
);
|
|
165
|
-
|
|
166
151
|
await markTestRunStart("solidity");
|
|
167
152
|
|
|
168
153
|
const runStream = run(
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import "../../../types/config.js";
|
|
2
|
+
import type {
|
|
3
|
+
SensitiveString,
|
|
4
|
+
ResolvedConfigurationVariable,
|
|
5
|
+
} from "../../../types/config.js";
|
|
2
6
|
|
|
3
7
|
declare module "../../../types/config.js" {
|
|
4
8
|
export interface TestPathsUserConfig {
|
|
@@ -11,7 +15,7 @@ declare module "../../../types/config.js" {
|
|
|
11
15
|
}
|
|
12
16
|
|
|
13
17
|
declare module "../../../types/test.js" {
|
|
14
|
-
export interface
|
|
18
|
+
export interface SolidityTestConfigBase {
|
|
15
19
|
timeout?: number;
|
|
16
20
|
fsPermissions?: {
|
|
17
21
|
readWriteFile?: string[];
|
|
@@ -33,12 +37,6 @@ declare module "../../../types/test.js" {
|
|
|
33
37
|
prevRandao?: bigint;
|
|
34
38
|
blockGasLimit?: bigint | false;
|
|
35
39
|
|
|
36
|
-
forking?: {
|
|
37
|
-
url?: string;
|
|
38
|
-
blockNumber?: bigint;
|
|
39
|
-
rpcEndpoints?: Record<string, string>;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
40
|
fuzz?: {
|
|
43
41
|
failurePersistDir?: string;
|
|
44
42
|
failurePersistFile?: string;
|
|
@@ -62,13 +60,29 @@ declare module "../../../types/test.js" {
|
|
|
62
60
|
};
|
|
63
61
|
}
|
|
64
62
|
|
|
63
|
+
export interface SolidityTestForkingUserConfig {
|
|
64
|
+
url?: SensitiveString;
|
|
65
|
+
blockNumber?: bigint;
|
|
66
|
+
rpcEndpoints?: Record<string, SensitiveString>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface SolidityTestUserConfig extends SolidityTestConfigBase {
|
|
70
|
+
forking?: SolidityTestForkingUserConfig;
|
|
71
|
+
}
|
|
72
|
+
|
|
65
73
|
export interface HardhatTestUserConfig {
|
|
66
74
|
solidity?: SolidityTestUserConfig;
|
|
67
75
|
}
|
|
68
76
|
|
|
69
|
-
|
|
70
|
-
|
|
77
|
+
export interface SolidityTestForkingConfig {
|
|
78
|
+
url?: ResolvedConfigurationVariable;
|
|
79
|
+
blockNumber?: bigint;
|
|
80
|
+
rpcEndpoints?: Record<string, ResolvedConfigurationVariable>;
|
|
81
|
+
}
|
|
71
82
|
|
|
83
|
+
export interface SolidityTestConfig extends SolidityTestConfigBase {
|
|
84
|
+
forking?: SolidityTestForkingConfig;
|
|
85
|
+
}
|
|
72
86
|
export interface HardhatTestConfig {
|
|
73
87
|
solidity: SolidityTestConfig;
|
|
74
88
|
}
|