Skip to content

Commit

Permalink
fix: fix pragma settings parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
z80dev committed Jan 30, 2024
1 parent 4841017 commit ebb7aff
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 3 deletions.
6 changes: 5 additions & 1 deletion dasy/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
build_layout_output,
build_opcodes_output,
)
from vyper.compiler.settings import Settings
from dasy.parser import parse_src
from dasy.parser.utils import filename_to_contract_name

Expand Down Expand Up @@ -74,13 +75,16 @@ def layout(self):

def generate_compiler_data(src: str, name="DasyContract") -> CompilerData:
(ast, settings) = parse_src(src)
settings = Settings(**settings)
data = CompilerData(
"",
ast.name or name,
None,
source_id=0,
**settings,
settings=settings,
)
print(data)
print(data.settings)
data.vyper_module = ast
return data

Expand Down
1 change: 1 addition & 0 deletions dasy/parser/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ def parse_src(src: str):
add_src_map(src, element, v)
elif isinstance(ast, dict):
settings.update(ast)
continue
elif ast:
add_src_map(src, element, ast)
else:
Expand Down
6 changes: 6 additions & 0 deletions examples/Transient.vy
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma evm-version cancun

@nonreentrant("lock")
@external
def foo() -> uint256:
return 4
2 changes: 1 addition & 1 deletion examples/nonreentrant.dasy
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(pragma :evm-version "cancun")
(pragma :evm-version "paris")

(defn func0 [] [:external (nonreentrant "lock")]
(raw_call msg/sender b"" :value 0))
Expand Down
14 changes: 14 additions & 0 deletions examples/nonreentrant2.dasy
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
;; (interface! "examples/nonreentrantenforcer.dasy")
(definterface Nonreentrantenforcer
(defn func0 [] :nonpayable))

(defvar target (public Nonreentrantenforcer))

(defn __init__ [:address target] :external
(set self/target (Nonreentrantenforcer target)))

(defn callback [] :external
(.func0 self/target))

(defn __fallback__ [] :external
(.func0 self/target))
10 changes: 10 additions & 0 deletions examples/nonreentrantenforcer.dasy
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(pragma :evm-version "paris")

(defn func0 [] [:external (nonreentrant "lock")]
(raw_call msg/sender b"" :value 0))

(defn func1 [] [:external (nonreentrant "lock_2")]
(raw_call msg/sender b"" :value 0))

(defn func2 [] [:external (nonreentrant "lock_2")]
(raw_call msg/sender b"" :value 0))
10 changes: 10 additions & 0 deletions examples/transient_nonreentrant.dasy
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(pragma :evm-version "cancun")

(defn func0 [] [:external (nonreentrant "lock")]
(raw_call msg/sender b"" :value 0))

(defn func1 [] [:external (nonreentrant "lock_2")]
(raw_call msg/sender b"" :value 0))

(defn func2 [] [:external (nonreentrant "lock_2")]
(raw_call msg/sender b"" :value 0))
5 changes: 4 additions & 1 deletion tests/test_dasy.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,10 @@ def testInterface():


def test_reentrancy():
c = compile("examples/nonreentrant.dasy") # noqa: F841
# TODO: This test should fail!
c = compile("examples/nonreentrantenforcer.dasy") # noqa: F841
helper = compile("examples/nonreentrant2.dasy", c.address) # noqa: F841
helper.callback()


def test_auction():
Expand Down

0 comments on commit ebb7aff

Please sign in to comment.