Skip to content

Commit 12c9d83

Browse files
committed
bugfix: Fix gethdev ipc path for auto.gethdev
1 parent a35efbc commit 12c9d83

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

newsfragments/3576.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a bug related to building the ipc path for connecting to a geth ``--dev`` instance via ``web3.auto.gethdev``.

tests/core/providers/test_auto_provider.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,19 @@ def test_load_provider_from_env(monkeypatch, uri, expected_type, expected_attrs)
5555

5656

5757
def test_get_dev_ipc_path(monkeypatch, tmp_path):
58-
uri = str(tmp_path)
58+
# test default path
59+
path = get_dev_ipc_path()
60+
assert path == "/tmp/geth.ipc"
61+
62+
uri = str(tmp_path) + "/geth.ipc"
63+
64+
# test setting the "TMPDIR" environment variable
65+
monkeypatch.setenv("TMPDIR", str(tmp_path))
66+
path = get_dev_ipc_path()
67+
assert path == uri
68+
monkeypatch.delenv("TMPDIR") # reset
69+
70+
# test with WEB3_PROVIDER_URI set
5971
monkeypatch.setenv("WEB3_PROVIDER_URI", uri)
6072
path = get_dev_ipc_path()
6173
assert path == uri

tests/core/providers/test_ipc_provider.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def test_get_default_ipc_path(platform, expected_result, expected_error):
9797
"platform, expected_result, expected_error",
9898
[
9999
("darwin", "/var/path/to/tmp/T/geth.ipc", None),
100-
("linux", "/tmp/geth.ipc", None),
100+
("linux", "/var/path/to/tmp/T/geth.ipc", None),
101101
("freebsd", "/tmp/geth.ipc", None),
102102
("win32", r"\\.\pipe\geth.ipc", None),
103103
(
@@ -119,7 +119,7 @@ def test_get_dev_ipc_path_(provider_env_uri, platform, expected_result, expected
119119
os.environ,
120120
{
121121
"TMPDIR": "/var/path/to/tmp/T/",
122-
"WEB3_PROVIDER_URI": provider_env_uri,
122+
"WEB3_PROVIDER_URI": provider_env_uri or "",
123123
},
124124
):
125125
if provider_env_uri:
@@ -130,7 +130,7 @@ def test_get_dev_ipc_path_(provider_env_uri, platform, expected_result, expected
130130
):
131131
get_dev_ipc_path()
132132
else:
133-
assert get_dev_ipc_path().endswith(expected_result)
133+
assert get_dev_ipc_path() == expected_result
134134

135135

136136
@pytest.fixture

web3/providers/ipc.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,15 @@ def get_default_ipc_path() -> str:
116116

117117

118118
def get_dev_ipc_path() -> str:
119-
if os.environ.get("WEB3_PROVIDER_URI", ""):
120-
return os.environ.get("WEB3_PROVIDER_URI")
119+
web3_provider_uri = os.environ.get("WEB3_PROVIDER_URI", "")
120+
if web3_provider_uri and "geth.ipc" in web3_provider_uri:
121+
return web3_provider_uri
121122

122-
elif sys.platform == "darwin":
123-
tmpdir = os.environ.get("TMPDIR", "")
123+
elif sys.platform == "darwin" or sys.platform.startswith("linux"):
124+
tmpdir = os.environ.get("TMPDIR", "/tmp")
124125
return os.path.expanduser(os.path.join(tmpdir, "geth.ipc"))
125126

126-
elif sys.platform.startswith("linux") or sys.platform.startswith("freebsd"):
127+
elif sys.platform.endswith("freebsd"):
127128
return os.path.expanduser(os.path.join("/tmp", "geth.ipc"))
128129

129130
elif sys.platform == "win32":

0 commit comments

Comments
 (0)