11const path = require ( 'path' ) ;
22const PluginUI = require ( './resources/nomiclabs.ui' ) ;
33
4- const { task, types } = require ( "hardhat/config" ) ;
4+ const { extendConfig , task, types } = require ( "hardhat/config" ) ;
55const { HardhatPluginError } = require ( "hardhat/plugins" )
66const { HARDHAT_NETWORK_RESET_EVENT } = require ( "hardhat/internal/constants" ) ;
77const {
@@ -21,6 +21,24 @@ let optimizerDetails;
2121// UI for the task flags...
2222const ui = new PluginUI ( ) ;
2323
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+
2442subtask ( TASK_COMPILE_SOLIDITY_GET_COMPILER_INPUT ) . setAction ( async ( _ , { config } , runSuper ) => {
2543 const solcInput = await runSuper ( ) ;
2644 if ( measureCoverage ) {
@@ -133,6 +151,12 @@ task("coverage", "Generates a code coverage report for tests")
133151 // Catch interrupt signals
134152 process . on ( "SIGINT" , nomiclabsUtils . finish . bind ( null , config , api , true ) ) ;
135153
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+
136160 // Version Info
137161 ui . report ( 'hardhat-versions' , [ pkg . version ] ) ;
138162
@@ -208,7 +232,13 @@ task("coverage", "Generates a code coverage report for tests")
208232 // ==============
209233 // Server launch
210234 // ==============
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+ }
212242
213243 accounts = await utils . getAccountsHardhat ( network . provider ) ;
214244 nodeInfo = await utils . getNodeInfoHardhat ( network . provider ) ;
0 commit comments