Skip to content

Commit

Permalink
validate all locations where geth_kwargs is an arg
Browse files Browse the repository at this point in the history
  • Loading branch information
pacrob committed May 17, 2024
1 parent f21b72c commit ee2724c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
4 changes: 2 additions & 2 deletions geth/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def get_accounts(data_dir: str, **geth_kwargs: Any) -> tuple[str, ...] | tuple[(
"""
validate_geth_kwargs(geth_kwargs)

command, proc = spawn_geth( # type: ignore[no-untyped-call]
command, proc = spawn_geth(
dict(data_dir=data_dir, suffix_args=["account", "list"], **geth_kwargs)
)
stdoutdata, stderrdata = proc.communicate()
Expand Down Expand Up @@ -122,7 +122,7 @@ def target_account() -> str:
elif not isinstance(password, bytes):
raise ValueError("Password must be either a path to a file or bytes")

command, proc = spawn_geth(geth_kwargs) # type: ignore[no-untyped-call]
command, proc = spawn_geth(geth_kwargs)

if isinstance(password, str):
stdoutdata, stderrdata = proc.communicate()
Expand Down
6 changes: 6 additions & 0 deletions geth/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import semantic_version

from geth.utils.validation import (
validate_geth_kwargs,
)

from .utils.encoding import (
force_text,
)
Expand All @@ -17,6 +21,7 @@ def get_geth_version_info_string(**geth_kwargs):
"`suffix_args` parameter"
)
geth_kwargs["suffix_args"] = ["version"]
validate_geth_kwargs(geth_kwargs)
stdoutdata, stderrdata, command, proc = geth_wrapper(**geth_kwargs)
return stdoutdata

Expand All @@ -25,6 +30,7 @@ def get_geth_version_info_string(**geth_kwargs):


def get_geth_version(**geth_kwargs):
validate_geth_kwargs(geth_kwargs)
version_info_string = get_geth_version_info_string(**geth_kwargs)
version_match = re.search(VERSION_REGEX, force_text(version_info_string, "utf8"))
if not version_match:
Expand Down
1 change: 1 addition & 0 deletions geth/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def __init__(
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
):
validate_geth_kwargs(geth_kwargs)
self.geth_kwargs = geth_kwargs
self.command = construct_popen_command(**geth_kwargs)
self.stdin = stdin
Expand Down
6 changes: 2 additions & 4 deletions geth/reset.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@


def soft_reset_chain(
allow_live: bool = False,
allow_testnet: bool = False,
**geth_kwargs: Any,
allow_live: bool = False, allow_testnet: bool = False, **geth_kwargs: Any
) -> None:
validate_geth_kwargs(geth_kwargs)
data_dir = geth_kwargs.get("data_dir")
Expand All @@ -46,7 +44,7 @@ def soft_reset_chain(
suffix_args.extend(("removedb",))
geth_kwargs.update({"suffix_args": suffix_args})

_, proc = spawn_geth(geth_kwargs) # type: ignore[no-untyped-call]
_, proc = spawn_geth(geth_kwargs)

stdoutdata, stderrdata = proc.communicate(b"y")

Expand Down
12 changes: 9 additions & 3 deletions geth/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
get_open_port,
is_port_open,
)
from geth.utils.validation import (
validate_geth_kwargs,
)

is_nice_available = functools.partial(is_executable_available, "nice")

Expand Down Expand Up @@ -305,8 +308,8 @@ def construct_popen_command( # type: ignore
return builder.command


# type ignored TODO rethink GethKwargs in a separate PR
def geth_wrapper(**geth_kwargs): # type: ignore[no-untyped-def]
validate_geth_kwargs(geth_kwargs)
stdin = geth_kwargs.pop("stdin", None)
command = construct_popen_command(**geth_kwargs) # type: ignore[no-untyped-call]

Expand Down Expand Up @@ -334,10 +337,13 @@ def geth_wrapper(**geth_kwargs): # type: ignore[no-untyped-def]
return stdoutdata, stderrdata, command, proc


# type ignored TODO rethink GethKwargs in a separate PR
def spawn_geth( # type: ignore[no-untyped-def]
geth_kwargs, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE
geth_kwargs: dict[str, Any],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
):
validate_geth_kwargs(geth_kwargs)
command = construct_popen_command(**geth_kwargs) # type: ignore[no-untyped-call]

proc = subprocess.Popen(
Expand Down

0 comments on commit ee2724c

Please sign in to comment.