hardhat 2.12.5 → 2.12.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/builtin-tasks/compile.js +10 -1
- package/builtin-tasks/compile.js.map +1 -1
- package/builtin-tasks/flatten.js +1 -1
- package/builtin-tasks/flatten.js.map +1 -1
- package/builtin-tasks/help.js +2 -4
- package/builtin-tasks/help.js.map +1 -1
- package/builtin-tasks/task-names.d.ts +1 -0
- package/builtin-tasks/task-names.d.ts.map +1 -1
- package/builtin-tasks/task-names.js +3 -2
- package/builtin-tasks/task-names.js.map +1 -1
- package/internal/cli/cli.js +0 -7
- package/internal/cli/cli.js.map +1 -1
- package/internal/cli/project-creation.d.ts +0 -1
- package/internal/cli/project-creation.d.ts.map +1 -1
- package/internal/cli/project-creation.js +19 -15
- package/internal/cli/project-creation.js.map +1 -1
- package/internal/cli/prompt.d.ts +2 -2
- package/internal/cli/prompt.d.ts.map +1 -1
- package/internal/cli/prompt.js +1 -2
- package/internal/cli/prompt.js.map +1 -1
- package/internal/cli/types.d.ts +1 -0
- package/internal/cli/types.d.ts.map +1 -1
- package/internal/core/config/config-loading.d.ts.map +1 -1
- package/internal/core/config/config-loading.js +1 -0
- package/internal/core/config/config-loading.js.map +1 -1
- package/internal/core/config/config-validation.d.ts +2 -0
- package/internal/core/config/config-validation.d.ts.map +1 -1
- package/internal/core/config/config-validation.js +18 -1
- package/internal/core/config/config-validation.js.map +1 -1
- package/internal/core/errors-list.d.ts +7 -0
- package/internal/core/errors-list.d.ts.map +1 -1
- package/internal/core/errors-list.js +9 -0
- package/internal/core/errors-list.js.map +1 -1
- package/internal/core/providers/construction.d.ts.map +1 -1
- package/internal/core/providers/construction.js +25 -5
- package/internal/core/providers/construction.js.map +1 -1
- package/internal/core/providers/http.d.ts +2 -2
- package/internal/core/providers/http.d.ts.map +1 -1
- package/internal/core/providers/http.js +29 -5
- package/internal/core/providers/http.js.map +1 -1
- package/internal/core/runtime-environment.d.ts +1 -0
- package/internal/core/runtime-environment.d.ts.map +1 -1
- package/internal/core/runtime-environment.js +2 -0
- package/internal/core/runtime-environment.js.map +1 -1
- package/internal/hardhat-network/jsonrpc/handler.d.ts +1 -0
- package/internal/hardhat-network/jsonrpc/handler.d.ts.map +1 -1
- package/internal/hardhat-network/jsonrpc/handler.js +13 -18
- package/internal/hardhat-network/jsonrpc/handler.js.map +1 -1
- package/internal/hardhat-network/provider/modules/evm.d.ts +2 -1
- package/internal/hardhat-network/provider/modules/evm.d.ts.map +1 -1
- package/internal/hardhat-network/provider/modules/evm.js +10 -4
- package/internal/hardhat-network/provider/modules/evm.js.map +1 -1
- package/internal/hardhat-network/provider/node-types.d.ts +1 -1
- package/internal/hardhat-network/provider/node-types.d.ts.map +1 -1
- package/internal/hardhat-network/provider/node.d.ts +1 -0
- package/internal/hardhat-network/provider/node.d.ts.map +1 -1
- package/internal/hardhat-network/provider/node.js +6 -4
- package/internal/hardhat-network/provider/node.js.map +1 -1
- package/internal/hardhat-network/provider/provider.d.ts +25 -21
- package/internal/hardhat-network/provider/provider.d.ts.map +1 -1
- package/internal/hardhat-network/provider/provider.js +25 -42
- package/internal/hardhat-network/provider/provider.js.map +1 -1
- package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.d.ts.map +1 -1
- package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.js +4 -2
- package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.js.map +1 -1
- package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.d.ts.map +1 -1
- package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.js +4 -2
- package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.js.map +1 -1
- package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.d.ts.map +1 -1
- package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.js +4 -2
- package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.js.map +1 -1
- package/internal/hardhat-network/provider/utils/makeFakeSignature.d.ts +7 -0
- package/internal/hardhat-network/provider/utils/makeFakeSignature.d.ts.map +1 -0
- package/internal/hardhat-network/provider/utils/makeFakeSignature.js +31 -0
- package/internal/hardhat-network/provider/utils/makeFakeSignature.js.map +1 -0
- package/internal/hardhat-network/provider/utils/putGenesisBlock.d.ts +1 -1
- package/internal/hardhat-network/provider/utils/putGenesisBlock.d.ts.map +1 -1
- package/internal/hardhat-network/provider/utils/putGenesisBlock.js +2 -2
- package/internal/hardhat-network/provider/utils/putGenesisBlock.js.map +1 -1
- package/internal/solidity/resolver.d.ts +4 -3
- package/internal/solidity/resolver.d.ts.map +1 -1
- package/internal/solidity/resolver.js +18 -7
- package/internal/solidity/resolver.js.map +1 -1
- package/internal/util/download.d.ts.map +1 -1
- package/internal/util/download.js +13 -10
- package/internal/util/download.js.map +1 -1
- package/internal/util/packageInfo.d.ts +1 -1
- package/internal/util/packageInfo.d.ts.map +1 -1
- package/internal/util/packageInfo.js +4 -10
- package/internal/util/packageInfo.js.map +1 -1
- package/internal/util/proxy.d.ts +2 -0
- package/internal/util/proxy.d.ts.map +1 -0
- package/internal/util/proxy.js +19 -0
- package/internal/util/proxy.js.map +1 -0
- package/package.json +3 -4
- package/src/builtin-tasks/compile.ts +16 -1
- package/src/builtin-tasks/flatten.ts +4 -1
- package/src/builtin-tasks/help.ts +15 -16
- package/src/builtin-tasks/task-names.ts +2 -0
- package/src/internal/cli/cli.ts +1 -11
- package/src/internal/cli/project-creation.ts +20 -20
- package/src/internal/cli/prompt.ts +2 -4
- package/src/internal/cli/types.ts +2 -0
- package/src/internal/core/config/config-loading.ts +3 -1
- package/src/internal/core/config/config-validation.ts +20 -0
- package/src/internal/core/errors-list.ts +10 -0
- package/src/internal/core/providers/construction.ts +29 -24
- package/src/internal/core/providers/http.ts +17 -11
- package/src/internal/core/runtime-environment.ts +3 -0
- package/src/internal/hardhat-network/jsonrpc/handler.ts +31 -28
- package/src/internal/hardhat-network/provider/modules/evm.ts +15 -3
- package/src/internal/hardhat-network/provider/node-types.ts +1 -1
- package/src/internal/hardhat-network/provider/node.ts +5 -1
- package/src/internal/hardhat-network/provider/provider.ts +60 -49
- package/src/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.ts +5 -2
- package/src/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.ts +5 -2
- package/src/internal/hardhat-network/provider/transactions/FakeSenderTransaction.ts +5 -2
- package/src/internal/hardhat-network/provider/utils/makeFakeSignature.ts +46 -0
- package/src/internal/hardhat-network/provider/utils/putGenesisBlock.ts +2 -2
- package/src/internal/solidity/resolver.ts +28 -11
- package/src/internal/util/download.ts +13 -12
- package/src/internal/util/packageInfo.ts +9 -10
- package/src/internal/util/proxy.ts +18 -0
- package/src/types/artifacts.ts +1 -0
- package/src/types/config.ts +2 -0
- package/src/types/runtime.ts +1 -0
- package/types/artifacts.d.ts +1 -0
- package/types/artifacts.d.ts.map +1 -1
- package/types/config.d.ts +2 -0
- package/types/config.d.ts.map +1 -1
- package/types/runtime.d.ts +1 -0
- package/types/runtime.d.ts.map +1 -1
|
@@ -82,40 +82,23 @@ export class JsonRpcHandler {
|
|
|
82
82
|
this._provider.addListener("notification", listener);
|
|
83
83
|
|
|
84
84
|
ws.on("message", async (msg) => {
|
|
85
|
-
let rpcReq: JsonRpcRequest |
|
|
86
|
-
let rpcResp: JsonRpcResponse |
|
|
85
|
+
let rpcReq: JsonRpcRequest | JsonRpcRequest[];
|
|
86
|
+
let rpcResp: JsonRpcResponse | JsonRpcResponse[];
|
|
87
87
|
|
|
88
88
|
try {
|
|
89
89
|
rpcReq = _readWsRequest(msg as string);
|
|
90
90
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
// so we can cleanup on websocket close.
|
|
99
|
-
if (
|
|
100
|
-
rpcReq.method === "eth_subscribe" &&
|
|
101
|
-
isSuccessfulJsonResponse(rpcResp)
|
|
102
|
-
) {
|
|
103
|
-
subscriptions.push(rpcResp.result);
|
|
104
|
-
}
|
|
91
|
+
rpcResp = Array.isArray(rpcReq)
|
|
92
|
+
? await Promise.all(
|
|
93
|
+
rpcReq.map((req) =>
|
|
94
|
+
this._handleSingleWsRequest(req, subscriptions)
|
|
95
|
+
)
|
|
96
|
+
)
|
|
97
|
+
: await this._handleSingleWsRequest(rpcReq, subscriptions);
|
|
105
98
|
} catch (error) {
|
|
106
99
|
rpcResp = _handleError(error);
|
|
107
100
|
}
|
|
108
101
|
|
|
109
|
-
// Validate the RPC response.
|
|
110
|
-
if (!isValidJsonResponse(rpcResp)) {
|
|
111
|
-
// Malformed response coming from the provider, report to user as an internal error.
|
|
112
|
-
rpcResp = _handleError(new InternalError("Internal error"));
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (rpcReq !== undefined) {
|
|
116
|
-
rpcResp.id = rpcReq.id;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
102
|
ws.send(JSON.stringify(rpcResp));
|
|
120
103
|
});
|
|
121
104
|
|
|
@@ -155,7 +138,9 @@ export class JsonRpcHandler {
|
|
|
155
138
|
res.end(JSON.stringify(rpcResp));
|
|
156
139
|
}
|
|
157
140
|
|
|
158
|
-
private async _handleSingleRequest(
|
|
141
|
+
private async _handleSingleRequest(
|
|
142
|
+
req: JsonRpcRequest
|
|
143
|
+
): Promise<JsonRpcResponse> {
|
|
159
144
|
if (!isValidJsonRequest(req)) {
|
|
160
145
|
return _handleError(new InvalidRequestError("Invalid request"));
|
|
161
146
|
}
|
|
@@ -182,6 +167,24 @@ export class JsonRpcHandler {
|
|
|
182
167
|
return rpcResp;
|
|
183
168
|
}
|
|
184
169
|
|
|
170
|
+
private async _handleSingleWsRequest(
|
|
171
|
+
rpcReq: JsonRpcRequest,
|
|
172
|
+
subscriptions: string[]
|
|
173
|
+
) {
|
|
174
|
+
const rpcResp = await this._handleSingleRequest(rpcReq);
|
|
175
|
+
|
|
176
|
+
// If eth_subscribe was successful, keep track of the subscription id,
|
|
177
|
+
// so we can cleanup on websocket close.
|
|
178
|
+
if (
|
|
179
|
+
rpcReq.method === "eth_subscribe" &&
|
|
180
|
+
isSuccessfulJsonResponse(rpcResp)
|
|
181
|
+
) {
|
|
182
|
+
subscriptions.push(rpcResp.result);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return rpcResp;
|
|
186
|
+
}
|
|
187
|
+
|
|
185
188
|
private _handleRequest = async (
|
|
186
189
|
req: JsonRpcRequest
|
|
187
190
|
): Promise<JsonRpcResponse> => {
|
|
@@ -218,7 +221,7 @@ const _readJsonHttpRequest = async (req: IncomingMessage): Promise<any> => {
|
|
|
218
221
|
return json;
|
|
219
222
|
};
|
|
220
223
|
|
|
221
|
-
const _readWsRequest = (msg: string): JsonRpcRequest => {
|
|
224
|
+
const _readWsRequest = (msg: string): JsonRpcRequest | JsonRpcRequest[] => {
|
|
222
225
|
let json: any;
|
|
223
226
|
try {
|
|
224
227
|
json = JSON.parse(msg);
|
|
@@ -32,6 +32,7 @@ export class EvmModule {
|
|
|
32
32
|
private readonly _node: HardhatNode,
|
|
33
33
|
private readonly _miningTimer: MiningTimer,
|
|
34
34
|
private readonly _logger: ModulesLogger,
|
|
35
|
+
private readonly _allowBlocksWithSameTimestamp: boolean,
|
|
35
36
|
private readonly _experimentalHardhatNetworkMessageTraceHooks: BoundExperimentalHardhatNetworkMessageTraceHook[] = []
|
|
36
37
|
) {}
|
|
37
38
|
|
|
@@ -86,12 +87,23 @@ export class EvmModule {
|
|
|
86
87
|
const latestBlock = await this._node.getLatestBlock();
|
|
87
88
|
const increment = BigInt(timestamp) - latestBlock.header.timestamp;
|
|
88
89
|
|
|
89
|
-
if (increment
|
|
90
|
+
if (increment < 0n) {
|
|
90
91
|
throw new InvalidInputError(
|
|
91
|
-
`Timestamp ${timestamp.toString()} is lower than
|
|
92
|
-
|
|
92
|
+
`Timestamp ${timestamp.toString()} is lower than the previous block's timestamp ${
|
|
93
|
+
latestBlock.header.timestamp
|
|
94
|
+
}`
|
|
93
95
|
);
|
|
94
96
|
}
|
|
97
|
+
|
|
98
|
+
if (!this._allowBlocksWithSameTimestamp && increment === 0n) {
|
|
99
|
+
throw new InvalidInputError(
|
|
100
|
+
`Timestamp ${timestamp.toString()} is equal to the previous block's timestamp.
|
|
101
|
+
|
|
102
|
+
Enable the "allowBlocksWithSameTimestamp" option in the Hardhat network configuration to allow this.
|
|
103
|
+
`
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
95
107
|
this._node.setNextBlockTimestamp(BigInt(timestamp));
|
|
96
108
|
return timestamp.toString();
|
|
97
109
|
}
|
|
@@ -24,7 +24,6 @@ interface CommonConfig {
|
|
|
24
24
|
hardfork: string;
|
|
25
25
|
minGasPrice: bigint;
|
|
26
26
|
networkId: number;
|
|
27
|
-
networkName: string;
|
|
28
27
|
allowUnlimitedContractSize?: boolean;
|
|
29
28
|
initialDate?: Date;
|
|
30
29
|
tracingConfig?: TracingConfig;
|
|
@@ -32,6 +31,7 @@ interface CommonConfig {
|
|
|
32
31
|
mempoolOrder: MempoolOrder;
|
|
33
32
|
coinbase: string;
|
|
34
33
|
chains: HardhatNetworkChainsConfig;
|
|
34
|
+
allowBlocksWithSameTimestamp: boolean;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
export type LocalNodeConfig = CommonConfig;
|
|
@@ -146,6 +146,7 @@ export class HardhatNode extends EventEmitter {
|
|
|
146
146
|
mempoolOrder,
|
|
147
147
|
networkId,
|
|
148
148
|
chainId,
|
|
149
|
+
allowBlocksWithSameTimestamp,
|
|
149
150
|
} = config;
|
|
150
151
|
|
|
151
152
|
let stateManager: StateManager;
|
|
@@ -293,6 +294,7 @@ export class HardhatNode extends EventEmitter {
|
|
|
293
294
|
hardfork,
|
|
294
295
|
hardforkActivations,
|
|
295
296
|
mixHashGenerator,
|
|
297
|
+
allowBlocksWithSameTimestamp,
|
|
296
298
|
tracingConfig,
|
|
297
299
|
forkNetworkId,
|
|
298
300
|
forkBlockNum,
|
|
@@ -378,6 +380,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
378
380
|
public readonly hardfork: HardforkName,
|
|
379
381
|
private readonly _hardforkActivations: HardforkHistoryConfig,
|
|
380
382
|
private _mixHashGenerator: RandomBufferGenerator,
|
|
383
|
+
private _allowBlocksWithSameTimestamp: boolean,
|
|
381
384
|
tracingConfig?: TracingConfig,
|
|
382
385
|
private _forkNetworkId?: number,
|
|
383
386
|
private _forkBlockNumber?: bigint,
|
|
@@ -494,7 +497,8 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
494
497
|
const [, offsetShouldChange, newOffset] = timestampAndOffset;
|
|
495
498
|
|
|
496
499
|
const needsTimestampIncrease =
|
|
497
|
-
|
|
500
|
+
!this._allowBlocksWithSameTimestamp &&
|
|
501
|
+
(await this._timestampClashesWithPreviousBlockOne(blockTimestamp));
|
|
498
502
|
if (needsTimestampIncrease) {
|
|
499
503
|
blockTimestamp += 1n;
|
|
500
504
|
}
|
|
@@ -58,6 +58,30 @@ const PRIVATE_RPC_METHODS = new Set([
|
|
|
58
58
|
|
|
59
59
|
export const DEFAULT_COINBASE = "0xc014ba5ec014ba5ec014ba5ec014ba5ec014ba5e";
|
|
60
60
|
|
|
61
|
+
interface HardhatNetworkProviderConfig {
|
|
62
|
+
hardfork: string;
|
|
63
|
+
chainId: number;
|
|
64
|
+
networkId: number;
|
|
65
|
+
blockGasLimit: number;
|
|
66
|
+
minGasPrice: bigint;
|
|
67
|
+
automine: boolean;
|
|
68
|
+
intervalMining: IntervalMiningConfig;
|
|
69
|
+
mempoolOrder: MempoolOrder;
|
|
70
|
+
chains: HardhatNetworkChainsConfig;
|
|
71
|
+
genesisAccounts: GenesisAccount[];
|
|
72
|
+
allowUnlimitedContractSize: boolean;
|
|
73
|
+
throwOnTransactionFailures: boolean;
|
|
74
|
+
throwOnCallFailures: boolean;
|
|
75
|
+
allowBlocksWithSameTimestamp: boolean;
|
|
76
|
+
|
|
77
|
+
initialBaseFeePerGas?: number;
|
|
78
|
+
initialDate?: Date;
|
|
79
|
+
coinbase?: string;
|
|
80
|
+
experimentalHardhatNetworkMessageTraceHooks?: BoundExperimentalHardhatNetworkMessageTraceHook[];
|
|
81
|
+
forkConfig?: ForkConfig;
|
|
82
|
+
forkCachePath?: string;
|
|
83
|
+
}
|
|
84
|
+
|
|
61
85
|
export class HardhatNetworkProvider
|
|
62
86
|
extends EventEmitter
|
|
63
87
|
implements EIP1193Provider
|
|
@@ -75,28 +99,9 @@ export class HardhatNetworkProvider
|
|
|
75
99
|
private _common?: Common;
|
|
76
100
|
|
|
77
101
|
constructor(
|
|
78
|
-
private readonly
|
|
79
|
-
private readonly _networkName: string,
|
|
80
|
-
private readonly _chainId: number,
|
|
81
|
-
private readonly _networkId: number,
|
|
82
|
-
private readonly _blockGasLimit: number,
|
|
83
|
-
private readonly _initialBaseFeePerGas: number | undefined,
|
|
84
|
-
private readonly _minGasPrice: bigint,
|
|
85
|
-
private readonly _throwOnTransactionFailures: boolean,
|
|
86
|
-
private readonly _throwOnCallFailures: boolean,
|
|
87
|
-
private readonly _automine: boolean,
|
|
88
|
-
private readonly _intervalMining: IntervalMiningConfig,
|
|
89
|
-
private readonly _mempoolOrder: MempoolOrder,
|
|
90
|
-
private readonly _chains: HardhatNetworkChainsConfig,
|
|
102
|
+
private readonly _config: HardhatNetworkProviderConfig,
|
|
91
103
|
private readonly _logger: ModulesLogger,
|
|
92
|
-
private readonly
|
|
93
|
-
private readonly _artifacts?: Artifacts,
|
|
94
|
-
private readonly _allowUnlimitedContractSize = false,
|
|
95
|
-
private readonly _initialDate?: Date,
|
|
96
|
-
private readonly _experimentalHardhatNetworkMessageTraceHooks: BoundExperimentalHardhatNetworkMessageTraceHook[] = [],
|
|
97
|
-
private _forkConfig?: ForkConfig,
|
|
98
|
-
private readonly _forkCachePath?: string,
|
|
99
|
-
private readonly _coinbase = DEFAULT_COINBASE
|
|
104
|
+
private readonly _artifacts?: Artifacts
|
|
100
105
|
) {
|
|
101
106
|
super();
|
|
102
107
|
}
|
|
@@ -228,24 +233,26 @@ export class HardhatNetworkProvider
|
|
|
228
233
|
}
|
|
229
234
|
|
|
230
235
|
const config: NodeConfig = {
|
|
231
|
-
automine: this.
|
|
232
|
-
blockGasLimit: this.
|
|
233
|
-
minGasPrice: this.
|
|
234
|
-
genesisAccounts: this.
|
|
235
|
-
allowUnlimitedContractSize: this.
|
|
236
|
+
automine: this._config.automine,
|
|
237
|
+
blockGasLimit: this._config.blockGasLimit,
|
|
238
|
+
minGasPrice: this._config.minGasPrice,
|
|
239
|
+
genesisAccounts: this._config.genesisAccounts,
|
|
240
|
+
allowUnlimitedContractSize: this._config.allowUnlimitedContractSize,
|
|
236
241
|
tracingConfig: await this._makeTracingConfig(),
|
|
237
|
-
initialBaseFeePerGas: this.
|
|
238
|
-
mempoolOrder: this.
|
|
239
|
-
hardfork: this.
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
forkConfig: this._forkConfig,
|
|
242
|
+
initialBaseFeePerGas: this._config.initialBaseFeePerGas,
|
|
243
|
+
mempoolOrder: this._config.mempoolOrder,
|
|
244
|
+
hardfork: this._config.hardfork,
|
|
245
|
+
chainId: this._config.chainId,
|
|
246
|
+
networkId: this._config.networkId,
|
|
247
|
+
initialDate: this._config.initialDate,
|
|
248
|
+
forkConfig: this._config.forkConfig,
|
|
245
249
|
forkCachePath:
|
|
246
|
-
this.
|
|
247
|
-
|
|
248
|
-
|
|
250
|
+
this._config.forkConfig !== undefined
|
|
251
|
+
? this._config.forkCachePath
|
|
252
|
+
: undefined,
|
|
253
|
+
coinbase: this._config.coinbase ?? DEFAULT_COINBASE,
|
|
254
|
+
chains: this._config.chains,
|
|
255
|
+
allowBlocksWithSameTimestamp: this._config.allowBlocksWithSameTimestamp,
|
|
249
256
|
};
|
|
250
257
|
|
|
251
258
|
const [common, node] = await HardhatNode.create(config);
|
|
@@ -256,10 +263,10 @@ export class HardhatNetworkProvider
|
|
|
256
263
|
this._ethModule = new EthModule(
|
|
257
264
|
common,
|
|
258
265
|
node,
|
|
259
|
-
this.
|
|
260
|
-
this.
|
|
266
|
+
this._config.throwOnTransactionFailures,
|
|
267
|
+
this._config.throwOnCallFailures,
|
|
261
268
|
this._logger,
|
|
262
|
-
this.
|
|
269
|
+
this._config.experimentalHardhatNetworkMessageTraceHooks
|
|
263
270
|
);
|
|
264
271
|
|
|
265
272
|
const miningTimer = this._makeMiningTimer();
|
|
@@ -270,7 +277,8 @@ export class HardhatNetworkProvider
|
|
|
270
277
|
node,
|
|
271
278
|
miningTimer,
|
|
272
279
|
this._logger,
|
|
273
|
-
this.
|
|
280
|
+
this._config.allowBlocksWithSameTimestamp,
|
|
281
|
+
this._config.experimentalHardhatNetworkMessageTraceHooks
|
|
274
282
|
);
|
|
275
283
|
this._hardhatModule = new HardhatModule(
|
|
276
284
|
node,
|
|
@@ -279,7 +287,7 @@ export class HardhatNetworkProvider
|
|
|
279
287
|
this._logger.setEnabled(loggingEnabled);
|
|
280
288
|
},
|
|
281
289
|
this._logger,
|
|
282
|
-
this.
|
|
290
|
+
this._config.experimentalHardhatNetworkMessageTraceHooks
|
|
283
291
|
);
|
|
284
292
|
this._debugModule = new DebugModule(node);
|
|
285
293
|
this._personalModule = new PersonalModule(node);
|
|
@@ -320,13 +328,16 @@ export class HardhatNetworkProvider
|
|
|
320
328
|
}
|
|
321
329
|
|
|
322
330
|
private _makeMiningTimer(): MiningTimer {
|
|
323
|
-
const miningTimer = new MiningTimer(
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
331
|
+
const miningTimer = new MiningTimer(
|
|
332
|
+
this._config.intervalMining,
|
|
333
|
+
async () => {
|
|
334
|
+
try {
|
|
335
|
+
await this.request({ method: "hardhat_intervalMine" });
|
|
336
|
+
} catch (e) {
|
|
337
|
+
console.error("Unexpected error calling hardhat_intervalMine:", e);
|
|
338
|
+
}
|
|
328
339
|
}
|
|
329
|
-
|
|
340
|
+
);
|
|
330
341
|
|
|
331
342
|
miningTimer.start();
|
|
332
343
|
|
|
@@ -334,7 +345,7 @@ export class HardhatNetworkProvider
|
|
|
334
345
|
}
|
|
335
346
|
|
|
336
347
|
private async _reset(miningTimer: MiningTimer, forkConfig?: ForkConfig) {
|
|
337
|
-
this.
|
|
348
|
+
this._config.forkConfig = forkConfig;
|
|
338
349
|
if (this._node !== undefined) {
|
|
339
350
|
this._stopForwardingNodeEvents(this._node);
|
|
340
351
|
}
|
package/src/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.ts
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
InternalError,
|
|
17
17
|
InvalidArgumentsError,
|
|
18
18
|
} from "../../../core/providers/errors";
|
|
19
|
+
import { makeFakeSignature } from "../utils/makeFakeSignature";
|
|
19
20
|
|
|
20
21
|
/* eslint-disable @nomiclabs/hardhat-internal-rules/only-hardhat-error */
|
|
21
22
|
|
|
@@ -124,12 +125,14 @@ export class FakeSenderAccessListEIP2930Transaction extends AccessListEIP2930Tra
|
|
|
124
125
|
data: AccessListEIP2930TxData = {},
|
|
125
126
|
opts?: TxOptions
|
|
126
127
|
) {
|
|
128
|
+
const fakeSignature = makeFakeSignature(data, sender);
|
|
129
|
+
|
|
127
130
|
super(
|
|
128
131
|
{
|
|
129
132
|
...data,
|
|
130
133
|
v: data.v ?? 1,
|
|
131
|
-
r: data.r ??
|
|
132
|
-
s: data.s ??
|
|
134
|
+
r: data.r ?? fakeSignature.r,
|
|
135
|
+
s: data.s ?? fakeSignature.s,
|
|
133
136
|
},
|
|
134
137
|
{ ...opts, freeze: false }
|
|
135
138
|
);
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
InternalError,
|
|
16
16
|
InvalidArgumentsError,
|
|
17
17
|
} from "../../../core/providers/errors";
|
|
18
|
+
import { makeFakeSignature } from "../utils/makeFakeSignature";
|
|
18
19
|
|
|
19
20
|
/* eslint-disable @nomiclabs/hardhat-internal-rules/only-hardhat-error */
|
|
20
21
|
|
|
@@ -123,12 +124,14 @@ export class FakeSenderEIP1559Transaction extends FeeMarketEIP1559Transaction {
|
|
|
123
124
|
data: FeeMarketEIP1559TxData = {},
|
|
124
125
|
opts?: TxOptions
|
|
125
126
|
) {
|
|
127
|
+
const fakeSignature = makeFakeSignature(data, sender);
|
|
128
|
+
|
|
126
129
|
super(
|
|
127
130
|
{
|
|
128
131
|
...data,
|
|
129
132
|
v: data.v ?? 1,
|
|
130
|
-
r: data.r ??
|
|
131
|
-
s: data.s ??
|
|
133
|
+
r: data.r ?? fakeSignature.r,
|
|
134
|
+
s: data.s ?? fakeSignature.s,
|
|
132
135
|
},
|
|
133
136
|
{ ...opts, freeze: false }
|
|
134
137
|
);
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
InternalError,
|
|
8
8
|
InvalidArgumentsError,
|
|
9
9
|
} from "../../../core/providers/errors";
|
|
10
|
+
import { makeFakeSignature } from "../utils/makeFakeSignature";
|
|
10
11
|
|
|
11
12
|
/* eslint-disable @nomiclabs/hardhat-internal-rules/only-hardhat-error */
|
|
12
13
|
|
|
@@ -97,12 +98,14 @@ export class FakeSenderTransaction extends Transaction {
|
|
|
97
98
|
private readonly _sender: Address;
|
|
98
99
|
|
|
99
100
|
constructor(sender: Address, data: TxData = {}, opts?: TxOptions) {
|
|
101
|
+
const fakeSignature = makeFakeSignature(data, sender);
|
|
102
|
+
|
|
100
103
|
super(
|
|
101
104
|
{
|
|
102
105
|
...data,
|
|
103
106
|
v: data.v ?? 27,
|
|
104
|
-
r: data.r ??
|
|
105
|
-
s: data.s ??
|
|
107
|
+
r: data.r ?? fakeSignature.r,
|
|
108
|
+
s: data.s ?? fakeSignature.s,
|
|
106
109
|
},
|
|
107
110
|
{ ...opts, freeze: false }
|
|
108
111
|
);
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AccessListEIP2930Transaction,
|
|
3
|
+
FeeMarketEIP1559Transaction,
|
|
4
|
+
TxData,
|
|
5
|
+
} from "@nomicfoundation/ethereumjs-tx";
|
|
6
|
+
import { Address } from "@nomicfoundation/ethereumjs-util";
|
|
7
|
+
|
|
8
|
+
import { createNonCryptographicHashBasedIdentifier } from "../../../util/hash";
|
|
9
|
+
|
|
10
|
+
// Produces a signature with r and s values taken from a hash of the inputs.
|
|
11
|
+
export function makeFakeSignature(
|
|
12
|
+
tx: TxData | AccessListEIP2930Transaction | FeeMarketEIP1559Transaction,
|
|
13
|
+
sender: Address
|
|
14
|
+
): {
|
|
15
|
+
r: number;
|
|
16
|
+
s: number;
|
|
17
|
+
} {
|
|
18
|
+
const hashInputString = [
|
|
19
|
+
sender,
|
|
20
|
+
tx.nonce,
|
|
21
|
+
tx.gasLimit,
|
|
22
|
+
tx.value,
|
|
23
|
+
tx.to,
|
|
24
|
+
tx.data,
|
|
25
|
+
"gasPrice" in tx ? tx.gasPrice : "",
|
|
26
|
+
"chainId" in tx ? tx.chainId : "",
|
|
27
|
+
"maxPriorityFeePerGas" in tx ? tx.maxPriorityFeePerGas : "",
|
|
28
|
+
"maxFeePerGas" in tx ? tx.maxFeePerGas : "",
|
|
29
|
+
"accessList" in tx
|
|
30
|
+
? tx.accessList?.map(([buf, bufs]) =>
|
|
31
|
+
[buf, ...bufs].map((b) => b.toString("hex")).join(";")
|
|
32
|
+
)
|
|
33
|
+
: "",
|
|
34
|
+
]
|
|
35
|
+
.map((a) => a?.toString() ?? "")
|
|
36
|
+
.join(",");
|
|
37
|
+
|
|
38
|
+
const hashDigest = createNonCryptographicHashBasedIdentifier(
|
|
39
|
+
Buffer.from(hashInputString)
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
r: hashDigest.readUInt32LE(),
|
|
44
|
+
s: hashDigest.readUInt32LE(4),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -12,7 +12,7 @@ import { getCurrentTimestamp } from "./getCurrentTimestamp";
|
|
|
12
12
|
export async function putGenesisBlock(
|
|
13
13
|
blockchain: HardhatBlockchain,
|
|
14
14
|
common: Common,
|
|
15
|
-
{ initialDate, blockGasLimit }: LocalNodeConfig,
|
|
15
|
+
{ initialDate, blockGasLimit: initialBlockGasLimit }: LocalNodeConfig,
|
|
16
16
|
stateTrie: Trie,
|
|
17
17
|
hardfork: HardforkName,
|
|
18
18
|
initialMixHash: Buffer,
|
|
@@ -27,7 +27,7 @@ export async function putGenesisBlock(
|
|
|
27
27
|
|
|
28
28
|
const header: HeaderData = {
|
|
29
29
|
timestamp: `0x${initialBlockTimestamp.toString(16)}`,
|
|
30
|
-
gasLimit:
|
|
30
|
+
gasLimit: initialBlockGasLimit,
|
|
31
31
|
difficulty: isPostMerge ? 0 : 1,
|
|
32
32
|
nonce: isPostMerge ? "0x0000000000000000" : "0x0000000000000042",
|
|
33
33
|
extraData: "0x1234",
|
|
@@ -69,7 +69,10 @@ export class Resolver {
|
|
|
69
69
|
constructor(
|
|
70
70
|
private readonly _projectRoot: string,
|
|
71
71
|
private readonly _parser: Parser,
|
|
72
|
-
private readonly _readFile: (absolutePath: string) => Promise<string
|
|
72
|
+
private readonly _readFile: (absolutePath: string) => Promise<string>,
|
|
73
|
+
private readonly _transformImportName: (
|
|
74
|
+
importName: string
|
|
75
|
+
) => Promise<string>
|
|
73
76
|
) {}
|
|
74
77
|
|
|
75
78
|
/**
|
|
@@ -100,12 +103,14 @@ export class Resolver {
|
|
|
100
103
|
/**
|
|
101
104
|
* Resolves an import from an already resolved file.
|
|
102
105
|
* @param from The file were the import statement is present.
|
|
103
|
-
* @param
|
|
106
|
+
* @param importName The path in the import statement.
|
|
104
107
|
*/
|
|
105
108
|
public async resolveImport(
|
|
106
109
|
from: ResolvedFile,
|
|
107
|
-
|
|
110
|
+
importName: string
|
|
108
111
|
): Promise<ResolvedFile> {
|
|
112
|
+
const imported = await this._transformImportName(importName);
|
|
113
|
+
|
|
109
114
|
const scheme = this._getUriScheme(imported);
|
|
110
115
|
if (scheme !== undefined) {
|
|
111
116
|
throw new HardhatError(ERRORS.RESOLVER.INVALID_IMPORT_PROTOCOL, {
|
|
@@ -182,14 +187,26 @@ export class Resolver {
|
|
|
182
187
|
ERRORS.RESOLVER.LIBRARY_FILE_NOT_FOUND
|
|
183
188
|
)
|
|
184
189
|
) {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
190
|
+
if (imported !== importName) {
|
|
191
|
+
throw new HardhatError(
|
|
192
|
+
ERRORS.RESOLVER.IMPORTED_MAPPED_FILE_NOT_FOUND,
|
|
193
|
+
{
|
|
194
|
+
imported,
|
|
195
|
+
importName,
|
|
196
|
+
from: from.sourceName,
|
|
197
|
+
},
|
|
198
|
+
error
|
|
199
|
+
);
|
|
200
|
+
} else {
|
|
201
|
+
throw new HardhatError(
|
|
202
|
+
ERRORS.RESOLVER.IMPORTED_FILE_NOT_FOUND,
|
|
203
|
+
{
|
|
204
|
+
imported,
|
|
205
|
+
from: from.sourceName,
|
|
206
|
+
},
|
|
207
|
+
error
|
|
208
|
+
);
|
|
209
|
+
}
|
|
193
210
|
}
|
|
194
211
|
|
|
195
212
|
if (
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import type { Dispatcher } from "undici";
|
|
2
|
+
|
|
1
3
|
import fs from "fs";
|
|
2
4
|
import fsExtra from "fs-extra";
|
|
3
5
|
import path from "path";
|
|
4
6
|
import util from "util";
|
|
5
7
|
|
|
6
8
|
import { getHardhatVersion } from "./packageInfo";
|
|
9
|
+
import { shouldUseProxy } from "./proxy";
|
|
7
10
|
|
|
8
11
|
const TEMP_FILE_PREFIX = "tmp-";
|
|
9
12
|
|
|
@@ -27,29 +30,24 @@ export async function download(
|
|
|
27
30
|
const { getGlobalDispatcher, ProxyAgent, request } = await import("undici");
|
|
28
31
|
const streamPipeline = util.promisify(pipeline);
|
|
29
32
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (process.env.HTTP_PROXY !== undefined) {
|
|
36
|
-
return new ProxyAgent(process.env.HTTP_PROXY);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return getGlobalDispatcher();
|
|
33
|
+
let dispatcher: Dispatcher;
|
|
34
|
+
if (process.env.http_proxy !== undefined && shouldUseProxy(url)) {
|
|
35
|
+
dispatcher = new ProxyAgent(process.env.http_proxy);
|
|
36
|
+
} else {
|
|
37
|
+
dispatcher = getGlobalDispatcher();
|
|
40
38
|
}
|
|
41
39
|
|
|
42
40
|
const hardhatVersion = getHardhatVersion();
|
|
43
41
|
|
|
44
42
|
// Fetch the url
|
|
45
43
|
const response = await request(url, {
|
|
46
|
-
dispatcher
|
|
44
|
+
dispatcher,
|
|
47
45
|
headersTimeout: timeoutMillis,
|
|
48
46
|
maxRedirections: 10,
|
|
49
47
|
method: "GET",
|
|
50
48
|
headers: {
|
|
51
49
|
...extraHeaders,
|
|
52
|
-
"User-Agent": `hardhat ${hardhatVersion
|
|
50
|
+
"User-Agent": `hardhat ${hardhatVersion}`,
|
|
53
51
|
},
|
|
54
52
|
});
|
|
55
53
|
|
|
@@ -59,6 +57,9 @@ export async function download(
|
|
|
59
57
|
|
|
60
58
|
await streamPipeline(response.body, fs.createWriteStream(tmpFilePath));
|
|
61
59
|
return fsExtra.move(tmpFilePath, filePath, { overwrite: true });
|
|
60
|
+
} else {
|
|
61
|
+
// undici's response bodies must always be consumed to prevent leaks
|
|
62
|
+
await response.body.text();
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
// eslint-disable-next-line @nomiclabs/hardhat-internal-rules/only-hardhat-error
|
|
@@ -2,6 +2,8 @@ import findup from "find-up";
|
|
|
2
2
|
import fsExtra from "fs-extra";
|
|
3
3
|
import path from "path";
|
|
4
4
|
|
|
5
|
+
import { assertHardhatInvariant } from "../core/errors";
|
|
6
|
+
|
|
5
7
|
export function getPackageJsonPath(): string {
|
|
6
8
|
return findClosestPackageJson(__filename)!;
|
|
7
9
|
}
|
|
@@ -38,17 +40,14 @@ export async function getPackageJson(): Promise<PackageJson> {
|
|
|
38
40
|
return fsExtra.readJSON(path.join(root, "package.json"));
|
|
39
41
|
}
|
|
40
42
|
|
|
41
|
-
export function getHardhatVersion(): string
|
|
43
|
+
export function getHardhatVersion(): string {
|
|
42
44
|
const packageJsonPath = findClosestPackageJson(__filename);
|
|
43
45
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
assertHardhatInvariant(
|
|
47
|
+
packageJsonPath !== null,
|
|
48
|
+
"There should be a package.json in hardhat-core's root directory"
|
|
49
|
+
);
|
|
47
50
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return packageJson.version;
|
|
51
|
-
} catch {
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
51
|
+
const packageJson = fsExtra.readJsonSync(packageJsonPath);
|
|
52
|
+
return packageJson.version;
|
|
54
53
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function shouldUseProxy(url: string): boolean {
|
|
2
|
+
const { hostname } = new URL(url);
|
|
3
|
+
const noProxy = process.env.NO_PROXY;
|
|
4
|
+
|
|
5
|
+
if (hostname === "localhost" || hostname === "127.0.0.1" || noProxy === "*") {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
if (noProxy !== undefined && noProxy !== "") {
|
|
10
|
+
const noProxyList = noProxy.split(",");
|
|
11
|
+
|
|
12
|
+
if (noProxyList.includes(hostname)) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return true;
|
|
18
|
+
}
|