Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unit tests #137

Merged
merged 5 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
charles-cooper marked this conversation as resolved.
Show resolved Hide resolved
mypy --install-types --non-interactive --follow-imports=silent --ignore-missing-imports --implicit-optional -p boa

build:
Expand Down
17 changes: 14 additions & 3 deletions boa/contracts/vyper/vyper_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,27 @@
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,
compile_vyper_function,
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
Expand Down
10 changes: 6 additions & 4 deletions boa/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change got lost and broke anvil, so the error did not need to be swallowed


c = type(
"TitanoboaComputation",
(titanoboa_computation, self.vm.state.computation_class),
Expand Down Expand Up @@ -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):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just moved it close to _fork_mode

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

Expand Down
6 changes: 5 additions & 1 deletion boa/interpret.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion boa/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
5 changes: 1 addition & 4 deletions boa/vm/fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions tests/integration/network/anvil/test_network_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading