Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSchiavini committed May 22, 2024
1 parent 80d4069 commit ffcd91d
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 31 deletions.
4 changes: 1 addition & 3 deletions boa_zksync/browser.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import logging
import os
from shutil import which

import requests
from boa.integrations.jupyter.browser import BrowserRPC, BrowserSigner, colab_eval_js
from boa.rpc import EthereumRPC

from boa_zksync.environment import ZksyncEnv
from boa_zksync.util import install_zkvyper_compiler, install_era_test_node
from boa_zksync.util import install_era_test_node, install_zkvyper_compiler


class ZksyncBrowserEnv(ZksyncEnv):
Expand Down
12 changes: 6 additions & 6 deletions boa_zksync/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

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_expr_type,
generate_source_for_arbitrary_stmt,
generate_source_for_internal_fn,
)
from boa.contracts.vyper.vyper_contract import VyperContract
from boa.rpc import to_int, to_bytes
from boa.rpc import to_bytes, to_int
from boa.util.abi import Address
from cached_property import cached_property
from vyper.semantics.analysis.base import VarInfo
Expand Down Expand Up @@ -188,9 +188,9 @@ def __init__(self, code: str, contract: ZksyncContract):
abi = {
"anonymous": False,
"inputs": [],
"outputs": [
{"name": "eval", "type": typ.abi_type.selector_name()}
] if typ else [],
"outputs": (
[{"name": "eval", "type": typ.abi_type.selector_name()}] if typ else []
),
"name": "__boa_debug__",
"type": "function",
}
Expand Down
21 changes: 15 additions & 6 deletions boa_zksync/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from boa.environment import _AddressType
from boa.interpret import json
from boa.network import NetworkEnv, _EstimateGasFailed
from boa.rpc import RPC, EthereumRPC, to_hex, RPCError, to_int
from boa.rpc import RPC, EthereumRPC, RPCError, to_hex, to_int
from boa.util.abi import Address
from eth.exceptions import VMError
from eth_account import Account
Expand Down Expand Up @@ -122,11 +122,16 @@ def execute_code(
args = ZksyncMessage(sender, to_address, gas or 0, value, data)

try:
trace_call = self._rpc.fetch("debug_traceCall", [args.as_json_dict(), "latest", {"tracer": "callTracer"}])
trace_call = self._rpc.fetch(
"debug_traceCall",
[args.as_json_dict(), "latest", {"tracer": "callTracer"}],
)
traced_computation = ZksyncComputation.from_call_trace(trace_call)
except (RPCError, HTTPError):
output = self._rpc.fetch("eth_call", [args.as_json_dict(), "latest"])
traced_computation = ZksyncComputation(args, bytes.fromhex(output.removeprefix("0x")))
traced_computation = ZksyncComputation(
args, bytes.fromhex(output.removeprefix("0x"))
)

if is_modifying:
try:
Expand Down Expand Up @@ -261,8 +266,9 @@ def __init__(self, getter, setter):
self.getter = getter
self.setter = setter

def __set_name__(self, owner: Type["_RPCState"], name: str) -> None:
... # python descriptor protocol
def __set_name__(
self, owner: Type["_RPCState"], name: str
) -> None: ... # python descriptor protocol

def __get__(self, state: "_RPCState", owner):
if state is None:
Expand All @@ -277,7 +283,10 @@ class _RPCState:
# Test node adds a virtual empty block at the end of the batch.
# When you use the RPC - you get the timestamp of the last actually committed block.
timestamp = _RPCProperty(
lambda rpc: to_int(rpc.fetch_uncached("eth_getBlockByNumber", ["pending", False])["timestamp"]) + 1,
lambda rpc: to_int(
rpc.fetch_uncached("eth_getBlockByNumber", ["pending", False])["timestamp"]
)
+ 1,
lambda rpc, value: rpc.fetch_uncached("evm_setTime", [value - 1]),
)

Expand Down
50 changes: 40 additions & 10 deletions boa_zksync/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,46 @@
class EraTestNode(EthereumRPC):
# list of public+private keys for test accounts in the era_test_node
TEST_ACCOUNTS = [
("0xBC989fDe9e54cAd2aB4392Af6dF60f04873A033A", "0x3d3cbc973389cb26f657686445bcc75662b415b656078503592ac8c1abb8810e"),
("0x55bE1B079b53962746B2e86d12f158a41DF294A6", "0x509ca2e9e6acf0ba086477910950125e698d4ea70fa6f63e000c5a22bda9361c"),
("0xCE9e6063674DC585F6F3c7eaBe82B9936143Ba6C", "0x71781d3a358e7a65150e894264ccc594993fbc0ea12d69508a340bc1d4f5bfbc"),
("0xd986b0cB0D1Ad4CCCF0C4947554003fC0Be548E9", "0x379d31d4a7031ead87397f332aab69ef5cd843ba3898249ca1046633c0c7eefe"),
("0x87d6ab9fE5Adef46228fB490810f0F5CB16D6d04", "0x105de4e75fe465d075e1daae5647a02e3aad54b8d23cf1f70ba382b9f9bee839"),
("0x78cAD996530109838eb016619f5931a03250489A", "0x7becc4a46e0c3b512d380ca73a4c868f790d1055a7698f38fb3ca2b2ac97efbb"),
("0xc981b213603171963F81C687B9fC880d33CaeD16", "0xe0415469c10f3b1142ce0262497fe5c7a0795f0cbfd466a6bfa31968d0f70841"),
("0x42F3dc38Da81e984B92A95CBdAAA5fA2bd5cb1Ba", "0x4d91647d0a8429ac4433c83254fb9625332693c848e578062fe96362f32bfe91"),
("0x64F47EeD3dC749d13e49291d46Ea8378755fB6DF", "0x41c9f9518aa07b50cb1c0cc160d45547f57638dd824a8d85b5eb3bf99ed2bdeb"),
("0xe2b8Cb53a43a56d4d2AB6131C81Bd76B86D3AFe5", "0xb0680d66303a0163a19294f1ef8c95cd69a9d7902a4aca99c05f3e134e68a11a"),
(
"0xBC989fDe9e54cAd2aB4392Af6dF60f04873A033A",
"0x3d3cbc973389cb26f657686445bcc75662b415b656078503592ac8c1abb8810e",
),
(
"0x55bE1B079b53962746B2e86d12f158a41DF294A6",
"0x509ca2e9e6acf0ba086477910950125e698d4ea70fa6f63e000c5a22bda9361c",
),
(
"0xCE9e6063674DC585F6F3c7eaBe82B9936143Ba6C",
"0x71781d3a358e7a65150e894264ccc594993fbc0ea12d69508a340bc1d4f5bfbc",
),
(
"0xd986b0cB0D1Ad4CCCF0C4947554003fC0Be548E9",
"0x379d31d4a7031ead87397f332aab69ef5cd843ba3898249ca1046633c0c7eefe",
),
(
"0x87d6ab9fE5Adef46228fB490810f0F5CB16D6d04",
"0x105de4e75fe465d075e1daae5647a02e3aad54b8d23cf1f70ba382b9f9bee839",
),
(
"0x78cAD996530109838eb016619f5931a03250489A",
"0x7becc4a46e0c3b512d380ca73a4c868f790d1055a7698f38fb3ca2b2ac97efbb",
),
(
"0xc981b213603171963F81C687B9fC880d33CaeD16",
"0xe0415469c10f3b1142ce0262497fe5c7a0795f0cbfd466a6bfa31968d0f70841",
),
(
"0x42F3dc38Da81e984B92A95CBdAAA5fA2bd5cb1Ba",
"0x4d91647d0a8429ac4433c83254fb9625332693c848e578062fe96362f32bfe91",
),
(
"0x64F47EeD3dC749d13e49291d46Ea8378755fB6DF",
"0x41c9f9518aa07b50cb1c0cc160d45547f57638dd824a8d85b5eb3bf99ed2bdeb",
),
(
"0xe2b8Cb53a43a56d4d2AB6131C81Bd76B86D3AFe5",
"0xb0680d66303a0163a19294f1ef8c95cd69a9d7902a4aca99c05f3e134e68a11a",
),
]

def __init__(self, rpc: Optional[EthereumRPC] = None, block_identifier="safe"):
Expand Down
6 changes: 3 additions & 3 deletions boa_zksync/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ class ZksyncComputation:
error: VMError | None = None
children: list["ZksyncComputation"] = field(default_factory=list)
gas_used: int = 0
revert_reason: str = None
revert_reason: str | None = None
type: str = "Call"
value: int = 0

Expand Down Expand Up @@ -249,7 +249,8 @@ def from_call_trace(cls, output: dict) -> "ZksyncComputation":
@classmethod
def from_debug_trace(cls, output: dict):
"""
Finds the actual transaction computation, since zksync has system contract calls in the trace.
Finds the actual transaction computation, since zksync has system
contract calls in the trace.
"""
to, sender = output["to"], output["from"]

Expand All @@ -262,7 +263,6 @@ def _find(calls: list[dict]):

return _find(output["calls"])


@property
def is_success(self) -> bool:
"""
Expand Down
1 change: 0 additions & 1 deletion tests/test_browser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from typing import Any
from unittest.mock import MagicMock

import boa
import pytest
Expand Down
9 changes: 7 additions & 2 deletions tests/test_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,16 @@ def transfer(_to : address, _value : uint256) -> bool:
return True
"""
contract = boa.loads(code, 100)
assert [str(e) for e in contract.get_logs()] == ["Transfer(sender=0x0000000000000000000000000000000000000000, receiver=0xBC989fDe9e54cAd2aB4392Af6dF60f04873A033A, value=100)"]
assert [str(e) for e in contract.get_logs()] == [
"Transfer(sender=0x0000000000000000000000000000000000000000, "
"receiver=0xBC989fDe9e54cAd2aB4392Af6dF60f04873A033A, value=100)"
]

to = boa.env.generate_address()
contract.transfer(to, 10)
assert [str(e) for e in contract.get_logs()] == [f"Transfer(sender={boa.env.eoa}, receiver={to}, value=10)"]
assert [str(e) for e in contract.get_logs()] == [
f"Transfer(sender={boa.env.eoa}, receiver={to}, value=10)"
]


def test_time(zksync_env):
Expand Down

0 comments on commit ffcd91d

Please sign in to comment.