Skip to content

Commit

Permalink
Lint and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSchiavini committed Apr 30, 2024
1 parent 7a68cad commit a4c8351
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 19 deletions.
1 change: 1 addition & 0 deletions boa_zksync/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class ZksyncBrowserEnv(ZksyncEnv):
"""
A zkSync environment for deploying contracts using a browser wallet RPC.
"""

def __init__(self, address=None, *args, **kwargs):
if colab_eval_js and not which("zkvyper"):
logging.warning(
Expand Down
21 changes: 15 additions & 6 deletions boa_zksync/contract.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import textwrap
from contextlib import contextmanager
from unittest.mock import MagicMock

from boa.contracts.abi.abi_contract import ABIContract, ABIFunction
from boa.contracts.vyper.compiler_utils import (
generate_source_for_internal_fn,
generate_source_for_arbitrary_stmt,
detect_statement_type,
detect_expr_type,
)
from boa.contracts.vyper.vyper_contract import VyperContract
from boa.rpc import to_bytes
Expand All @@ -27,21 +26,31 @@ def eval(self, code):

@contextmanager
def override_vyper_namespace(self):
c = VyperContract(self.compiler_data.vyper, env=self.env, override_address=self.address, skip_initcode=True, filename=self.filename)
c = VyperContract(
self.compiler_data.vyper,
env=self.env,
override_address=self.address,
skip_initcode=True,
filename=self.filename,
)
with c.override_vyper_namespace():
yield

@cached_property
def _storage(self):
def storage(): return None
def storage():
return None

for name, var in self.compiler_data.global_ctx.variables.items():
if not var.is_immutable and not var.is_constant:
setattr(storage, name, ZksyncInternalVariable(var, name, self))
return storage

@cached_property
def internal(self):
def internal(): return None
def internal():
return None

for fn in self.compiler_data.global_ctx.functions:
typ = fn._metadata["type"]
if typ.is_internal:
Expand Down Expand Up @@ -130,7 +139,7 @@ def __boa_private_{self.var_name}__() -> {self.var.typ.abi_type.selector_name()}

class ZksyncEval(_ZksyncInternal):
def __init__(self, code: str, contract: ZksyncContract):
typ = detect_statement_type(code, contract)
typ = detect_expr_type(code, contract)
abi = {
"anonymous": False,
"inputs": [],
Expand Down
6 changes: 4 additions & 2 deletions boa_zksync/deployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@
class ZksyncDeployer(ABIContractFactory):

def __init__(self, compiler_data: ZksyncCompilerData, filename=None):
super().__init__(compiler_data.contract_name, compiler_data.abi, filename, compiler_data)
super().__init__(
compiler_data.contract_name, compiler_data.abi, filename, compiler_data
)

@staticmethod
def create_compiler_data(
source_code: str,
contract_name: str = None,
filename: str = None,
compiler_args: dict = None,
**kwargs
**kwargs,
) -> ZksyncCompilerData:
if not contract_name:
contract_name = Path(filename).stem if filename else "<anonymous contract>"
Expand Down
4 changes: 3 additions & 1 deletion tests/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ def _javascript_call(js_func: str, *args, timeout_message: str) -> Any:
return None

if method == "wallet_switchEthereumChain":
assert args[1:] == ([{"chainId": "0x1"}],), f"Bad args passed to mock: {args}"
assert args[1:] == (
[{"chainId": "0x1"}],
), f"Bad args passed to mock: {args}"
return None

raise KeyError(args)
Expand Down
22 changes: 12 additions & 10 deletions tests/test_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,18 @@ def get_name_of(addr: HasName) -> String[32]:

(trace,) = ctx.value.args
assert trace == StackTrace(
[" Test an error(<CalledContract interface at "
f"{called_contract.address}>.name() -> ['string'])",
" Test an error(<CallerContract interface at "
f"{caller_contract.address}>.get_name_of(address) -> "
"['string'])",
" <Unknown contract 0x0000000000000000000000000000000000008009>",
" <Unknown contract 0x0000000000000000000000000000000000008002>",
" Test an error(<CallerContract interface at "
f"{caller_contract.address}>.get_name_of(address) -> "
"['string'])"]
[
" Test an error(<CalledContract interface at "
f"{called_contract.address}>.name() -> ['string'])",
" Test an error(<CallerContract interface at "
f"{caller_contract.address}>.get_name_of(address) -> "
"['string'])",
" <Unknown contract 0x0000000000000000000000000000000000008009>",
" <Unknown contract 0x0000000000000000000000000000000000008002>",
" Test an error(<CallerContract interface at "
f"{caller_contract.address}>.get_name_of(address) -> "
"['string'])",
]
)


Expand Down

0 comments on commit a4c8351

Please sign in to comment.