1
1
const path = require ( 'path' ) ;
2
2
const PluginUI = require ( './resources/nomiclabs.ui' ) ;
3
3
4
- const { task, types } = require ( "hardhat/config" ) ;
4
+ const { extendConfig , task, types } = require ( "hardhat/config" ) ;
5
5
const { HardhatPluginError } = require ( "hardhat/plugins" )
6
6
const { HARDHAT_NETWORK_RESET_EVENT } = require ( "hardhat/internal/constants" ) ;
7
7
const {
@@ -21,6 +21,24 @@ let optimizerDetails;
21
21
// UI for the task flags...
22
22
const ui = new PluginUI ( ) ;
23
23
24
+ // Workaround for hardhat-viem-plugin and other provider redefinition conflicts
25
+ extendConfig ( ( config , userConfig ) => {
26
+ if ( Boolean ( process . env . SOLIDITY_COVERAGE ) ) {
27
+ const { cloneDeep } = require ( "lodash" ) ;
28
+ const { configureHardhatEVMGas } = require ( './resources/nomiclabs.utils' ) ;
29
+ const API = require ( './../lib/api' ) ;
30
+ const api = new API ( { } ) ;
31
+
32
+ let hardhatNetworkForCoverage = { } ;
33
+ if ( userConfig . networks && userConfig . networks . hardhat ) {
34
+ hardhatNetworkForCoverage = cloneDeep ( userConfig . networks . hardhat ) ;
35
+ } ;
36
+
37
+ configureHardhatEVMGas ( hardhatNetworkForCoverage , api ) ;
38
+ config . networks . hardhat = Object . assign ( config . networks . hardhat , hardhatNetworkForCoverage ) ;
39
+ }
40
+ } ) ;
41
+
24
42
subtask ( TASK_COMPILE_SOLIDITY_GET_COMPILER_INPUT ) . setAction ( async ( _ , { config } , runSuper ) => {
25
43
const solcInput = await runSuper ( ) ;
26
44
if ( measureCoverage ) {
@@ -133,6 +151,12 @@ task("coverage", "Generates a code coverage report for tests")
133
151
// Catch interrupt signals
134
152
process . on ( "SIGINT" , nomiclabsUtils . finish . bind ( null , config , api , true ) ) ;
135
153
154
+ // Warn about hardhat-viem plugin if present and config hasn't happened
155
+ if ( env . viem !== undefined && nomiclabsUtils . requiresEVMConfiguration ( env . network . config , api ) ) {
156
+ ui . report ( 'hardhat-viem' , [ ] ) ;
157
+ throw new Error ( ui . generate ( 'hardhat-viem' ) ) ;
158
+ }
159
+
136
160
// Version Info
137
161
ui . report ( 'hardhat-versions' , [ pkg . version ] ) ;
138
162
@@ -208,7 +232,13 @@ task("coverage", "Generates a code coverage report for tests")
208
232
// ==============
209
233
// Server launch
210
234
// ==============
211
- let network = await nomiclabsUtils . setupHardhatNetwork ( env , api , ui ) ;
235
+ let network
236
+
237
+ if ( nomiclabsUtils . requiresEVMConfiguration ( env . network . config , api ) ) {
238
+ network = await nomiclabsUtils . setupHardhatNetwork ( env , api , ui ) ;
239
+ } else {
240
+ network = env . network ;
241
+ }
212
242
213
243
accounts = await utils . getAccountsHardhat ( network . provider ) ;
214
244
nodeInfo = await utils . getNodeInfoHardhat ( network . provider ) ;
0 commit comments