Skip to content

Commit

Permalink
Use a custom block ID for test stability
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSchiavini committed May 23, 2024
1 parent ffcd91d commit 3d25cab
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
8 changes: 4 additions & 4 deletions boa_zksync/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ def set_zksync_test_env():
boa.set_deployer_class(ZksyncDeployer)


def set_zksync_fork(url):
def set_zksync_fork(url, *args, **kwargs):
env = ZksyncEnv.from_url(url)
env.fork()
env.fork(*args, **kwargs)
boa.set_env(env)
boa.set_deployer_class(ZksyncDeployer)


def set_zksync_browser_env(address=None):
def set_zksync_browser_env(*args, **kwargs):
# import locally because jupyter is generally not installed
from boa_zksync.browser import ZksyncBrowserEnv

boa.set_env(ZksyncBrowserEnv(address))
boa.set_env(ZksyncBrowserEnv(*args, **kwargs))
boa.set_deployer_class(ZksyncDeployer)


Expand Down
12 changes: 8 additions & 4 deletions boa_zksync/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,18 @@ class EraTestNode(EthereumRPC):
),
]

def __init__(self, rpc: Optional[EthereumRPC] = None, block_identifier="safe"):
self.inner_rpc = rpc
def __init__(
self, inner_rpc: Optional[EthereumRPC] = None, block_identifier="safe"
):
self.inner_rpc = inner_rpc

port = find_free_port()
fork_at = (
["--fork-at", block_identifier] if isinstance(block_identifier, int) else []
["--fork-at", f"{block_identifier}"]
if isinstance(block_identifier, int)
else []
)
fork_args = ["fork", rpc._rpc_url] + fork_at if rpc else ["run"]
fork_args = ["fork", inner_rpc._rpc_url] + fork_at if inner_rpc else ["run"]
self._test_node = Popen(
["era_test_node", "--port", f"{port}"] + fork_args,
stdout=sys.stdout,
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)
boa_zksync.set_zksync_fork(fork_url, block_identifier=1689570)
boa.env.add_account(account, force_eoa=True)
yield boa.env
boa.set_env(old_env)
Expand Down

0 comments on commit 3d25cab

Please sign in to comment.