@@ -202,6 +202,76 @@ def test_eth_sign(self, web3, unlocked_account_dual_type):
202202 )
203203 assert new_signature != signature
204204
205+ def test_eth_signTypedData (self , web3 , unlocked_account_dual_type ):
206+ validJSONMessage = '''
207+ {
208+ "types": {
209+ "EIP712Domain": [
210+ {"name": "name", "type": "string"},
211+ {"name": "version", "type": "string"},
212+ {"name": "chainId", "type": "uint256"},
213+ {"name": "verifyingContract", "type": "address"}
214+ ],
215+ "Person": [
216+ {"name": "name", "type": "string"},
217+ {"name": "wallet", "type": "address"}
218+ ],
219+ "Mail": [
220+ {"name": "from", "type": "Person"},
221+ {"name": "to", "type": "Person"},
222+ {"name": "contents", "type": "string"}
223+ ]
224+ },
225+ "primaryType": "Mail",
226+ "domain": {
227+ "name": "Ether Mail",
228+ "version": "1",
229+ "chainId": 1,
230+ "verifyingContract": "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"
231+ },
232+ "message": {
233+ "from": {
234+ "name": "Cow",
235+ "wallet": "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826"
236+ },
237+ "to": {
238+ "name": "Bob",
239+ "wallet": "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB"
240+ },
241+ "contents": "Hello, Bob!"
242+ }
243+ }
244+ '''
245+ signature = web3 .eth .signTypedData (
246+ unlocked_account_dual_type ,
247+ validJSONMessage
248+ )
249+ assert is_bytes (signature )
250+ assert len (signature ) == 32 + 32 + 1
251+
252+ # # test other formats
253+ # hexsign = web3.eth.sign(
254+ # unlocked_account_dual_type,
255+ # hexstr='0x4d6573736167652074c3b6207369676e2e204c6f6e676572207468616e206861736821'
256+ # )
257+ # assert hexsign == signature
258+ #
259+ # intsign = web3.eth.sign(
260+ # unlocked_account_dual_type,
261+ # 0x4d6573736167652074c3b6207369676e2e204c6f6e676572207468616e206861736821
262+ # )
263+ # assert intsign == signature
264+ #
265+ # bytessign = web3.eth.sign(
266+ # unlocked_account_dual_type, b'Message t\xc3\xb6 sign. Longer than hash!'
267+ # )
268+ # assert bytessign == signature
269+ #
270+ # new_signature = web3.eth.sign(
271+ # unlocked_account_dual_type, text='different message is different'
272+ # )
273+ # assert new_signature != signature
274+
205275 def test_eth_signTransaction (self , web3 , unlocked_account ):
206276 txn_params = {
207277 'from' : unlocked_account ,
0 commit comments