Skip to content

Commit

Permalink
Add failing testcase handling function access to global variables
Browse files Browse the repository at this point in the history
  • Loading branch information
nielstron committed Apr 23, 2023
1 parent 68f33e1 commit f61b912
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions opshin/tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -976,3 +976,33 @@ def validator(x: Token) -> bool:
except Exception as e:
failed = True
self.assertTrue(failed, "Machine did validate the content")

def test_inner_outer_state_functions(self):
source_code = """
a = 2
def b() -> int:
return a
def validator(_: None) -> int:
a = 3
return b()
"""
ast = compiler.parse(source_code)
code = compiler.compile(ast).compile()
res = uplc_eval(uplc.Apply(code, uplc.PlutusConstr(0, [])))
self.assertEqual(res, uplc.PlutusInteger(2))

def test_outer_state_change_functions(self):
source_code = """
a = 2
def b() -> int:
return a
a = 3
def validator(_: None) -> int:
return b()
"""
ast = compiler.parse(source_code)
code = compiler.compile(ast).compile()
res = uplc_eval(uplc.Apply(code, uplc.PlutusConstr(0, [])))
self.assertEqual(res, uplc.PlutusInteger(3))

0 comments on commit f61b912

Please sign in to comment.