Skip to content

Commit 9fa1b09

Browse files
committed
Test custom JSONEncoder's fallback path
1 parent de080fe commit 9fa1b09

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

tests/test_message_json.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import json
22
import os
33

4+
import pytest
5+
46
from eip712_structs import EIP712Struct, String, make_domain, Bytes
57

68

@@ -125,3 +127,12 @@ class Foo(EIP712Struct):
125127
reconstructed = EIP712Struct.from_message(json.loads(result))
126128
assert reconstructed.domain == domain
127129
assert reconstructed.message == foo
130+
131+
class UnserializableObject:
132+
pass
133+
obj = UnserializableObject()
134+
135+
# Fabricate this failure case to test that the custom json encoder's fallback path works as expected.
136+
foo.values['b'] = obj
137+
with pytest.raises(TypeError, match='not JSON serializable'):
138+
foo.to_message_json(domain)

0 commit comments

Comments
 (0)