Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
7 changes: 4 additions & 3 deletions boa/contracts/vyper/vyper_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,9 +681,10 @@ def module_t(self):
@property
def source_map(self):
if self._source_map is None:
with anchor_settings(self.compiler_data.settings):
assembly = self.compiler_data.assembly_runtime
_, self._source_map = compile_ir.assembly_to_evm(assembly)
# cache- backwards compatibility (some caches might not have it
# until next release)
self._source_map = self.compiler_data.source_map

return self._source_map

def find_error_meta(self, computation):
Expand Down
23 changes: 22 additions & 1 deletion boa/interpret.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import vvm
import vyper
import vyper.ir.compile_ir as compile_ir
from packaging.version import Version
from vvm.utils.versioning import _pick_vyper_version, detect_version_specifier_set
from vyper.ast.parse import parse_to_ast
Expand Down Expand Up @@ -168,12 +169,32 @@ def get_compiler_data():
with anchor_settings(ret.settings):
# force compilation to happen so DiskCache will cache the compiled artifact:
_ = ret.bytecode, ret.bytecode_runtime

# workaround since CompilerData does not compute source_map
if not hasattr(ret, "source_map"):
# cache source map
ret.source_map = _compute_source_map(ret)

return ret

assert isinstance(deployer, type) or deployer is None
deployer_id = repr(deployer) # a unique str identifying the deployer class
cache_key = str((contract_name, filename, fingerprint, kwargs, deployer_id))
return _disk_cache.caching_lookup(cache_key, get_compiler_data)

ret = _disk_cache.caching_lookup(cache_key, get_compiler_data)

if not hasattr(ret, "source_map"):
# invalidate so it will be cached on the next run
_disk_cache.invalidate(cache_key)

# compute source map so it's available downstream
ret.source_map = _compute_source_map(ret)

return ret


def _compute_source_map(compiler_data: CompilerData) -> Any:
return compile_ir.assembly_to_evm(compiler_data.assembly_runtime)


def load(filename: str | Path, *args, **kwargs) -> _Contract: # type: ignore
Expand Down
17 changes: 17 additions & 0 deletions boa/test/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,23 @@
_old_init = hypothesis.core.HypothesisHandle.__init__


# variant of env.anchor() which *doesn't* roll back state if an
# exception is caught. this makes it so that the user can inspect the
# state in the case of an error, but if a test is successful, the state
# is correctly isolated.
@contextlib.contextmanager
def _test_anchor(env):
ctx = env.anchor()

try:
ctx.__enter__()
yield
except Exception: # except EvmError?
raise

ctx.__exit__(None, None, None)


def _HypothesisHandle__init__(self, *args, **kwargs):
_old_init(self, *args, **kwargs)

Expand Down
Loading