Skip to content

Commit 2d1c6bb

Browse files
fix: fixed EIP712 tests
1 parent 5ca135b commit 2d1c6bb

File tree

1 file changed

+2
-43
lines changed

1 file changed

+2
-43
lines changed

Tests/web3swiftTests/localTests/EIP712Tests.swift

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,9 @@ import Core
44

55
class EIP712Tests: LocalTestCase {
66
func testWithoutChainId() throws {
7-
87
let to = EthereumAddress("0x3F06bAAdA68bB997daB03d91DBD0B73e196c5A4d")!
9-
108
let value = EIP712.UInt256(0)
11-
129
let amountLinen = EIP712.UInt256("0001000000000000000")//
13-
1410
let function = ABI.Element.Function(
1511
name: "approveAndMint",
1612
inputs: [
@@ -19,28 +15,18 @@ class EIP712Tests: LocalTestCase {
1915
outputs: [.init(name: "", type: .bool)],
2016
constant: false,
2117
payable: false)
22-
2318
let object = ABI.Element.function(function)
24-
2519
let safeTxData = object.encodeParameters([
2620
EthereumAddress("0x41B5844f4680a8C38fBb695b7F9CFd1F64474a72")! as AnyObject,
2721
amountLinen as AnyObject
2822
])!
29-
3023
let operation: EIP712.UInt8 = 1
31-
3224
let safeTxGas = EIP712.UInt256(250000)
33-
3425
let baseGas = EIP712.UInt256(60000)
35-
3626
let gasPrice = EIP712.UInt256("20000000000")
37-
3827
let gasToken = EthereumAddress("0x0000000000000000000000000000000000000000")!
39-
print(1)
4028
let refundReceiver = EthereumAddress("0x7c07D32e18D6495eFDC487A32F8D20daFBa53A5e")!
41-
print(2)
4229
let nonce: EIP712.UInt256 = .init(6)
43-
print(3)
4430
let safeTX = SafeTx(
4531
to: to,
4632
value: value,
@@ -52,38 +38,26 @@ class EIP712Tests: LocalTestCase {
5238
gasToken: gasToken,
5339
refundReceiver: refundReceiver,
5440
nonce: nonce)
55-
print(4)
5641
let password = ""
57-
print(5)
5842
let chainId: EIP712.UInt256? = nil
59-
print(6)
6043
let verifyingContract = EthereumAddress("0x40c21f00Faafcf10Cc671a75ea0de62305199DC1")!
61-
print(7)
6244
let mnemonic = "normal dune pole key case cradle unfold require tornado mercy hospital buyer"
63-
print(8)
6445
let keystore = try! BIP32Keystore(mnemonics: mnemonic, password: "", mnemonicsPassword: "")!
65-
print(9)
6646
let account = keystore.addresses?[0]
67-
print(10)
6847
let signature = try Web3Signer.signEIP712(
69-
safeTx: safeTX,
48+
safeTX,
7049
keystore: keystore,
7150
verifyingContract: verifyingContract,
7251
account: account!,
7352
password: password,
7453
chainId: chainId)
75-
print(11)
7654
XCTAssertEqual(signature.toHexString(), "bf3182a3f52e65b416f86e76851c8e7d5602aef28af694f31359705b039d8d1931d53f3d5088ac7195944e8a9188d161ba3757877d08105885304f65282228c71c")
7755
}
7856

7957
func testWithChainId() throws {
80-
8158
let to = EthereumAddress("0x3F06bAAdA68bB997daB03d91DBD0B73e196c5A4d")!
82-
8359
let value = EIP712.UInt256(0)
84-
8560
let amount = EIP712.UInt256("0001000000000000000")
86-
8761
let function = ABI.Element.Function(
8862
name: "approveAndMint",
8963
inputs: [
@@ -92,28 +66,18 @@ class EIP712Tests: LocalTestCase {
9266
outputs: [.init(name: "", type: .bool)],
9367
constant: false,
9468
payable: false)
95-
9669
let object = ABI.Element.function(function)
97-
9870
let safeTxData = object.encodeParameters([
9971
EthereumAddress("0x41B5844f4680a8C38fBb695b7F9CFd1F64474a72")! as AnyObject,
10072
amount as AnyObject
10173
])!
102-
10374
let operation: EIP712.UInt8 = 1
104-
10575
let safeTxGas = EIP712.UInt256(250000)
106-
10776
let baseGas = EIP712.UInt256(60000)
108-
10977
let gasPrice = EIP712.UInt256("20000000000")
110-
11178
let gasToken = EthereumAddress("0x0000000000000000000000000000000000000000")!
112-
11379
let refundReceiver = EthereumAddress("0x7c07D32e18D6495eFDC487A32F8D20daFBa53A5e")!
114-
11580
let nonce: EIP712.UInt256 = .init(0)
116-
11781
let safeTX = SafeTx(
11882
to: to,
11983
value: value,
@@ -125,24 +89,19 @@ class EIP712Tests: LocalTestCase {
12589
gasToken: gasToken,
12690
refundReceiver: refundReceiver,
12791
nonce: nonce)
128-
12992
let mnemonic = "normal dune pole key case cradle unfold require tornado mercy hospital buyer"
13093
let keystore = try! BIP32Keystore(mnemonics: mnemonic, password: "", mnemonicsPassword: "")!
131-
13294
let verifyingContract = EthereumAddress("0x76106814dc6150b0fe510fbda4d2d877ac221270")!
133-
13495
let account = keystore.addresses?[0]
13596
let password = ""
13697
let chainId: EIP712.UInt256? = EIP712.UInt256(42)
137-
13898
let signature = try Web3Signer.signEIP712(
139-
safeTx: safeTX,
99+
safeTX,
140100
keystore: keystore,
141101
verifyingContract: verifyingContract,
142102
account: account!,
143103
password: password,
144104
chainId: chainId)
145-
146105
XCTAssertEqual(signature.toHexString(), "f1f423cb23efad5035d4fb95c19cfcd46d4091f2bd924680b88c4f9edfa1fb3a4ce5fc5d169f354e3b464f45a425ed3f6203af06afbacdc5c8224a300ce9e6b21b")
147106
}
148107
}

0 commit comments

Comments
 (0)