Skip to content

Commit

Permalink
Merge branch '0.1' of github.com:DanielSchiavini/titanoboa-zksync
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSchiavini committed Aug 20, 2024
2 parents 4db81c0 + 5da3a09 commit bd5e0c3
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 4 deletions.
6 changes: 5 additions & 1 deletion boa_zksync/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,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"]

Expand All @@ -271,7 +272,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:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "titanoboa-zksync"
version = "0.2.1"
version = "0.2.2"
description = "A Zksync plugin for the Titanoboa Vyper interpreter"
license = { file = "LICENSE" }
readme = "README.md"
Expand Down
54 changes: 54 additions & 0 deletions tests/test_computation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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
3 changes: 1 addition & 2 deletions tests/test_get_compiler_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
File renamed without changes.

0 comments on commit bd5e0c3

Please sign in to comment.