From 49a914759990a08f9edca8837a12f4514d97ec96 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Tue, 19 Nov 2024 18:27:34 +0100 Subject: [PATCH] move update() into ctor and rename to update_address --- boa/integrations/jupyter/browser.py | 7 ++++--- tests/unitary/jupyter/test_browser.py | 3 +-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/boa/integrations/jupyter/browser.py b/boa/integrations/jupyter/browser.py index b41cb054..1f8719cd 100644 --- a/boa/integrations/jupyter/browser.py +++ b/boa/integrations/jupyter/browser.py @@ -110,6 +110,8 @@ def __init__(self, address=None, rpc=None): self._given_address = address self.address = address + self.update_address() + def send_transaction(self, tx_data: dict) -> dict: """ Implements the Account class' send_transaction method. @@ -135,7 +137,7 @@ def sign_typed_data(self, full_message: dict[str, Any]) -> str: TRANSACTION_TIMEOUT_MESSAGE, ) - def update(self): + def update_address(self): address = getattr(self._given_address, "address", self._given_address) accounts = self._rpc.fetch("eth_requestAccounts", [], ADDRESS_TIMEOUT_MESSAGE) @@ -146,7 +148,6 @@ def update(self): raise ValueError(f"Address {address} is not available in the browser") self.address = Address(address) - return self.address class BrowserEnv(NetworkEnv): @@ -162,7 +163,7 @@ def __init__(self, address=None, **kwargs): self._update_signer() def _update_signer(self): - self.signer.update() + self.signer.update_address() self.add_account(self.signer, force_eoa=True) def execute_code(self, *args, **kwargs): diff --git a/tests/unitary/jupyter/test_browser.py b/tests/unitary/jupyter/test_browser.py index 618362f8..c4c51029 100644 --- a/tests/unitary/jupyter/test_browser.py +++ b/tests/unitary/jupyter/test_browser.py @@ -160,7 +160,6 @@ def test_browser_signer_colab(colab_eval_mock, mocked_token, display_mock): address = boa.env.generate_address() colab_eval_mock.return_value = json.dumps({"data": [address]}) signer = BrowserSigner() - signer.update() assert signer.address == address colab_eval_mock.assert_called_once() (js,), _ = colab_eval_mock.call_args @@ -315,5 +314,5 @@ def test_browser_js_error(token, display_mock, mock_callback, account, mock_fork "eth_requestAccounts", error={"message": "custom message", "stack": ""} ) with pytest.raises(RPCError) as exc_info: - BrowserSigner().update() + BrowserSigner() assert str(exc_info.value) == "-1: custom message"