Skip to content

Commit 0f1d690

Browse files
committed
Add a test for invalid enum value
1 parent 4623d0d commit 0f1d690

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

chia/_tests/core/util/test_streamable.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,17 @@ class TestClassStr(Streamable):
726726
TestClassStr.from_bytes(bytes([0, 0, 100, 24, 52]))
727727

728728

729+
def test_deserialization_to_invalid_enum() -> None:
730+
@streamable
731+
@dataclass(frozen=True)
732+
class TestClassStr(Streamable):
733+
a: StringEnum
734+
735+
# encodes the string "baz" which is not a valid value for StringEnum
736+
with pytest.raises(ValueError, match=re.escape("'baz' is not a valid StringEnum")):
737+
TestClassStr.from_bytes(bytes([0, 0, 0, 3, 98, 97, 122]))
738+
739+
729740
def test_ambiguous_deserialization_bytes() -> None:
730741
@streamable
731742
@dataclass(frozen=True)

0 commit comments

Comments
 (0)