Skip to content

Commit 16d7c13

Browse files
authored
Merge branch 'v-next' into feat/skeleton-solidity-test-integration
2 parents 771ec25 + 2697d7a commit 16d7c13

File tree

17 files changed

+1341
-160
lines changed

17 files changed

+1341
-160
lines changed

v-next/example-project/viem-scketch-plugin.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { HardhatPlugin } from "@ignored/hardhat-vnext/types/plugins";
2-
import { ChainType } from "@ignored/hardhat-vnext/types/config";
32
import { HookContext } from "@ignored/hardhat-vnext/types/hooks";
43

5-
import type { NetworkConnection } from "@ignored/hardhat-vnext/types/network";
4+
import type {
5+
ChainType,
6+
NetworkConnection,
7+
} from "@ignored/hardhat-vnext/types/network";
68

79
import "@ignored/hardhat-vnext/types/network";
810

v-next/hardhat-network-helpers/src/internal/hook-handlers/network.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import type { ChainType } from "@ignored/hardhat-vnext/types/config";
21
import type {
32
HookContext,
43
NetworkHooks,
54
} from "@ignored/hardhat-vnext/types/hooks";
6-
import type { NetworkConnection } from "@ignored/hardhat-vnext/types/network";
5+
import type {
6+
ChainType,
7+
NetworkConnection,
8+
} from "@ignored/hardhat-vnext/types/network";
79

810
import { NetworkHelpers } from "../network-helpers/network-helpers.js";
911

v-next/hardhat-network-helpers/src/type-extensions.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import "@ignored/hardhat-vnext/types/network";
22

33
import type { NetworkHelpers } from "./internal/network-helpers/network-helpers.js";
4-
import type { ChainType } from "@ignored/hardhat-vnext/types/config";
54

65
declare module "@ignored/hardhat-vnext/types/network" {
76
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- the ChainTypeT must be declared in the interface but in this scenario it's not used

v-next/hardhat-zod-utils/src/index.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { ZodTypeDef, ZodType } from "zod";
22

3-
import { isObject } from "@ignored/hardhat-vnext-utils/lang";
43
import { z } from "zod";
54

65
/**
@@ -138,29 +137,32 @@ export const incompatibleFieldType = (errorMessage = "Unexpected field") =>
138137
/**
139138
* A Zod type to validate Hardhat's ConfigurationVariable objects.
140139
*/
141-
export const configurationVariableType = z.object({
140+
export const configurationVariableSchema = z.object({
142141
_type: z.literal("ConfigurationVariable"),
143142
name: z.string(),
144143
});
145144

146145
/**
147146
* A Zod type to validate Hardhat's SensitiveString values.
148147
*/
149-
export const sensitiveStringType = conditionalUnionType(
150-
[
151-
[(data) => typeof data === "string", z.string()],
152-
[isObject, configurationVariableType],
153-
],
148+
export const sensitiveStringSchema = unionType(
149+
[z.string(), configurationVariableSchema],
154150
"Expected a string or a Configuration Variable",
155151
);
156152

157153
/**
158154
* A Zod type to validate Hardhat's SensitiveString values that expect a URL.
155+
*
156+
* TODO: The custom error message in the unionType function doesn't work
157+
* correctly when using string().url() for validation, see:
158+
* https://github.com/colinhacks/zod/issues/2940
159+
* As a workaround, we provide the error message directly in the url() call.
160+
* We should remove this when the issue is fixed.
159161
*/
160-
export const sensitiveUrlType = conditionalUnionType(
162+
export const sensitiveUrlSchema = unionType(
161163
[
162-
[(data) => typeof data === "string", z.string().url()],
163-
[isObject, configurationVariableType],
164+
z.string().url("Expected a URL or a Configuration Variable"),
165+
configurationVariableSchema,
164166
],
165167
"Expected a URL or a Configuration Variable",
166168
);
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,94 @@
11
import type {
2+
ConfigurationVariable,
3+
GasConfig,
4+
GasUserConfig,
5+
HardhatConfig,
6+
HardhatUserConfig,
27
HttpNetworkConfig,
38
NetworkConfig,
49
NetworkUserConfig,
10+
ResolvedConfigurationVariable,
511
} from "../../../../types/config.js";
612
import type { ConfigHooks } from "../../../../types/hooks.js";
713

814
import { validateUserConfig } from "../type-validation.js";
915

10-
function resolveBigIntOrAuto(
11-
value: number | bigint | "auto" | undefined,
12-
): bigint | "auto" {
13-
if (value === undefined || value === "auto") {
14-
return "auto";
15-
}
16-
17-
// TODO: Validate that it's a valid BigInt
18-
return BigInt(value);
19-
}
20-
2116
export default async (): Promise<Partial<ConfigHooks>> => ({
22-
extendUserConfig: async (config, next) => {
23-
const extendedConfig = await next(config);
17+
extendUserConfig,
18+
validateUserConfig,
19+
resolveUserConfig,
20+
});
2421

25-
const networks: Record<string, NetworkUserConfig> =
26-
extendedConfig.networks ?? {};
22+
export async function extendUserConfig(
23+
config: HardhatUserConfig,
24+
next: (nextConfig: HardhatUserConfig) => Promise<HardhatUserConfig>,
25+
): Promise<HardhatUserConfig> {
26+
const extendedConfig = await next(config);
2727

28-
return {
29-
...extendedConfig,
30-
networks: {
31-
...networks,
32-
localhost: {
33-
url: "http://localhost:8545",
34-
...networks.localhost,
35-
type: "http",
36-
},
37-
},
38-
};
39-
},
40-
validateUserConfig,
41-
resolveUserConfig: async (userConfig, resolveConfigurationVariable, next) => {
42-
const resolvedConfig = await next(userConfig, resolveConfigurationVariable);
28+
const networks: Record<string, NetworkUserConfig> =
29+
extendedConfig.networks ?? {};
4330

44-
const networks: Record<string, NetworkUserConfig> =
45-
userConfig.networks ?? {};
31+
return {
32+
...extendedConfig,
33+
networks: {
34+
...networks,
35+
localhost: {
36+
url: "http://localhost:8545",
37+
...networks.localhost,
38+
type: "http",
39+
},
40+
},
41+
};
42+
}
4643

47-
const resolvedNetworks: Record<string, NetworkConfig> = {};
44+
export async function resolveUserConfig(
45+
userConfig: HardhatUserConfig,
46+
resolveConfigurationVariable: (
47+
variableOrString: ConfigurationVariable | string,
48+
) => ResolvedConfigurationVariable,
49+
next: (
50+
nextUserConfig: HardhatUserConfig,
51+
nextResolveConfigurationVariable: (
52+
variableOrString: ConfigurationVariable | string,
53+
) => ResolvedConfigurationVariable,
54+
) => Promise<HardhatConfig>,
55+
): Promise<HardhatConfig> {
56+
const resolvedConfig = await next(userConfig, resolveConfigurationVariable);
4857

49-
for (const [networkName, networkConfig] of Object.entries(networks)) {
50-
if (networkConfig.type !== "http") {
51-
// eslint-disable-next-line no-restricted-syntax -- TODO
52-
throw new Error("Only HTTP network is supported for now");
53-
}
58+
const networks: Record<string, NetworkUserConfig> = userConfig.networks ?? {};
5459

55-
const resolvedNetworkConfig: HttpNetworkConfig = {
56-
type: "http",
57-
chainId: networkConfig.chainId,
58-
chainType: networkConfig.chainType,
59-
from: networkConfig.from,
60-
gas: resolveBigIntOrAuto(networkConfig.gas),
61-
gasMultiplier: networkConfig.gasMultiplier ?? 1,
62-
gasPrice: resolveBigIntOrAuto(networkConfig.gasPrice),
63-
url: networkConfig.url,
64-
timeout: networkConfig.timeout ?? 20_000,
65-
httpHeaders: networkConfig.httpHeaders ?? {},
66-
};
60+
const resolvedNetworks: Record<string, NetworkConfig> = {};
6761

68-
resolvedNetworks[networkName] = resolvedNetworkConfig;
62+
for (const [networkName, networkConfig] of Object.entries(networks)) {
63+
if (networkConfig.type !== "http") {
64+
// eslint-disable-next-line no-restricted-syntax -- TODO
65+
throw new Error("Only HTTP network is supported for now");
6966
}
7067

71-
return {
72-
...resolvedConfig,
73-
defaultNetwork: resolvedConfig.defaultNetwork ?? "localhost",
74-
defaultChainType: resolvedConfig.defaultChainType ?? "unknown",
75-
networks: resolvedNetworks,
68+
const resolvedNetworkConfig: HttpNetworkConfig = {
69+
type: "http",
70+
chainId: networkConfig.chainId,
71+
chainType: networkConfig.chainType,
72+
from: networkConfig.from,
73+
gas: resolveGasConfig(networkConfig.gas),
74+
gasMultiplier: networkConfig.gasMultiplier ?? 1,
75+
gasPrice: resolveGasConfig(networkConfig.gasPrice),
76+
url: networkConfig.url,
77+
timeout: networkConfig.timeout ?? 20_000,
78+
httpHeaders: networkConfig.httpHeaders ?? {},
7679
};
77-
},
78-
});
80+
81+
resolvedNetworks[networkName] = resolvedNetworkConfig;
82+
}
83+
84+
return {
85+
...resolvedConfig,
86+
defaultChainType: resolvedConfig.defaultChainType ?? "unknown",
87+
defaultNetwork: resolvedConfig.defaultNetwork ?? "localhost",
88+
networks: resolvedNetworks,
89+
};
90+
}
91+
92+
function resolveGasConfig(value: GasUserConfig = "auto"): GasConfig {
93+
return value === "auto" ? value : BigInt(value);
94+
}

v-next/hardhat/src/internal/builtin-plugins/network-manager/http-provider.ts

-2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ export class HttpProvider extends EventEmitter implements EthereumProvider {
112112
this.#jsonRpcRequestWrapper = jsonRpcRequestWrapper;
113113
}
114114

115-
// TODO: We should test that the request is actually wrapped
116115
public async request(
117116
requestArguments: RequestArguments,
118117
): Promise<SuccessfulJsonRpcResponse["result"]> {
@@ -151,7 +150,6 @@ export class HttpProvider extends EventEmitter implements EthereumProvider {
151150
return jsonRpcResponse.result;
152151
}
153152

154-
// TODO: This should be tested
155153
public async close(): Promise<void> {
156154
// See https://github.com/nodejs/undici/discussions/3522#discussioncomment-10498734
157155
await this.#dispatcher.close();

v-next/hardhat/src/internal/builtin-plugins/network-manager/network-connection.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { ChainType, NetworkConfig } from "../../../types/config.js";
2-
import type { NetworkConnection } from "../../../types/network.js";
1+
import type { NetworkConfig } from "../../../types/config.js";
2+
import type { ChainType, NetworkConnection } from "../../../types/network.js";
33
import type { EthereumProvider } from "../../../types/providers.js";
44

55
export type CloseConnectionFunction<ChainTypeT extends ChainType | string> = (

v-next/hardhat/src/internal/builtin-plugins/network-manager/network-manager.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import type { NetworkConfig } from "../../../types/config.js";
2+
import type { HookManager } from "../../../types/hooks.js";
13
import type {
24
ChainType,
35
DefaultChainType,
4-
NetworkConfig,
5-
} from "../../../types/config.js";
6-
import type { HookManager } from "../../../types/hooks.js";
7-
import type { NetworkConnection } from "../../../types/network.js";
6+
NetworkConnection,
7+
} from "../../../types/network.js";
88
import type { EthereumProvider } from "../../../types/providers.js";
99

1010
import { HardhatError } from "@ignored/hardhat-vnext-errors";
@@ -71,6 +71,7 @@ export class NetworkManagerImplementation {
7171

7272
if (
7373
networkConfigOverride !== undefined &&
74+
"type" in networkConfigOverride &&
7475
networkConfigOverride.type !==
7576
this.#networkConfigs[resolvedNetworkName].type
7677
) {

v-next/hardhat/src/internal/builtin-plugins/network-manager/type-extensions/config.ts

+14-42
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,7 @@
1+
import type { ChainType, DefaultChainType } from "../../../../types/network.js";
2+
13
import "../../../../types/config.js";
24
declare module "../../../../types/config.js" {
3-
/**
4-
* Represents the possible chain types for the network. The options are:
5-
* - `"unknown"`: Represents the most generic type of network.
6-
* - `"l1"`: Represents Layer 1 networks like Ethereum.
7-
* - `"optimism"`: Represents Layer 2 networks like Optimism.
8-
*/
9-
export type ChainType = "unknown" | "l1" | "optimism";
10-
11-
/**
12-
* Determines the default chain type to use when no chain type is specified.
13-
* The default chain type is `"unknown"` by default. You can customize the
14-
* default chain type by adding a `defaultChainType` property to the
15-
* `ChainTypeConfig` interface with a valid `ChainType` value.
16-
* For example:
17-
* ```ts
18-
* declare module "@ignored/hardhat-vnext/types/config" {
19-
* export interface ChainTypeConfig {
20-
* defaultChainType: "l1";
21-
* }
22-
* }
23-
* ```
24-
*/
25-
export type DefaultChainType = ChainTypeConfig extends {
26-
defaultChainType: infer T;
27-
}
28-
? T extends ChainType
29-
? T
30-
: "unknown"
31-
: "unknown";
32-
33-
/* eslint-disable-next-line @typescript-eslint/no-empty-interface -- Empty
34-
interface to allow the user to change the default chain type. */
35-
export interface ChainTypeConfig {}
36-
375
export interface HardhatUserConfig {
386
defaultChainType?: DefaultChainType;
397
defaultNetwork?: string;
@@ -48,14 +16,16 @@ declare module "../../../../types/config.js" {
4816

4917
export type NetworkUserConfig = HttpNetworkUserConfig | EdrNetworkUserConfig;
5018

19+
export type GasUserConfig = "auto" | number | bigint;
20+
5121
export interface HttpNetworkUserConfig {
5222
type: "http";
5323
chainId?: number;
5424
chainType?: ChainType;
5525
from?: string;
56-
gas?: "auto" | number | bigint;
26+
gas?: GasUserConfig;
5727
gasMultiplier?: number;
58-
gasPrice?: "auto" | number | bigint;
28+
gasPrice?: GasUserConfig;
5929

6030
// HTTP network specific
6131
url: string;
@@ -68,23 +38,25 @@ declare module "../../../../types/config.js" {
6838
chainId: number;
6939
chainType?: ChainType;
7040
from?: string;
71-
gas: "auto" | number | bigint;
41+
gas: GasUserConfig;
7242
gasMultiplier: number;
73-
gasPrice: "auto" | number | bigint;
43+
gasPrice: GasUserConfig;
7444

7545
// EDR network specific
7646
}
7747

7848
export type NetworkConfig = HttpNetworkConfig | EdrNetworkConfig;
7949

50+
export type GasConfig = "auto" | bigint;
51+
8052
export interface HttpNetworkConfig {
8153
type: "http";
8254
chainId?: number;
8355
chainType?: ChainType;
8456
from?: string;
85-
gas: "auto" | bigint;
57+
gas: GasConfig;
8658
gasMultiplier: number;
87-
gasPrice: "auto" | bigint;
59+
gasPrice: GasConfig;
8860

8961
// HTTP network specific
9062
url: string;
@@ -97,9 +69,9 @@ declare module "../../../../types/config.js" {
9769
chainId: number;
9870
chainType?: ChainType;
9971
from: string;
100-
gas: "auto" | bigint;
72+
gas: GasConfig;
10173
gasMultiplier: number;
102-
gasPrice: "auto" | bigint;
74+
gasPrice: GasConfig;
10375

10476
// EDR network specific
10577
}

v-next/hardhat/src/internal/builtin-plugins/network-manager/type-extensions/hooks.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import type { ChainType } from "../../../../types/config.js";
2-
import type { NetworkConnection } from "../../../../types/network.js";
1+
import type {
2+
ChainType,
3+
NetworkConnection,
4+
} from "../../../../types/network.js";
35
import type {
46
JsonRpcRequest,
57
JsonRpcResponse,

0 commit comments

Comments
 (0)