-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Careful with set_balance in networks
- Loading branch information
1 parent
cf33614
commit f1d0d7b
Showing
8 changed files
with
78 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from typing import Any | ||
from unittest.mock import MagicMock | ||
|
||
import boa | ||
import pytest | ||
from _pytest.monkeypatch import MonkeyPatch | ||
|
||
from boa_zksync import set_zksync_browser_env | ||
from boa_zksync.environment import ZERO_ADDRESS | ||
|
||
|
||
def _javascript_call(js_func: str, *args, timeout_message: str) -> Any: | ||
if js_func == "rpc": | ||
method = args[0] | ||
if method == "evm_snapshot": | ||
return 1 | ||
|
||
if method == "evm_revert": | ||
assert args[1:] == ([1],), f"Bad args passed to mock: {args}" | ||
return None | ||
|
||
if method == "wallet_switchEthereumChain": | ||
assert args[1:] == ([{"chainId": "0x1"}],), f"Bad args passed to mock: {args}" | ||
return None | ||
|
||
raise KeyError(args) | ||
|
||
if js_func == "loadSigner": | ||
return ZERO_ADDRESS | ||
|
||
raise KeyError(js_func) | ||
|
||
|
||
@pytest.fixture(scope="session", autouse=True) | ||
def patch_js(): | ||
# we call MonkeyPatch directly because the default `monkeypatch` fixture has a function scope | ||
# this clashes with the boa plugin that tries to clean up the env after each test. | ||
mpatch = MonkeyPatch() | ||
mpatch.setattr("boa.integrations.jupyter.browser._javascript_call", _javascript_call) | ||
yield | ||
mpatch.undo() | ||
|
||
|
||
@pytest.fixture | ||
def browser_env(): | ||
set_zksync_browser_env() | ||
|
||
|
||
def test_browser(browser_env): | ||
boa.env.set_chain_id(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters