Skip to content

Commit

Permalink
Fix reset_fork after sending tx
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSchiavini committed Jun 4, 2024
1 parent 1f79f18 commit ff09ced
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 12 deletions.
6 changes: 3 additions & 3 deletions boa_zksync/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def vm(self):

def _reset_fork(self, block_identifier="latest"):
self._vm = None
if isinstance(self._rpc, EraTestNode) and (inner_rpc := self._rpc.inner_rpc):
if block_identifier == "latest" and isinstance(self._rpc, EraTestNode) and (inner_rpc := self._rpc.inner_rpc):
del self._rpc # close the old rpc
self._rpc = inner_rpc

Expand All @@ -80,7 +80,7 @@ def fork_rpc(
if reset_traces:
self.sha3_trace: dict = {}
self.sstore_trace: dict = {}
self._rpc = EraTestNode(rpc, block_identifier)
self._rpc = EraTestNode(rpc, block_identifier, **kwargs)

def register_contract(self, address, obj):
addr = Address(address)
Expand Down Expand Up @@ -132,7 +132,7 @@ def execute_code(
args, bytes.fromhex(output.removeprefix("0x"))
)

if is_modifying:
if is_modifying or True:
try:
receipt, trace = self._send_txn(**args.as_tx_params())
self.last_receipt = receipt
Expand Down
7 changes: 2 additions & 5 deletions boa_zksync/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,8 @@ def __init__(
else []
)
command = ["fork", inner_rpc._rpc_url] + fork_at if inner_rpc else ["run"]
self._test_node = Popen(
["era_test_node", "--port", f"{port}"] + list(node_args) + command,
stdout=sys.stdout,
stderr=sys.stderr,
)
args = ["era_test_node"] + list(node_args) + ["--port", f"{port}"] + command
self._test_node = Popen(args, stdout=sys.stdout, stderr=sys.stderr)

super().__init__(f"http://localhost:{port}")
logging.info(f"Started fork node at {self._rpc_url}")
Expand Down
7 changes: 4 additions & 3 deletions boa_zksync/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
from eth_account.datastructures import SignedMessage
from eth_account.messages import encode_typed_data
from rlp.sedes import BigEndianInt, Binary, List
from vyper.compiler import CompilerData
from vyper.compiler import CompilerData, Settings
from vyper.compiler.settings import OptimizationLevel

_EIP712_TYPE = bytes.fromhex("71")
_EIP712_TYPES_SPEC = {
Expand Down Expand Up @@ -174,11 +175,11 @@ def global_ctx(self):

@cached_property
def vyper(self) -> CompilerData:
return compiler_data(self.source_code, self.contract_name, VyperDeployer)
return compiler_data(self.source_code, self.contract_name, VyperDeployer, settings=self.settings)

@cached_property
def settings(self):
return self.vyper.settings
return Settings(optimize=OptimizationLevel.NONE)


@dataclass
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def zksync_env(account):
def zksync_sepolia_fork(account):
old_env = boa.env
fork_url = os.getenv("FORK_URL", "https://sepolia.era.zksync.dev")
boa_zksync.set_zksync_fork(fork_url, block_identifier=1689570)
boa_zksync.set_zksync_fork(fork_url, block_identifier=1689570, node_args=("--show-calls", "all", "--show-outputs"))
boa.env.add_account(account, force_eoa=True)
yield boa.env
boa.set_env(old_env)
Expand Down
26 changes: 26 additions & 0 deletions tests/test_fork.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import boa
import pytest
from boa.rpc import EthereumRPC

from boa_zksync import EraTestNode
from boa_zksync.environment import ZERO_ADDRESS


def test_dummy_contract(zksync_sepolia_fork):
Expand All @@ -12,3 +17,24 @@ def foo() -> bool:
assert c.foo() is True
c = boa.loads(code)
assert c.foo() is True


@pytest.mark.ignore_isolation
def test_contract_storage(zksync_sepolia_fork):
code = """
implementation: public(address)
@external
def set_implementation(_implementation: address):
self.implementation = _implementation
"""
c = boa.loads(code)
assert c.implementation() == ZERO_ADDRESS
boa.env.set_balance(boa.env.eoa, 10 ** 20)
c.set_implementation(c.address)
assert c.implementation() == c.address


def test_fork_rpc(zksync_sepolia_fork):
assert isinstance(boa.env._rpc, EraTestNode)
assert isinstance(boa.env._rpc.inner_rpc, EthereumRPC)

0 comments on commit ff09ced

Please sign in to comment.