Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSchiavini committed Sep 19, 2024
1 parent 1122473 commit 00daf4a
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 22 deletions.
15 changes: 14 additions & 1 deletion boa_zksync/deployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,23 @@ def _compile(
def from_abi_dict(cls, abi, name="<anonymous contract>", filename=None):
raise NotImplementedError("ZksyncDeployer does not support loading from ABI")

def deploy(self, *args, value=0, **kwargs) -> ZksyncContract:
def deploy(
self,
*args,
value=0,
gas=None,
dependency_bytecodes=(),
salt=b"\0" * 32,
max_priority_fee_per_gas=None,
**kwargs,
) -> ZksyncContract:
address, _ = self.env.deploy_code(
bytecode=self.zkvyper_data.bytecode,
value=value,
gas=gas,
dependency_bytecodes=dependency_bytecodes,
salt=salt,
max_priority_fee_per_gas=max_priority_fee_per_gas,
constructor_calldata=(
self.constructor.prepare_calldata(*args, **kwargs)
if args or kwargs
Expand Down
18 changes: 12 additions & 6 deletions boa_zksync/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from hashlib import sha256
from pathlib import Path
from typing import Any, Iterable, Optional, Type
from unittest.mock import MagicMock

from boa.contracts.abi.abi_contract import ABIContract, ABIContractFactory
from boa.environment import _AddressType
Expand All @@ -17,8 +16,13 @@

from boa_zksync.deployer import ZksyncDeployer
from boa_zksync.node import EraTestNode
from boa_zksync.types import DeployTransaction, ZksyncComputation, ZksyncMessage, ZERO_ADDRESS, \
CONTRACT_DEPLOYER_ADDRESS
from boa_zksync.types import (
CONTRACT_DEPLOYER_ADDRESS,
ZERO_ADDRESS,
DeployTransaction,
ZksyncComputation,
ZksyncMessage,
)

with open(Path(__file__).parent / "IContractDeployer.json") as f:
CONTRACT_DEPLOYER = ABIContractFactory.from_abi_dict(
Expand Down Expand Up @@ -51,8 +55,8 @@ def create(self):
@property
def vm(self):
if self._vm is None:
# todo: vyper base contract calls this property
self._vm = MagicMock(state=_RPCState(self._rpc))
self._vm = lambda: None
self._vm.state = _RPCState(self._rpc)
return self._vm

def _reset_fork(self, block_identifier="latest"):
Expand Down Expand Up @@ -165,6 +169,7 @@ def deploy_code(
constructor_calldata=b"",
dependency_bytecodes: Iterable[bytes] = (),
salt=b"\0" * 32,
max_priority_fee_per_gas=None,
**kwargs,
) -> tuple[Address, bytes]:
"""
Expand All @@ -176,6 +181,7 @@ def deploy_code(
:param constructor_calldata: The calldata for the contract constructor.
:param dependency_bytecodes: The bytecodes of the blueprints.
:param salt: The salt for the contract deployment.
:param max_priority_fee_per_gas: The max priority fee per gas for the transaction.
:param kwargs: Additional parameters for the transaction.
:return: The address of the deployed contract and the bytecode hash.
"""
Expand Down Expand Up @@ -203,7 +209,7 @@ def deploy_code(
to=CONTRACT_DEPLOYER_ADDRESS,
gas=gas or 0,
gas_price=gas_price,
max_priority_fee_per_gas=kwargs.pop("max_priority_fee_per_gas", gas_price),
max_priority_fee_per_gas=max_priority_fee_per_gas or gas_price,
nonce=nonce,
value=value,
calldata=self.create.prepare_calldata(
Expand Down
2 changes: 1 addition & 1 deletion boa_zksync/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def get_estimate_tx(self):
"to": self.to,
"gas": f"0x{self.gas:0x}",
"gasPrice": f"0x{self.gas_price:0x}",
"maxPriorityFeePerGas": f"0x{self.max_priority_fee_per_gas :0x}",
"maxPriorityFeePerGas": f"0x{self.max_priority_fee_per_gas:0x}",
"nonce": f"0x{self.nonce:0x}",
"value": f"0x{self.value:0x}",
"data": f"0x{self.calldata.hex()}",
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def zksync_sepolia_fork(account):
fork_url = os.getenv("FORK_URL", "https://sepolia.era.zksync.dev")
boa_zksync.set_zksync_fork(
fork_url,
block_identifier=1689570,
block_identifier=3000000,
node_args=("--show-calls", "all", "--show-outputs", "true"),
)
boa.env.add_account(account, force_eoa=True)
Expand Down
28 changes: 15 additions & 13 deletions tests/test_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,11 @@ def get_name_of(addr: HasName) -> String[32]:
caller_contract.get_name_of(called_contract)

(call_trace, stack_trace) = ctx.value.args
called_addr = called_contract.address
assert stack_trace == StackTrace(
[
" Test an error(<CalledContract interface at "
f"{called_contract.address}> (file CalledContract).name() -> ['string'])",
f"{called_addr}> (file CalledContract).name() -> ['string'])",
" Test an error(<CallerContract interface at "
f"{caller_contract.address}> (file "
"CallerContract).get_name_of(address) -> ['string'])",
Expand All @@ -167,20 +168,21 @@ def get_name_of(addr: HasName) -> String[32]:
)
assert isinstance(call_trace, TraceFrame)
assert str(call_trace).split("\n") == [
f'[E] [24549] CallerContract.get_name_of(addr = "{called_contract.address}") <0x>',
' [E] [23618] Unknown contract 0x0000000000000000000000000000000000008002.0x4de2e468',
' [566] Unknown contract 0x000000000000000000000000000000000000800B.0x29f172ad',
' [1909] Unknown contract 0x000000000000000000000000000000000000800B.0x06bed036',
' [159] Unknown contract 0x0000000000000000000000000000000000008010.0x00000000',
' [449] Unknown contract 0x000000000000000000000000000000000000800B.0xa225efcb',
' [2226] Unknown contract 0x0000000000000000000000000000000000008002.0x4de2e468',
' [427] Unknown contract 0x000000000000000000000000000000000000800B.0xa851ae78',
' [398] Unknown contract 0x0000000000000000000000000000000000008004.0xe516761e',
' [E] [2592] Unknown contract 0x0000000000000000000000000000000000008009.0xb47fade1',
f' [E] [1401] CallerContract.get_name_of(addr = "{called_contract.address}") <0x>',
' [E] [403] CalledContract.name() <0x>'
f'[E] [24523] CallerContract.get_name_of(addr = "{called_addr}") <0x>',
" [E] [23592] Unknown contract 0x0000000000000000000000000000000000008002.0x4de2e468",
" [566] Unknown contract 0x000000000000000000000000000000000000800B.0x29f172ad",
" [1909] Unknown contract 0x000000000000000000000000000000000000800B.0x06bed036",
" [159] Unknown contract 0x0000000000000000000000000000000000008010.0x00000000",
" [449] Unknown contract 0x000000000000000000000000000000000000800B.0xa225efcb",
" [2226] Unknown contract 0x0000000000000000000000000000000000008002.0x4de2e468",
" [427] Unknown contract 0x000000000000000000000000000000000000800B.0xa851ae78",
" [398] Unknown contract 0x0000000000000000000000000000000000008004.0xe516761e",
" [E] [2566] Unknown contract 0x0000000000000000000000000000000000008009.0xb47fade1",
f' [E] [1383] CallerContract.get_name_of(addr = "{called_addr}") <0x>',
" [E] [403] CalledContract.name() <0x>",
]


def test_private(zksync_env):
code = """
bar: uint256
Expand Down

0 comments on commit 00daf4a

Please sign in to comment.