11import XCTest
22@testable import web3swift
33
4- class EIP712Tests : XCTestCase {
4+ class EIP712Tests : LocalTestCase {
55 func testWithoutChainId( ) throws {
6-
6+
77 let to = EthereumAddress ( " 0x3F06bAAdA68bB997daB03d91DBD0B73e196c5A4d " ) !
8-
8+
99 let value = EIP712 . UInt256 ( 0 )
10-
10+
1111 let amountLinen = EIP712 . UInt256 ( " 0001000000000000000 " ) //
12-
12+
1313 let function = ABI . Element. Function (
1414 name: " approveAndMint " ,
1515 inputs: [
@@ -18,22 +18,22 @@ class EIP712Tests: XCTestCase {
1818 outputs: [ . init( name: " " , type: . bool) ] ,
1919 constant: false ,
2020 payable: false )
21-
21+
2222 let object = ABI . Element. function ( function)
23-
23+
2424 let safeTxData = object. encodeParameters ( [
2525 EthereumAddress ( " 0x41B5844f4680a8C38fBb695b7F9CFd1F64474a72 " ) ! as AnyObject ,
2626 amountLinen as AnyObject
2727 ] ) !
28-
28+
2929 let operation : EIP712 . UInt8 = 1
30-
30+
3131 let safeTxGas = EIP712 . UInt256 ( 250000 )
32-
32+
3333 let baseGas = EIP712 . UInt256 ( 60000 )
34-
34+
3535 let gasPrice = EIP712 . UInt256 ( " 20000000000 " )
36-
36+
3737 let gasToken = EthereumAddress ( " 0x0000000000000000000000000000000000000000 " ) !
3838 print ( 1 )
3939 let refundReceiver = EthereumAddress ( " 0x7c07D32e18D6495eFDC487A32F8D20daFBa53A5e " ) !
@@ -76,13 +76,13 @@ class EIP712Tests: XCTestCase {
7676 }
7777
7878 func testWithChainId( ) throws {
79-
79+
8080 let to = EthereumAddress ( " 0x3F06bAAdA68bB997daB03d91DBD0B73e196c5A4d " ) !
81-
81+
8282 let value = EIP712 . UInt256 ( 0 )
83-
83+
8484 let amount = EIP712 . UInt256 ( " 0001000000000000000 " )
85-
85+
8686 let function = ABI . Element. Function (
8787 name: " approveAndMint " ,
8888 inputs: [
@@ -91,28 +91,28 @@ class EIP712Tests: XCTestCase {
9191 outputs: [ . init( name: " " , type: . bool) ] ,
9292 constant: false ,
9393 payable: false )
94-
94+
9595 let object = ABI . Element. function ( function)
96-
96+
9797 let safeTxData = object. encodeParameters ( [
9898 EthereumAddress ( " 0x41B5844f4680a8C38fBb695b7F9CFd1F64474a72 " ) ! as AnyObject ,
9999 amount as AnyObject
100100 ] ) !
101-
101+
102102 let operation : EIP712 . UInt8 = 1
103-
103+
104104 let safeTxGas = EIP712 . UInt256 ( 250000 )
105-
105+
106106 let baseGas = EIP712 . UInt256 ( 60000 )
107-
107+
108108 let gasPrice = EIP712 . UInt256 ( " 20000000000 " )
109-
109+
110110 let gasToken = EthereumAddress ( " 0x0000000000000000000000000000000000000000 " ) !
111-
111+
112112 let refundReceiver = EthereumAddress ( " 0x7c07D32e18D6495eFDC487A32F8D20daFBa53A5e " ) !
113-
113+
114114 let nonce : EIP712 . UInt256 = . init( 0 )
115-
115+
116116 let safeTX = SafeTx (
117117 to: to,
118118 value: value,
@@ -124,25 +124,24 @@ class EIP712Tests: XCTestCase {
124124 gasToken: gasToken,
125125 refundReceiver: refundReceiver,
126126 nonce: nonce)
127-
127+
128128 let mnemonic = " normal dune pole key case cradle unfold require tornado mercy hospital buyer "
129129 let keystore = try ! BIP32Keystore ( mnemonics: mnemonic, password: " " , mnemonicsPassword: " " ) !
130-
130+
131131 let verifyingContract = EthereumAddress ( " 0x76106814dc6150b0fe510fbda4d2d877ac221270 " ) !
132-
132+
133133 let account = keystore. addresses ? [ 0 ]
134134 let password = " "
135135 let chainId : EIP712 . UInt256 ? = EIP712 . UInt256 ( 42 )
136-
136+
137137 let signature = try Web3Signer . signEIP712 (
138138 safeTx: safeTX,
139139 keystore: keystore,
140140 verifyingContract: verifyingContract,
141141 account: account!,
142142 password: password,
143143 chainId: chainId)
144-
144+
145145 XCTAssertEqual ( signature. toHexString ( ) , " f1f423cb23efad5035d4fb95c19cfcd46d4091f2bd924680b88c4f9edfa1fb3a4ce5fc5d169f354e3b464f45a425ed3f6203af06afbacdc5c8224a300ce9e6b21b " )
146146 }
147147}
148-
0 commit comments