From 171e00b2e63a4d5d0f6cb7eeb38a72726cac154d Mon Sep 17 00:00:00 2001 From: Daniel Schiavini Date: Wed, 7 Feb 2024 16:35:46 +0100 Subject: [PATCH 1/5] Revert "swallow an error" This reverts commit db8f14a5cfc328d60fc1ac2a97e735e1fcdf168d. --- boa/vm/fork.py | 5 +---- tests/integration/network/anvil/conftest.py | 4 ++++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/boa/vm/fork.py b/boa/vm/fork.py index 1156257e..436f21c6 100644 --- a/boa/vm/fork.py +++ b/boa/vm/fork.py @@ -209,10 +209,7 @@ def try_prefetch_state(self, msg: Message): # everything is returned in hex for address, v in res.items(): - try: - address = to_canonical_address(address) - except ValueError: - return + address = to_canonical_address(address) # set account if we don't already have it if self._get_account_helper(address) is None: diff --git a/tests/integration/network/anvil/conftest.py b/tests/integration/network/anvil/conftest.py index daa386ba..133d8c0d 100644 --- a/tests/integration/network/anvil/conftest.py +++ b/tests/integration/network/anvil/conftest.py @@ -61,6 +61,10 @@ def anvil_env(free_port): except requests.exceptions.ConnectionError: time.sleep(0.1) + # Anvil ignores the tracer argument, therefore returning invalid data. + # see https://github.com/foundry-rs/foundry/issues/6882 + anvil_env._fork_try_prefetch_state = False + yield NetworkEnv(anvil_uri) finally: anvil.terminate() From 4722b4b4bf81b0a1ade890bbd97270f2d2313705 Mon Sep 17 00:00:00 2001 From: Daniel Schiavini Date: Wed, 7 Feb 2024 16:50:13 +0100 Subject: [PATCH 2/5] Fix unit tests --- boa/environment.py | 10 ++++++---- tests/integration/network/anvil/conftest.py | 4 ---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/boa/environment.py b/boa/environment.py index 5c5a0c46..3d94236d 100644 --- a/boa/environment.py +++ b/boa/environment.py @@ -399,14 +399,13 @@ def set_random_seed(self, seed=None): def get_gas_price(self): return self._gas_price or 0 - def _set_account_db_class(self, account_db_class: type): - self.vm.__class__._state_class.account_db_class = account_db_class - def _init_vm(self, reset_traces=True): self.vm = self.chain.get_vm() - self.vm.patch = VMPatcher(self.vm) + # revert any previous AccountDBFork patching + self._set_account_db_class(AccountDB) + c = type( "TitanoboaComputation", (titanoboa_computation, self.vm.state.computation_class), @@ -474,6 +473,9 @@ def fork_rpc(self, rpc=None, reset_traces=True, block_identifier="safe", **kwarg def _fork_mode(self): return self.vm.__class__._state_class.account_db_class == AccountDBFork + def _set_account_db_class(self, account_db_class: type): + self.vm.__class__._state_class.account_db_class = account_db_class + def set_gas_meter_class(self, cls: type) -> None: self.vm.state.computation_class._gas_meter_class = cls diff --git a/tests/integration/network/anvil/conftest.py b/tests/integration/network/anvil/conftest.py index 133d8c0d..daa386ba 100644 --- a/tests/integration/network/anvil/conftest.py +++ b/tests/integration/network/anvil/conftest.py @@ -61,10 +61,6 @@ def anvil_env(free_port): except requests.exceptions.ConnectionError: time.sleep(0.1) - # Anvil ignores the tracer argument, therefore returning invalid data. - # see https://github.com/foundry-rs/foundry/issues/6882 - anvil_env._fork_try_prefetch_state = False - yield NetworkEnv(anvil_uri) finally: anvil.terminate() From 6d67bda184b257bf3c79d4a19f8b74929ac4a8d8 Mon Sep 17 00:00:00 2001 From: Daniel Schiavini Date: Wed, 7 Feb 2024 16:58:08 +0100 Subject: [PATCH 3/5] pre-commit run --all-files --- boa/contracts/vyper/vyper_contract.py | 17 ++++++++++++++--- boa/interpret.py | 6 +++++- boa/network.py | 11 ++++++++++- .../network/anvil/test_network_env.py | 1 + 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/boa/contracts/vyper/vyper_contract.py b/boa/contracts/vyper/vyper_contract.py index 85532351..15c69155 100644 --- a/boa/contracts/vyper/vyper_contract.py +++ b/boa/contracts/vyper/vyper_contract.py @@ -33,8 +33,16 @@ from vyper.utils import method_id from boa import BoaError -from boa.contracts.base_evm_contract import StackTrace, _BaseEVMContract, _handle_child_trace -from boa.contracts.vyper.ast_utils import ast_map_of, get_fn_ancestor_from_node, reason_at +from boa.contracts.base_evm_contract import ( + StackTrace, + _BaseEVMContract, + _handle_child_trace, +) +from boa.contracts.vyper.ast_utils import ( + ast_map_of, + get_fn_ancestor_from_node, + reason_at, +) from boa.contracts.vyper.compiler_utils import ( _METHOD_ID_VAR, anchor_compiler_settings, @@ -42,7 +50,10 @@ generate_bytecode_for_arbitrary_stmt, generate_bytecode_for_internal_fn, ) -from boa.contracts.vyper.decoder_utils import ByteAddressableStorage, decode_vyper_object +from boa.contracts.vyper.decoder_utils import ( + ByteAddressableStorage, + decode_vyper_object, +) from boa.contracts.vyper.event import Event, RawEvent from boa.contracts.vyper.ir_executor import executor_from_ir from boa.environment import Env diff --git a/boa/interpret.py b/boa/interpret.py index 6057b77b..61d978ce 100644 --- a/boa/interpret.py +++ b/boa/interpret.py @@ -9,7 +9,11 @@ from boa.contracts.abi.abi_contract import ABIContractFactory from boa.contracts.vyper.compiler_utils import anchor_compiler_settings -from boa.contracts.vyper.vyper_contract import VyperBlueprint, VyperContract, VyperDeployer +from boa.contracts.vyper.vyper_contract import ( + VyperBlueprint, + VyperContract, + VyperDeployer, +) from boa.explorer import fetch_abi_from_etherscan from boa.util.abi import Address from boa.util.disk_cache import DiskCache diff --git a/boa/network.py b/boa/network.py index 631dcdf1..7397568e 100644 --- a/boa/network.py +++ b/boa/network.py @@ -9,7 +9,16 @@ from requests.exceptions import HTTPError from boa.environment import Env -from boa.rpc import RPC, EthereumRPC, RPCError, fixup_dict, to_bytes, to_hex, to_int, trim_dict +from boa.rpc import ( + RPC, + EthereumRPC, + RPCError, + fixup_dict, + to_bytes, + to_hex, + to_int, + trim_dict, +) from boa.util.abi import Address diff --git a/tests/integration/network/anvil/test_network_env.py b/tests/integration/network/anvil/test_network_env.py index 15418bc5..13ad59d5 100644 --- a/tests/integration/network/anvil/test_network_env.py +++ b/tests/integration/network/anvil/test_network_env.py @@ -55,4 +55,5 @@ def test_raise_exception(simple_contract, t): with boa.reverts("oh no!"): simple_contract.raise_exception(t) + # XXX: probably want to test deployment revert behavior From 89540c26a4a94616e45afb320829aa10a9269771 Mon Sep 17 00:00:00 2001 From: Daniel Schiavini Date: Wed, 7 Feb 2024 17:05:48 +0100 Subject: [PATCH 4/5] Use pre-commit to make the configuration consistent --- Makefile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 25a72548..f8835335 100644 --- a/Makefile +++ b/Makefile @@ -3,9 +3,7 @@ all: lint build lint: - black -C -t py310 boa/ tests/ - isort boa/ tests/ - flake8 boa/ tests/ + pre-commit run --all-files mypy --install-types --non-interactive --follow-imports=silent --ignore-missing-imports --implicit-optional -p boa build: From ec8021e1293b127b60db88f588299d58373c6927 Mon Sep 17 00:00:00 2001 From: Daniel Schiavini Date: Thu, 8 Feb 2024 12:18:56 +0100 Subject: [PATCH 5/5] Revert "Revert "swallow an error"" This reverts commit 171e00b2e63a4d5d0f6cb7eeb38a72726cac154d. --- boa/vm/fork.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/boa/vm/fork.py b/boa/vm/fork.py index 436f21c6..1156257e 100644 --- a/boa/vm/fork.py +++ b/boa/vm/fork.py @@ -209,7 +209,10 @@ def try_prefetch_state(self, msg: Message): # everything is returned in hex for address, v in res.items(): - address = to_canonical_address(address) + try: + address = to_canonical_address(address) + except ValueError: + return # set account if we don't already have it if self._get_account_helper(address) is None: