From bedd49e5a4c1e79a7d12c799e42a23a9dc449395 Mon Sep 17 00:00:00 2001 From: Daniel Schiavini Date: Thu, 10 Oct 2024 19:41:55 +0200 Subject: [PATCH 1/4] feat: have set_env return a context manager (#329) use the Open helper so that `set_env` can be used in with statements, restoring the original env when exiting the block. --- boa/__init__.py | 23 +++++++++-------------- tests/unitary/test_boa.py | 4 ++-- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/boa/__init__.py b/boa/__init__.py index 03e3fb04..9f595984 100644 --- a/boa/__init__.py +++ b/boa/__init__.py @@ -37,25 +37,20 @@ @contextlib.contextmanager def swap_env(new_env): - old_env = env - try: - set_env(new_env) + with set_env(new_env): yield - finally: - set_env(old_env) -def set_env(new_env): +def _set_env(new): global env - env = new_env + env = new + Env._singleton = new - Env._singleton = new_env - -def _env_mgr(new_env): +def set_env(new_env): global env get_env = lambda: env # noqa: E731 - return Open(get_env, set_env, new_env) + return Open(get_env, _set_env, new_env) def fork( @@ -69,7 +64,7 @@ def fork( new_env = Env() new_env.fork(url=url, block_identifier=block_identifier, deprecated=False, **kwargs) - return _env_mgr(new_env) + return set_env(new_env) def set_browser_env(address=None): @@ -77,12 +72,12 @@ def set_browser_env(address=None): # import locally because jupyter is generally not installed from boa.integrations.jupyter import BrowserEnv - return _env_mgr(BrowserEnv(address)) + return set_env(BrowserEnv(address)) def set_network_env(url): """Set the environment to use a custom network URL""" - return _env_mgr(NetworkEnv.from_url(url)) + return set_env(NetworkEnv.from_url(url)) def set_etherscan(*args, **kwargs): diff --git a/tests/unitary/test_boa.py b/tests/unitary/test_boa.py index 4d38b906..b15e1707 100644 --- a/tests/unitary/test_boa.py +++ b/tests/unitary/test_boa.py @@ -4,7 +4,7 @@ def test_env_mgr_noctx(): s = boa.env t = boa.Env() - boa._env_mgr(t) + boa.set_env(t) assert boa.env is not s assert boa.env is t @@ -13,7 +13,7 @@ def test_env_mgr_with_ctx(): s = boa.env t = boa.Env() - with boa._env_mgr(t): + with boa.set_env(t): assert boa.env is not s assert boa.env is t From a52c79c67ba0e00ceafc70f9daf730c9a57f27c9 Mon Sep 17 00:00:00 2001 From: Alberto Date: Mon, 14 Oct 2024 16:57:23 +0200 Subject: [PATCH 2/4] feat: vvm deployer forward kwargs (#332) * feat: forward kwargs to `deploy` * test: forwarding test * ci: fix linter --- boa/contracts/vvm/vvm_contract.py | 4 ++-- tests/unitary/contracts/vvm/test_vvm.py | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/boa/contracts/vvm/vvm_contract.py b/boa/contracts/vvm/vvm_contract.py index 2c028be0..6eedc2b8 100644 --- a/boa/contracts/vvm/vvm_contract.py +++ b/boa/contracts/vvm/vvm_contract.py @@ -54,7 +54,7 @@ def constructor(self): return ABIFunction(t, contract_name=self.filename) return None - def deploy(self, *args, env=None): + def deploy(self, *args, env=None, **kwargs): encoded_args = b"" if self.constructor is not None: encoded_args = self.constructor.prepare_calldata(*args) @@ -64,7 +64,7 @@ def deploy(self, *args, env=None): if env is None: env = Env.get_singleton() - address, _ = env.deploy_code(bytecode=self.bytecode + encoded_args) + address, _ = env.deploy_code(bytecode=self.bytecode + encoded_args, **kwargs) return self.at(address) diff --git a/tests/unitary/contracts/vvm/test_vvm.py b/tests/unitary/contracts/vvm/test_vvm.py index 6a2da16f..3f10106d 100644 --- a/tests/unitary/contracts/vvm/test_vvm.py +++ b/tests/unitary/contracts/vvm/test_vvm.py @@ -37,3 +37,16 @@ def test_loads_vvm(): assert contract.foo() == 42 assert contract.bar() == 43 + + +def test_forward_args_on_deploy(): + with open(mock_3_10_path) as f: + code = f.read() + + contract_vvm_deployer = boa.loads_partial(code) + + random_addy = boa.env.generate_address() + + contract = contract_vvm_deployer.deploy(43, override_address=random_addy) + + assert random_addy == contract.address From 765b848bf844069c37d5e35da0c44c4fa0c63834 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Mon, 14 Oct 2024 12:19:00 -0400 Subject: [PATCH 3/4] update version to 0.2.4 (#333) --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 73d3659f..323c21b4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "titanoboa" -version = "0.2.3" +version = "0.2.4" description = "A Vyper interpreter" #authors = [] license = { file = "LICENSE" } From 034c0aedf02ecd722e564f3838464ce33dbd70f1 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Mon, 14 Oct 2024 21:12:51 -0400 Subject: [PATCH 4/4] refactor: simplify a test (#334) --- tests/integration/network/sepolia/test_sepolia_env.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/network/sepolia/test_sepolia_env.py b/tests/integration/network/sepolia/test_sepolia_env.py index 6d101cc2..0d00e631 100644 --- a/tests/integration/network/sepolia/test_sepolia_env.py +++ b/tests/integration/network/sepolia/test_sepolia_env.py @@ -42,7 +42,7 @@ def test_verify(simple_contract): api_key = os.getenv("BLOCKSCOUT_API_KEY") blockscout = Blockscout("https://eth-sepolia.blockscout.com", api_key) with boa.set_verifier(blockscout): - result = boa.verify(simple_contract, blockscout) + result = boa.verify(simple_contract) result.wait_for_verification() assert result.is_verified()