Skip to content

Commit

Permalink
Handle frozen variants explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
nielstron committed Jan 2, 2025
1 parent 4eebe5b commit 69bfb05
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1731,7 +1731,7 @@ def test_compiler_options(self):
p = parse(f.read())
p1 = tools.compile(p, compiler_config.OPT_O0_CONFIG)
p2 = tools.compile(p, compiler_config.OPT_O3_CONFIG)
self.assertNotEquals(
self.assertNotEqual(
p1.dumps(), p2.dumps(), "Compiler options did not change the program."
)
for i in range(5):
Expand Down
5 changes: 5 additions & 0 deletions tests/test_roundtrips.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ def visit_Variable(self, node: Variable):
class HypothesisTests(unittest.TestCase):
@hypothesis.given(uplc_program, hst.sampled_from(UPLCDialect))
@hypothesis.settings(max_examples=1000, deadline=None)
@hypothesis.example(
Program(version=(1, 0, 0), term=PlutusMap(frozendict.frozendict({}))),
UPLCDialect.LegacyAiken,
)
@hypothesis.example(
Program(version=(1, 0, 0), term=BuiltinByteString(value=b"")),
UPLCDialect.LegacyAiken,
Expand Down Expand Up @@ -452,6 +456,7 @@ def test_flat_unflat_roundtrip(self, p: Program):
# TODO test invalid programs being detected with an free variable error

@hypothesis.given(uplc_data)
@hypothesis.example(PlutusMap({}))
def test_cbor_plutus_data_roundtrip(self, p: PlutusData):
encoded = plutus_cbor_dumps(p)
decoded = data_from_cbor(encoded)
Expand Down
6 changes: 6 additions & 0 deletions uplc/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,12 @@ def default_encoder(encoder: CBOREncoder, value: Union[PlutusData, IndefiniteLis
encoder.encode(item)
encoder.write(b"\xff")
return
if isinstance(value, frozendict.frozendict):
encoder.encode(dict(value))
return
if isinstance(value, frozenlist):
encoder.encode(list(value))
return
if not isinstance(value, PlutusData):
raise NotImplementedError(f"Can not encode type {type(value)}")
value = value.to_cbor()
Expand Down

0 comments on commit 69bfb05

Please sign in to comment.