Skip to content

Commit

Permalink
Honor WEB3_PROVIDER_URI for geth auto dev connection (#2023)
Browse files Browse the repository at this point in the history
  • Loading branch information
kclowes authored Jun 14, 2021
1 parent d7ae2df commit f4add46
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions newsfragments/2023.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Have the geth dev IPC auto connection check for the ``WEB3_PROVIDER_URI`` environment variable.
10 changes: 10 additions & 0 deletions tests/core/providers/test_auto_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
from web3.providers.auto import (
load_provider_from_environment,
)
from web3.providers.ipc import (
get_dev_ipc_path,
)

# Ugly hack to import infura now that API KEY is required
os.environ['WEB3_INFURA_API_KEY'] = 'test'
Expand Down Expand Up @@ -51,6 +54,13 @@ def test_load_provider_from_env(monkeypatch, uri, expected_type, expected_attrs)
assert getattr(provider, attr) == val


def test_get_dev_ipc_path(monkeypatch, tmp_path):
uri = str(tmp_path)
monkeypatch.setenv('WEB3_PROVIDER_URI', uri)
path = get_dev_ipc_path()
assert path == uri


@pytest.mark.parametrize('environ_name', ['WEB3_INFURA_API_KEY', 'WEB3_INFURA_PROJECT_ID'])
def test_web3_auto_infura_empty_key(monkeypatch, caplog, environ_name):
monkeypatch.setenv('WEB3_INFURA_SCHEME', 'https')
Expand Down
6 changes: 5 additions & 1 deletion web3/providers/ipc.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@ def get_default_ipc_path() -> str: # type: ignore

# type ignored b/c missing return statement is by design here
def get_dev_ipc_path() -> str: # type: ignore
if sys.platform == 'darwin':
if os.environ.get('WEB3_PROVIDER_URI', ''):
ipc_path = os.environ.get('WEB3_PROVIDER_URI')
if os.path.exists(ipc_path):
return ipc_path
elif sys.platform == 'darwin':
tmpdir = os.environ.get('TMPDIR', '')
ipc_path = os.path.expanduser(os.path.join(
tmpdir,
Expand Down

0 comments on commit f4add46

Please sign in to comment.