Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use dict index to get value instead of guessing filename (hotfix 0.1) #8

Merged
merged 5 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion boa_zksync/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from boa.rpc import to_bytes

from boa_zksync.compiler_utils import get_compiler_output
from boa_zksync.types import ZksyncCompilerData


Expand Down Expand Up @@ -40,7 +41,7 @@ def compile_zksync(
with open(filename) as file:
source_code = file.read()

compile_output = output[filename.removeprefix("./")]
compile_output = get_compiler_output(output)
bytecode = to_bytes(compile_output.pop("bytecode"))
return ZksyncCompilerData(
contract_name, source_code, compiler_args, bytecode, **compile_output
Expand Down
14 changes: 14 additions & 0 deletions boa_zksync/compiler_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,17 @@ def detect_expr_type(source_code, contract):
except InvalidType:
pass
return None


def get_compiler_output(output):
# we need this helper method to get the correct key containing compiler output
# from the compiler. Assuming key names could change and also assuming that the
# number of keys could change, this method breaks if any of that happens:

excluded_keys = {"version", "zk_version", "__VYPER_MINIMAL_PROXY_CONTRACT"}
contract_keys = set(output.keys()) - excluded_keys

if len(contract_keys) != 1:
raise ValueError(f"Expected exactly one contract key, found {contract_keys}")

return output[next(iter(contract_keys))]
1 change: 1 addition & 0 deletions boa_zksync/deployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def env(self) -> "ZksyncEnv":
"""
env = Env.get_singleton()
from boa_zksync.environment import ZksyncEnv

assert isinstance(
env, ZksyncEnv
), "ZksyncDeployer can only be used in zkSync environments"
Expand Down
37 changes: 37 additions & 0 deletions tests/test_get_compiler_output.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import pytest

from boa_zksync.compiler_utils import get_compiler_output


def test_get_compiler_output():

output_dict = {"blabla": 123, "zk_version": 456, "version": 789}

assert get_compiler_output(output_dict) == 123


def test_get_compiler_output_too_many_keys():

output_dict = {
"blabla": 123,
"zk_version": 456,
"version": 789,
"new_compiler_output_key": 101112,
}

with pytest.raises(
ValueError,
match="Expected exactly one contract key, found {'blabla', 'new_compiler_output_key'}",
):
get_compiler_output(output_dict)


def test_get_compiler_output_unexpected_key():

output_dict = {"blabla": 123, "zk_versions": 456, "version": 789}

with pytest.raises(
ValueError,
match="Expected exactly one contract key, found {'blabla', 'zk_versions'}",
):
get_compiler_output(output_dict)