Skip to content

Commit 4990084

Browse files
chore: added new test for Invalid Order Signature error
1 parent e40c3f8 commit 4990084

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

Tests/web3swiftTests/localTests/EIP712TypedDataPayloadTests.swift

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,4 +360,103 @@ class EIP712TypedDataPayloadTests: XCTestCase {
360360
let (compressedSignature, _) = try SECP256K1.signForRecovery(hash: parsedEip712TypedData.signHash(), privateKey: privateKey)
361361
XCTAssertEqual(compressedSignature!.toHexString(), "f2ec61e636ff7bb3ac8bc2a4cc2c8b8f635dd1b2ec8094c963128b358e79c85c5ca6dd637ed7e80f0436fe8fce39c0e5f2082c9517fe677cc2917dcd6c84ba881c")
362362
}
363+
364+
/// This test makes sure that custom types are alphabetically ordered when encoded
365+
/// This test is built on thje following example: https://github.com/trustwallet/wallet-core/pull/2325/files
366+
/// Link to the GitHub issue https://github.com/trustwallet/wallet-core/issues/2323
367+
/// > According to the description of the issues it fixes (see the link above):
368+
/// > The type string is different from `metamask/eth-sig-util`
369+
/// > `type: OrderComponents(...)OfferItem(...)ConsiderationItem(...)`
370+
/// > `ConsiderationItem` should be in front of `OfferItem`
371+
func testEIP712OpenseaInvalidOrderSignature() throws {
372+
let rawPayload = """
373+
{
374+
"types": {
375+
"EIP712Domain": [
376+
{ "name": "name", "type": "string" },
377+
{ "name": "version", "type": "string" },
378+
{ "name": "chainId", "type": "uint256" },
379+
{ "name": "verifyingContract", "type": "address" }
380+
],
381+
"OrderComponents": [
382+
{ "name": "offerer", "type": "address" },
383+
{ "name": "zone", "type": "address" },
384+
{ "name": "offer", "type": "OfferItem[]" },
385+
{ "name": "consideration", "type": "ConsiderationItem[]" },
386+
{ "name": "orderType", "type": "uint8" },
387+
{ "name": "startTime", "type": "uint256" },
388+
{ "name": "endTime", "type": "uint256" },
389+
{ "name": "zoneHash", "type": "bytes32" },
390+
{ "name": "salt", "type": "uint256" },
391+
{ "name": "conduitKey", "type": "bytes32" },
392+
{ "name": "counter", "type": "uint256" }
393+
],
394+
"OfferItem": [
395+
{ "name": "itemType", "type": "uint8" },
396+
{ "name": "token", "type": "address" },
397+
{ "name": "identifierOrCriteria", "type": "uint256" },
398+
{ "name": "startAmount", "type": "uint256" },
399+
{ "name": "endAmount", "type": "uint256" }
400+
],
401+
"ConsiderationItem": [
402+
{ "name": "itemType", "type": "uint8" },
403+
{ "name": "token", "type": "address" },
404+
{ "name": "identifierOrCriteria", "type": "uint256" },
405+
{ "name": "startAmount", "type": "uint256" },
406+
{ "name": "endAmount", "type": "uint256" },
407+
{ "name": "recipient", "type": "address" }
408+
]
409+
},
410+
"primaryType": "OrderComponents",
411+
"domain": {
412+
"name": "Seaport",
413+
"version": "1.1",
414+
"chainId": "1",
415+
"verifyingContract": "0x00000000006c3852cbEf3e08E8dF289169EdE581"
416+
},
417+
"message": {
418+
"offerer": "0x7d8bf18C7cE84b3E175b339c4Ca93aEd1dD166F1",
419+
"offer": [
420+
{
421+
"itemType": "2",
422+
"token": "0x3F53082981815Ed8142384EDB1311025cA750Ef1",
423+
"identifierOrCriteria": "134",
424+
"startAmount": "1",
425+
"endAmount": "1"
426+
}
427+
],
428+
"orderType": "2",
429+
"consideration": [
430+
{
431+
"itemType": "0",
432+
"token": "0x0000000000000000000000000000000000000000",
433+
"identifierOrCriteria": "0",
434+
"startAmount": "975000000000000000",
435+
"endAmount": "975000000000000000",
436+
"recipient": "0x7d8bf18C7cE84b3E175b339c4Ca93aEd1dD166F1"
437+
},
438+
{
439+
"itemType": "0",
440+
"token": "0x0000000000000000000000000000000000000000",
441+
"identifierOrCriteria": "0",
442+
"startAmount": "25000000000000000",
443+
"endAmount": "25000000000000000",
444+
"recipient": "0x8De9C5A032463C561423387a9648c5C7BCC5BC90"
445+
}
446+
],
447+
"startTime": "1655450129",
448+
"endTime": "1658042129",
449+
"zone": "0x004C00500000aD104D7DBd00e3ae0A5C00560C00",
450+
"zoneHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
451+
"salt": "795459960395409",
452+
"conduitKey": "0x0000007b02230091a7ed01230072f7006a004d60a8d4e71d599b8104250f0000",
453+
"totalOriginalConsiderationItems": "2",
454+
"counter": "0"
455+
}
456+
}
457+
"""
458+
459+
let parsedPayload = try EIP712Parser.parse(rawPayload)
460+
try XCTAssertEqual(parsedPayload.signHash().toHexString(), "54140d99a864932cbc40fd8a2d1d1706c3923a79c183a3b151e929ac468064db")
461+
}
363462
}

0 commit comments

Comments
 (0)