@@ -35,17 +35,6 @@ class Hardhat(AbstractPlatform):
35
35
PROJECT_URL = "https://github.com/nomiclabs/hardhat"
36
36
TYPE = Type .HARDHAT
37
37
38
- def __init__ (self , target : str , ** kwargs : str ):
39
- super ().__init__ (target , ** kwargs )
40
-
41
- self ._ignore_compile = kwargs .get ("hardhat_ignore_compile" , False ) or kwargs .get (
42
- "ignore_compile" , False
43
- )
44
-
45
- self ._base_cmd = ["hardhat" ]
46
- if not kwargs .get ("npx_disable" , False ):
47
- self ._base_cmd = ["npx" ] + self ._base_cmd
48
-
49
38
# pylint: disable=too-many-locals,too-many-statements
50
39
def compile (self , crytic_compile : "CryticCompile" , ** kwargs : str ) -> None :
51
40
"""Run the compilation
@@ -59,7 +48,15 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
59
48
InvalidCompilation: If hardhat failed to run
60
49
"""
61
50
62
- detected_paths = self ._get_hardhat_paths (kwargs )
51
+ hardhat_ignore_compile = kwargs .get ("hardhat_ignore_compile" , False ) or kwargs .get (
52
+ "ignore_compile" , False
53
+ )
54
+
55
+ base_cmd = ["hardhat" ]
56
+ if not kwargs .get ("npx_disable" , False ):
57
+ base_cmd = ["npx" ] + base_cmd
58
+
59
+ detected_paths = self ._get_hardhat_paths (base_cmd , kwargs )
63
60
64
61
build_directory = Path (
65
62
self ._target ,
@@ -69,8 +66,8 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
69
66
70
67
hardhat_working_dir = Path (self ._target , detected_paths ["root" ])
71
68
72
- if not self . _ignore_compile :
73
- cmd = self . _base_cmd + ["compile" , "--force" ]
69
+ if not hardhat_ignore_compile :
70
+ cmd = base_cmd + ["compile" , "--force" ]
74
71
75
72
LOGGER .info (
76
73
"'%s' running" ,
@@ -246,11 +243,14 @@ def _guessed_tests(self) -> List[str]:
246
243
"""
247
244
return ["hardhat test" ]
248
245
249
- def _get_hardhat_paths (self , args : Dict [str , str ]) -> Dict [str , Union [Path , str ]]:
246
+ def _get_hardhat_paths (
247
+ self , base_cmd : List [str ], args : Dict [str , str ]
248
+ ) -> Dict [str , Union [Path , str ]]:
250
249
"""Obtain hardhat configuration paths, defaulting to the
251
250
standard config if needed.
252
251
253
252
Args:
253
+ base_cmd ([str]): hardhat command
254
254
args (Dict[str, str]): crytic-compile options that may affect paths
255
255
256
256
Returns:
@@ -277,7 +277,7 @@ def _get_hardhat_paths(self, args: Dict[str, str]) -> Dict[str, Union[Path, str]
277
277
override_paths ["root" ] = Path (target_path , args ["hardhat_working_dir" ])
278
278
279
279
print_paths = "console.log(JSON.stringify(config.paths))"
280
- config_str = self ._run_hardhat_console (print_paths )
280
+ config_str = self ._run_hardhat_console (base_cmd , print_paths )
281
281
282
282
try :
283
283
paths = json .loads (config_str or "{}" )
@@ -286,22 +286,23 @@ def _get_hardhat_paths(self, args: Dict[str, str]) -> Dict[str, Union[Path, str]
286
286
LOGGER .info ("Problem deserializing hardhat configuration: %s" , e )
287
287
return {** default_paths , ** override_paths }
288
288
289
- def _run_hardhat_console (self , command : str ) -> Optional [str ]:
289
+ def _run_hardhat_console (self , base_cmd : List [ str ], command : str ) -> Optional [str ]:
290
290
"""Run a JS command in the hardhat console
291
291
292
292
Args:
293
+ base_cmd ([str]): hardhat command
293
294
command (str): console command to run
294
295
295
296
Returns:
296
297
Optional[str]: command output if execution succeeds
297
298
"""
298
299
with subprocess .Popen (
299
- self . _base_cmd + ["console" , "--no-compile" ],
300
+ base_cmd + ["console" , "--no-compile" ],
300
301
stdin = subprocess .PIPE ,
301
302
stdout = subprocess .PIPE ,
302
303
stderr = subprocess .PIPE ,
303
304
cwd = self ._target ,
304
- executable = shutil .which (self . _base_cmd [0 ]),
305
+ executable = shutil .which (base_cmd [0 ]),
305
306
) as process :
306
307
stdout_bytes , stderr_bytes = process .communicate (command .encode ("utf-8" ))
307
308
stdout , stderr = (
0 commit comments