@@ -4,13 +4,9 @@ import Core
4
4
5
5
class EIP712Tests : LocalTestCase {
6
6
func testWithoutChainId( ) throws {
7
-
8
7
let to = EthereumAddress ( " 0x3F06bAAdA68bB997daB03d91DBD0B73e196c5A4d " ) !
9
-
10
8
let value = EIP712 . UInt256 ( 0 )
11
-
12
9
let amountLinen = EIP712 . UInt256 ( " 0001000000000000000 " ) //
13
-
14
10
let function = ABI . Element. Function (
15
11
name: " approveAndMint " ,
16
12
inputs: [
@@ -19,28 +15,18 @@ class EIP712Tests: LocalTestCase {
19
15
outputs: [ . init( name: " " , type: . bool) ] ,
20
16
constant: false ,
21
17
payable: false )
22
-
23
18
let object = ABI . Element. function ( function)
24
-
25
19
let safeTxData = object. encodeParameters ( [
26
20
EthereumAddress ( " 0x41B5844f4680a8C38fBb695b7F9CFd1F64474a72 " ) ! as AnyObject ,
27
21
amountLinen as AnyObject
28
22
] ) !
29
-
30
23
let operation : EIP712 . UInt8 = 1
31
-
32
24
let safeTxGas = EIP712 . UInt256 ( 250000 )
33
-
34
25
let baseGas = EIP712 . UInt256 ( 60000 )
35
-
36
26
let gasPrice = EIP712 . UInt256 ( " 20000000000 " )
37
-
38
27
let gasToken = EthereumAddress ( " 0x0000000000000000000000000000000000000000 " ) !
39
- print ( 1 )
40
28
let refundReceiver = EthereumAddress ( " 0x7c07D32e18D6495eFDC487A32F8D20daFBa53A5e " ) !
41
- print ( 2 )
42
29
let nonce : EIP712 . UInt256 = . init( 6 )
43
- print ( 3 )
44
30
let safeTX = SafeTx (
45
31
to: to,
46
32
value: value,
@@ -52,38 +38,26 @@ class EIP712Tests: LocalTestCase {
52
38
gasToken: gasToken,
53
39
refundReceiver: refundReceiver,
54
40
nonce: nonce)
55
- print ( 4 )
56
41
let password = " "
57
- print ( 5 )
58
42
let chainId : EIP712 . UInt256 ? = nil
59
- print ( 6 )
60
43
let verifyingContract = EthereumAddress ( " 0x40c21f00Faafcf10Cc671a75ea0de62305199DC1 " ) !
61
- print ( 7 )
62
44
let mnemonic = " normal dune pole key case cradle unfold require tornado mercy hospital buyer "
63
- print ( 8 )
64
45
let keystore = try ! BIP32Keystore ( mnemonics: mnemonic, password: " " , mnemonicsPassword: " " ) !
65
- print ( 9 )
66
46
let account = keystore. addresses ? [ 0 ]
67
- print ( 10 )
68
47
let signature = try Web3Signer . signEIP712 (
69
- safeTx : safeTX,
48
+ safeTX,
70
49
keystore: keystore,
71
50
verifyingContract: verifyingContract,
72
51
account: account!,
73
52
password: password,
74
53
chainId: chainId)
75
- print ( 11 )
76
54
XCTAssertEqual ( signature. toHexString ( ) , " bf3182a3f52e65b416f86e76851c8e7d5602aef28af694f31359705b039d8d1931d53f3d5088ac7195944e8a9188d161ba3757877d08105885304f65282228c71c " )
77
55
}
78
56
79
57
func testWithChainId( ) throws {
80
-
81
58
let to = EthereumAddress ( " 0x3F06bAAdA68bB997daB03d91DBD0B73e196c5A4d " ) !
82
-
83
59
let value = EIP712 . UInt256 ( 0 )
84
-
85
60
let amount = EIP712 . UInt256 ( " 0001000000000000000 " )
86
-
87
61
let function = ABI . Element. Function (
88
62
name: " approveAndMint " ,
89
63
inputs: [
@@ -92,28 +66,18 @@ class EIP712Tests: LocalTestCase {
92
66
outputs: [ . init( name: " " , type: . bool) ] ,
93
67
constant: false ,
94
68
payable: false )
95
-
96
69
let object = ABI . Element. function ( function)
97
-
98
70
let safeTxData = object. encodeParameters ( [
99
71
EthereumAddress ( " 0x41B5844f4680a8C38fBb695b7F9CFd1F64474a72 " ) ! as AnyObject ,
100
72
amount as AnyObject
101
73
] ) !
102
-
103
74
let operation : EIP712 . UInt8 = 1
104
-
105
75
let safeTxGas = EIP712 . UInt256 ( 250000 )
106
-
107
76
let baseGas = EIP712 . UInt256 ( 60000 )
108
-
109
77
let gasPrice = EIP712 . UInt256 ( " 20000000000 " )
110
-
111
78
let gasToken = EthereumAddress ( " 0x0000000000000000000000000000000000000000 " ) !
112
-
113
79
let refundReceiver = EthereumAddress ( " 0x7c07D32e18D6495eFDC487A32F8D20daFBa53A5e " ) !
114
-
115
80
let nonce : EIP712 . UInt256 = . init( 0 )
116
-
117
81
let safeTX = SafeTx (
118
82
to: to,
119
83
value: value,
@@ -125,24 +89,19 @@ class EIP712Tests: LocalTestCase {
125
89
gasToken: gasToken,
126
90
refundReceiver: refundReceiver,
127
91
nonce: nonce)
128
-
129
92
let mnemonic = " normal dune pole key case cradle unfold require tornado mercy hospital buyer "
130
93
let keystore = try ! BIP32Keystore ( mnemonics: mnemonic, password: " " , mnemonicsPassword: " " ) !
131
-
132
94
let verifyingContract = EthereumAddress ( " 0x76106814dc6150b0fe510fbda4d2d877ac221270 " ) !
133
-
134
95
let account = keystore. addresses ? [ 0 ]
135
96
let password = " "
136
97
let chainId : EIP712 . UInt256 ? = EIP712 . UInt256 ( 42 )
137
-
138
98
let signature = try Web3Signer . signEIP712 (
139
- safeTx : safeTX,
99
+ safeTX,
140
100
keystore: keystore,
141
101
verifyingContract: verifyingContract,
142
102
account: account!,
143
103
password: password,
144
104
chainId: chainId)
145
-
146
105
XCTAssertEqual ( signature. toHexString ( ) , " f1f423cb23efad5035d4fb95c19cfcd46d4091f2bd924680b88c4f9edfa1fb3a4ce5fc5d169f354e3b464f45a425ed3f6203af06afbacdc5c8224a300ce9e6b21b " )
147
106
}
148
107
}
0 commit comments