Skip to content

Commit

Permalink
Self-review
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSchiavini committed Apr 15, 2024
1 parent ba65161 commit 913840e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
5 changes: 3 additions & 2 deletions boa/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def fork_rpc(self, rpc: RPC, reset_traces=True, block_identifier="safe", **kwarg
self.sha3_trace = {}
self.sstore_trace = {}

self.evm.fork_rpc(rpc, block_identifier=block_identifier, **kwargs)
self.evm.fork_rpc(rpc, block_identifier, **kwargs)

def get_gas_meter_class(self):
return self.evm.get_gas_meter_class()
Expand Down Expand Up @@ -151,7 +151,8 @@ def reset_gas_used(self):
# to the snapshot on exiting the with statement
@contextlib.contextmanager
def anchor(self):
return self.evm.anchor()
with self.evm.anchor():
yield

@contextlib.contextmanager
def sender(self, address):
Expand Down
13 changes: 7 additions & 6 deletions boa/vm/py_evm.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,9 @@ def __init__(self, env, fast_mode_enabled=False, fork_try_prefetch_state=False):
self.env = env
self._fast_mode_enabled = fast_mode_enabled
self._fork_try_prefetch_state = fork_try_prefetch_state
self._init_vm(env, AccountDB)
self._init_vm()

def _init_vm(self, env, account_db_class: Type[AccountDB]):
def _init_vm(self, account_db_class=AccountDB):
self.vm = self.chain.get_vm()
self.vm.__class__._state_class.account_db_class = account_db_class

Expand All @@ -385,7 +385,7 @@ def _init_vm(self, env, account_db_class: Type[AccountDB]):
c: Type[titanoboa_computation] = type(
"TitanoboaComputation",
(titanoboa_computation, self.vm.state.computation_class),
{"env": env},
{"env": self.env},
)

if self._fast_mode_enabled:
Expand All @@ -394,8 +394,8 @@ def _init_vm(self, env, account_db_class: Type[AccountDB]):
self.vm.state.computation_class = c

# patch in tracing opcodes
c.opcodes[0x20] = Sha3PreimageTracer(c.opcodes[0x20], env)
c.opcodes[0x55] = SstoreTracer(c.opcodes[0x55], env)
c.opcodes[0x20] = Sha3PreimageTracer(c.opcodes[0x20], self.env)
c.opcodes[0x55] = SstoreTracer(c.opcodes[0x55], self.env)

def _trace_sstore(self, account, slot):
self.sstore_trace.setdefault(account, set())
Expand All @@ -412,7 +412,7 @@ def enable_fast_mode(self, flag: bool = True):

def fork_rpc(self, rpc: RPC, block_identifier: str, **kwargs):
account_db_class = AccountDBFork.class_from_rpc(rpc, block_identifier, **kwargs)
self._init_vm(self.env, account_db_class)
self._init_vm(account_db_class)
block_info = self.vm.state._account_db._block_info

self.vm.patch.timestamp = int(block_info["timestamp"], 16)
Expand Down Expand Up @@ -453,6 +453,7 @@ def reset_access_counters(self):
def snapshot(self) -> Any:
return self.vm.state.snapshot()

@contextlib.contextmanager
def anchor(self):
snapshot_id = self.snapshot()
try:
Expand Down
1 change: 0 additions & 1 deletion tests/unitary/test_blueprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def test_create2_address():

child_contract_address = factory.create_child(blueprint.address, salt)

# TODO: make a util function on boa.env to get code
blueprint_bytecode = boa.env.get_code(blueprint.address)
assert child_contract_address == get_create2_address(
blueprint_bytecode, factory.address, salt
Expand Down
2 changes: 1 addition & 1 deletion tests/unitary/test_deploy_value.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import eth.exceptions
import pytest

import boa
Expand All @@ -21,6 +20,7 @@ def test_deploy_with_endowment():
assert boa.env.get_balance(boa.env.eoa) == 0
assert boa.env.get_balance(c.address) == 1000


# try to call ctor with skip_init=True - must raise
def test_deploy_with_endowment_must_init():
deployer = boa.loads_partial(fund_me_source)
Expand Down

0 comments on commit 913840e

Please sign in to comment.