Skip to content

Commit

Permalink
feat: add nickname to Env (#266)
Browse files Browse the repository at this point in the history
I added the nickname attribute to the Env and NetworkEnv objects.

* added nicknames to envs
* fix url masking

---------

Co-authored-by: Charles Cooper <[email protected]>
  • Loading branch information
PatrickAlphaC and charles-cooper authored Aug 28, 2024
1 parent 3667459 commit 8d1e36d
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions boa/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def __init__(self, fork_try_prefetch_state=False, fast_mode_enabled=False):

self._gas_tracker = 0

self.nickname = "pyevm"

self.evm = PyEVM(self, fast_mode_enabled, fork_try_prefetch_state)

def set_random_seed(self, seed=None):
Expand Down
3 changes: 3 additions & 0 deletions boa/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class NetworkEnv(Env):
def __init__(
self,
rpc: str | RPC,
nickname: str = None,
accounts: dict[str, Account] = None,
fork_try_prefetch_state=True,
**kwargs,
Expand All @@ -164,6 +165,8 @@ def __init__(

self._rpc: RPC = rpc

self.nickname = nickname or rpc.name

self._reset_fork()

self._accounts = accounts or {}
Expand Down
5 changes: 4 additions & 1 deletion boa/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ def name(self):
# url stripped out (content which you might not want to end up
# in logs)
parse_result = urlparse(self._rpc_url)
return f"{parse_result.scheme}://{parse_result.netloc} (URL partially masked for privacy)"
partial_ret = f"{parse_result.scheme}://{parse_result.netloc}"
if partial_ret != self._rpc_url:
return f"{partial_ret} (URL partially masked for privacy)"
return self._rpc_url

def fetch(self, method, params):
# the obvious thing to do here is dispatch into fetch_multi.
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions tests/integration/network/anvil/test_network_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ def test_env_type():
assert isinstance(boa.env, NetworkEnv)


def test_network_env_nickname(free_port):
assert boa.env.nickname == f"http://localhost:{free_port}"


def test_total_supply(simple_contract):
assert simple_contract.totalSupply() == STARTING_SUPPLY

Expand Down
12 changes: 12 additions & 0 deletions tests/unitary/test_env_defaults.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import pytest

from boa import Env


@pytest.fixture
def env():
return Env()


def test_env_nickname(env):
assert env.nickname == "pyevm"

0 comments on commit 8d1e36d

Please sign in to comment.