Skip to content

Commit

Permalink
Refactor environment to separate it from pyevm
Browse files Browse the repository at this point in the history
Preparation to handle vyperlang#104
  • Loading branch information
DanielSchiavini committed Feb 7, 2024
1 parent 3d977d3 commit 81258f8
Show file tree
Hide file tree
Showing 14 changed files with 662 additions and 536 deletions.
3 changes: 2 additions & 1 deletion boa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from boa.contracts.base_evm_contract import BoaError
from boa.contracts.vyper.vyper_contract import check_boa_error_matches
from boa.debugger import BoaDebug
from boa.environment import Env, enable_pyevm_verbose_logging, patch_opcode
from boa.environment import Env
from boa.interpret import (
from_etherscan,
load,
Expand All @@ -16,6 +16,7 @@
)
from boa.precompile import precompile
from boa.test.strategies import fuzz
from boa.vm.py_evm import enable_pyevm_verbose_logging, patch_opcode

# turn off tracebacks if we are in repl
# https://stackoverflow.com/a/64523765
Expand Down
5 changes: 2 additions & 3 deletions boa/contracts/abi/abi_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
_handle_child_trace,
)
from boa.contracts.utils import decode_addresses, encode_addresses
from boa.environment import Address
from boa.util.abi import ABIError, abi_decode, abi_encode, is_abi_encodable
from boa.util.abi import ABIError, Address, abi_decode, abi_encode, is_abi_encodable


class ABIFunction:
Expand Down Expand Up @@ -199,7 +198,7 @@ def __init__(
super().__init__(env, filename=filename, address=address)
self._name = name
self._functions = functions
self._bytecode = self.env.vm.state.get_code(address.canonical_address)
self._bytecode = self.env.evm.get_code(address)
if not self._bytecode:
warn(
f"Requested {self} but there is no bytecode at that address!",
Expand Down
3 changes: 2 additions & 1 deletion boa/contracts/base_evm_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

from eth.abc import ComputationAPI

from boa.environment import Address, Env
from boa.environment import Env
from boa.util.abi import Address
from boa.util.exceptions import strip_internal_frames


Expand Down
2 changes: 1 addition & 1 deletion boa/contracts/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any

from boa.environment import Address
from boa.util.abi import Address


def encode_addresses(values: list) -> list:
Expand Down
15 changes: 7 additions & 8 deletions boa/contracts/vyper/vyper_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@
)
from boa.contracts.vyper.event import Event, RawEvent
from boa.contracts.vyper.ir_executor import executor_from_ir
from boa.environment import Address, Env
from boa.environment import Env
from boa.profiling import LineProfile, cache_gas_used_for_computation
from boa.util.abi import abi_decode, abi_encode
from boa.util.abi import Address, abi_decode, abi_encode
from boa.util.lrudict import lrudict
from boa.vm.gas_meters import ProfilingGasMeter
from boa.vm.utils import to_bytes, to_int
Expand Down Expand Up @@ -106,8 +106,7 @@ def at(self, address: Any) -> "VyperContract":
skip_initcode=True,
filename=self.filename,
)
vm = ret.env.vm
bytecode = vm.state.get_code(address.canonical_address)
bytecode = ret.env.evm.get_code(address)

ret._set_bytecode(bytecode)

Expand Down Expand Up @@ -349,7 +348,7 @@ class StorageVar:
def __init__(self, contract, slot, typ):
self.contract = contract
self.addr = self.contract._address.canonical_address
self.accountdb = contract.env.vm.state._account_db
self.accountdb = contract.env.evm.get_account_db()
self.slot = slot
self.typ = typ

Expand All @@ -370,8 +369,8 @@ def _dealias(self, maybe_address):
def get(self, truncate_limit=None):
if isinstance(self.typ, HashMapT):
ret = {}
for k in self.contract.env.sstore_trace.get(self.addr, {}):
path = unwrap_storage_key(self.contract.env.sha3_trace, k)
for k in self.contract.env.evm.sstore_trace.get(self.addr, {}):
path = unwrap_storage_key(self.contract.env.evm.sha3_trace, k)
if to_int(path[0]) != self.slot:
continue

Expand Down Expand Up @@ -687,7 +686,7 @@ def marshal_to_python(self, computation, vyper_typ):
self.handle_error(computation)

# cache gas used for call if profiling is enabled
gas_meter = self.env.vm.state.computation_class._gas_meter_class
gas_meter = self.env.get_gas_meter_class()
if gas_meter == ProfilingGasMeter:
cache_gas_used_for_computation(self, computation)

Expand Down
Loading

0 comments on commit 81258f8

Please sign in to comment.