nucypher/tests/unit/conditions/test_condition_lingo.py

43 lines
1.1 KiB
Python
Raw Normal View History

import pytest
2022-09-22 11:42:48 +00:00
from nucypher.policy.conditions.lingo import ConditionLingo
2022-11-10 14:16:36 +00:00
CONDITIONS = [
{
"returnValueTest": {"value": 0, "comparator": ">"},
"method": "timelock"
},
{"operator": "and"},
{
"returnValueTest": {"value": 99999999999999999, "comparator": "<"},
"method": "timelock",
},
2022-09-22 11:42:48 +00:00
]
2022-11-10 14:16:36 +00:00
def test_invalid_condition():
with pytest.raises(Exception):
ConditionLingo.from_list([{}])
with pytest.raises(Exception):
ConditionLingo.from_list([{"dont_mind_me": "nothing_to_see_here"}])
2022-11-16 01:57:08 +00:00
def test_condition_lingo_to_from_list():
clingo = ConditionLingo.from_list(CONDITIONS)
clingo_list = clingo.to_list()
assert clingo_list == CONDITIONS
def test_compound_condition():
2022-11-10 14:16:36 +00:00
clingo = ConditionLingo.from_list(CONDITIONS)
2022-09-22 11:42:48 +00:00
assert clingo.eval()
2022-11-10 14:16:36 +00:00
def test_condition_lingo_repr():
clingo = ConditionLingo.from_list(CONDITIONS)
clingo_string = f"{clingo}"
assert f"{clingo.__class__.__name__}" in clingo_string
assert f"id={clingo.id}" in clingo_string
assert f"size={len(bytes(clingo))}" in clingo_string