From aa8928983c08ac6eed4b2c03ffafae6271fadbc6 Mon Sep 17 00:00:00 2001 From: Daniel Schiavini Date: Tue, 20 Aug 2024 14:38:50 +0200 Subject: [PATCH 1/2] Fix deployment issue for production RPC --- boa_zksync/types.py | 6 ++- pyproject.toml | 4 +- tests/test_computation.py | 50 +++++++++++++++++++++++++ tests/{test_fork.py => test_sepolia.py} | 1 + 4 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 tests/test_computation.py rename tests/{test_fork.py => test_sepolia.py} (95%) diff --git a/boa_zksync/types.py b/boa_zksync/types.py index 67c9db3..410dfc5 100644 --- a/boa_zksync/types.py +++ b/boa_zksync/types.py @@ -260,6 +260,7 @@ def from_debug_trace(cls, output: dict): """ Finds the actual transaction computation, since zksync has system contract calls in the trace. + Note: The output has more data when running via the era test node. """ to, sender = output["to"], output["from"] @@ -270,7 +271,10 @@ def _find(calls: list[dict]): if trace["to"] == to and trace["from"] == sender: return cls.from_call_trace(trace) - return _find(output["calls"]) + if result := _find(output["calls"]): + return result + # in production mode the result is not always nested + return cls.from_call_trace(output) @property def is_success(self) -> bool: diff --git a/pyproject.toml b/pyproject.toml index facd7ab..9292d44 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "titanoboa-zksync" -version = "0.1.1" +version = "0.1.2" description = "A Zksync plugin for the Titanoboa Vyper interpreter" license = { file = "LICENSE" } readme = "README.md" @@ -8,7 +8,7 @@ keywords = ["ethereum", "evm", "smart contract", "development", "vyper", "zksync classifiers = ["Topic :: Software Development"] # Requirements -dependencies = ["titanoboa>=0.1,<0.2"] +dependencies = ["titanoboa==0.1.10"] [project.optional-dependencies] forking-recommended = ["ujson"] diff --git a/tests/test_computation.py b/tests/test_computation.py new file mode 100644 index 0000000..2a00776 --- /dev/null +++ b/tests/test_computation.py @@ -0,0 +1,50 @@ +import boa + +from boa_zksync.types import ZksyncComputation + +_required_fields = {"gas": "0x0", "value": "0x0", "input": "0x00", "gasUsed": "0x0"} + + +def test_from_debug_trace_nested(): + sender = boa.env.generate_address() + to = boa.env.generate_address() + result = boa.env.generate_address().canonical_address + output = { + "from": sender, + "to": to, + "output": boa.env.generate_address(), + "calls": [{ + "from": boa.env.generate_address(), + "to": boa.env.generate_address(), + "output": boa.env.generate_address(), + "calls": [], + **_required_fields, + }, { + "from": sender, + "to": to, + "output": "0x" +result.hex(), + "calls": [], + **_required_fields, + }, { + "from": boa.env.generate_address(), + "to": boa.env.generate_address(), + "output": boa.env.generate_address(), + "calls": [], + **_required_fields, + }] + } + assert ZksyncComputation.from_debug_trace(output).output == result + + +def test_from_debug_trace_production_mode(): + # in production the real transaction output is directly in the result + # when running via the era test node, more contracts are actually included + result = boa.env.generate_address().canonical_address + output = { + "from": boa.env.generate_address(), + "to": boa.env.generate_address(), + "output": "0x" +result.hex(), + "calls": [], + **_required_fields, + } + assert ZksyncComputation.from_debug_trace(output).output == result diff --git a/tests/test_fork.py b/tests/test_sepolia.py similarity index 95% rename from tests/test_fork.py rename to tests/test_sepolia.py index 4f11c29..b95a751 100644 --- a/tests/test_fork.py +++ b/tests/test_sepolia.py @@ -4,6 +4,7 @@ from boa_zksync import EraTestNode from boa_zksync.environment import ZERO_ADDRESS +from boa_zksync.types import ZksyncComputation def test_dummy_contract(zksync_sepolia_fork): From 89415b4801d45af385d6d1318f054a047fc3ad92 Mon Sep 17 00:00:00 2001 From: Daniel Schiavini Date: Tue, 20 Aug 2024 14:41:31 +0200 Subject: [PATCH 2/2] Lint --- tests/test_computation.py | 44 +++++++++++++++++-------------- tests/test_get_compiler_output.py | 3 +-- tests/test_sepolia.py | 1 - 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/tests/test_computation.py b/tests/test_computation.py index 2a00776..31481dd 100644 --- a/tests/test_computation.py +++ b/tests/test_computation.py @@ -13,25 +13,29 @@ def test_from_debug_trace_nested(): "from": sender, "to": to, "output": boa.env.generate_address(), - "calls": [{ - "from": boa.env.generate_address(), - "to": boa.env.generate_address(), - "output": boa.env.generate_address(), - "calls": [], - **_required_fields, - }, { - "from": sender, - "to": to, - "output": "0x" +result.hex(), - "calls": [], - **_required_fields, - }, { - "from": boa.env.generate_address(), - "to": boa.env.generate_address(), - "output": boa.env.generate_address(), - "calls": [], - **_required_fields, - }] + "calls": [ + { + "from": boa.env.generate_address(), + "to": boa.env.generate_address(), + "output": boa.env.generate_address(), + "calls": [], + **_required_fields, + }, + { + "from": sender, + "to": to, + "output": "0x" + result.hex(), + "calls": [], + **_required_fields, + }, + { + "from": boa.env.generate_address(), + "to": boa.env.generate_address(), + "output": boa.env.generate_address(), + "calls": [], + **_required_fields, + }, + ], } assert ZksyncComputation.from_debug_trace(output).output == result @@ -43,7 +47,7 @@ def test_from_debug_trace_production_mode(): output = { "from": boa.env.generate_address(), "to": boa.env.generate_address(), - "output": "0x" +result.hex(), + "output": "0x" + result.hex(), "calls": [], **_required_fields, } diff --git a/tests/test_get_compiler_output.py b/tests/test_get_compiler_output.py index ae262ac..f5bc6c2 100644 --- a/tests/test_get_compiler_output.py +++ b/tests/test_get_compiler_output.py @@ -31,7 +31,6 @@ 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", + ValueError, match="Expected exactly one contract key, found blabla, zk_versions" ): get_compiler_output(output_dict) diff --git a/tests/test_sepolia.py b/tests/test_sepolia.py index b95a751..4f11c29 100644 --- a/tests/test_sepolia.py +++ b/tests/test_sepolia.py @@ -4,7 +4,6 @@ from boa_zksync import EraTestNode from boa_zksync.environment import ZERO_ADDRESS -from boa_zksync.types import ZksyncComputation def test_dummy_contract(zksync_sepolia_fork):