Skip to content

Commit ab436a3

Browse files
committed
hardhat: revert changes
1 parent 81ad88c commit ab436a3

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

crytic_compile/platform/hardhat.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,6 @@ class Hardhat(AbstractPlatform):
3535
PROJECT_URL = "https://github.com/nomiclabs/hardhat"
3636
TYPE = Type.HARDHAT
3737

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-
4938
# pylint: disable=too-many-locals,too-many-statements
5039
def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
5140
"""Run the compilation
@@ -59,7 +48,15 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
5948
InvalidCompilation: If hardhat failed to run
6049
"""
6150

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)
6360

6461
build_directory = Path(
6562
self._target,
@@ -69,8 +66,8 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
6966

7067
hardhat_working_dir = Path(self._target, detected_paths["root"])
7168

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"]
7471

7572
LOGGER.info(
7673
"'%s' running",
@@ -246,11 +243,14 @@ def _guessed_tests(self) -> List[str]:
246243
"""
247244
return ["hardhat test"]
248245

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]]:
250249
"""Obtain hardhat configuration paths, defaulting to the
251250
standard config if needed.
252251
253252
Args:
253+
base_cmd ([str]): hardhat command
254254
args (Dict[str, str]): crytic-compile options that may affect paths
255255
256256
Returns:
@@ -277,7 +277,7 @@ def _get_hardhat_paths(self, args: Dict[str, str]) -> Dict[str, Union[Path, str]
277277
override_paths["root"] = Path(target_path, args["hardhat_working_dir"])
278278

279279
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)
281281

282282
try:
283283
paths = json.loads(config_str or "{}")
@@ -286,22 +286,23 @@ def _get_hardhat_paths(self, args: Dict[str, str]) -> Dict[str, Union[Path, str]
286286
LOGGER.info("Problem deserializing hardhat configuration: %s", e)
287287
return {**default_paths, **override_paths}
288288

289-
def _run_hardhat_console(self, command: str) -> Optional[str]:
289+
def _run_hardhat_console(self, base_cmd: List[str], command: str) -> Optional[str]:
290290
"""Run a JS command in the hardhat console
291291
292292
Args:
293+
base_cmd ([str]): hardhat command
293294
command (str): console command to run
294295
295296
Returns:
296297
Optional[str]: command output if execution succeeds
297298
"""
298299
with subprocess.Popen(
299-
self._base_cmd + ["console", "--no-compile"],
300+
base_cmd + ["console", "--no-compile"],
300301
stdin=subprocess.PIPE,
301302
stdout=subprocess.PIPE,
302303
stderr=subprocess.PIPE,
303304
cwd=self._target,
304-
executable=shutil.which(self._base_cmd[0]),
305+
executable=shutil.which(base_cmd[0]),
305306
) as process:
306307
stdout_bytes, stderr_bytes = process.communicate(command.encode("utf-8"))
307308
stdout, stderr = (

0 commit comments

Comments
 (0)