@@ -35,7 +35,6 @@ struct TransferMatchingSignatureEvent: ABIEvent {
3535class EthereumClientTests : XCTestCase {
3636 var client : EthereumClient ?
3737 var account : EthereumAccount ?
38- let timeout = 10.0
3938
4039 override func setUp( ) {
4140 super. setUp ( )
@@ -44,34 +43,25 @@ class EthereumClientTests: XCTestCase {
4443 print ( " Public address: \( self . account? . address. value ?? " NONE " ) " )
4544 }
4645
47- func testEthGetTransactionCount( ) {
48- let expectation = XCTestExpectation ( description: " get transaction receipt " )
49-
50- client? . eth_getTransactionCount ( address: account!. address, block: . Latest, completion: { ( error, count) in
51- XCTAssertNotNil ( count, " Transaction count not available: \( error? . localizedDescription ?? " no error " ) " )
52- expectation. fulfill ( )
53- } )
54-
55- wait ( for: [ expectation] , timeout: timeout)
46+ func testEthGetTransactionCount( ) async {
47+ do {
48+ let count = try await client? . eth_getTransactionCount ( address: account!. address, block: . Latest)
49+ XCTAssertNotEqual ( count, 0 )
50+ } catch {
51+ XCTFail ( " Expected count but failed \( error) . " )
52+ }
5653 }
5754
58- func testEthGetTransactionCountPending( ) {
59- let expectation = XCTestExpectation ( description: " get transaction receipt " )
60-
61- client? . eth_getTransactionCount ( address: account!. address, block: . Pending, completion: { ( error, count) in
62- XCTAssertNotNil ( count, " Transaction count not available: \( error? . localizedDescription ?? " no error " ) " )
63- expectation. fulfill ( )
64- } )
65-
66- wait ( for: [ expectation] , timeout: timeout)
55+ func testEthGetTransactionCountPending( ) async {
56+ do {
57+ let count = try await client? . eth_getTransactionCount ( address: account!. address, block: . Pending)
58+ XCTAssertNotEqual ( count, 0 )
59+ } catch {
60+ XCTFail ( " Expected count but failed \( error) . " )
61+ }
6762 }
68- }
69-
70- #if compiler(>=5.5) && canImport(_Concurrency)
7163
72- @available ( macOS 10 . 15 , iOS 13 , watchOS 6 , tvOS 13 , * )
73- extension EthereumClientTests {
74- func testEthGetBalance_Async( ) async throws {
64+ func testEthGetBalance( ) async throws {
7565 do {
7666 let balance = try await client? . eth_getBalance ( address: account? . address ?? . zero, block: . Latest)
7767 XCTAssertNotNil ( balance, " Balance not available " )
@@ -80,7 +70,7 @@ extension EthereumClientTests {
8070 }
8171 }
8272
83- func testEthGetBalanceIncorrectAddress_Async ( ) async {
73+ func testEthGetBalanceIncorrectAddress ( ) async {
8474 do {
8575 _ = try await client? . eth_getBalance ( address: EthereumAddress ( " 0xnig42niog2 " ) , block: . Latest)
8676 XCTFail ( " Expected to throw while awaiting, but succeeded " )
@@ -89,7 +79,7 @@ extension EthereumClientTests {
8979 }
9080 }
9181
92- func testNetVersion_Async ( ) async {
82+ func testNetVersion ( ) async {
9383 do {
9484 let network = try await client? . net_version ( )
9585 XCTAssertEqual ( network, EthereumNetwork . Ropsten, " Network incorrect " )
@@ -98,7 +88,7 @@ extension EthereumClientTests {
9888 }
9989 }
10090
101- func testEthGasPrice_Async ( ) async {
91+ func testEthGasPrice ( ) async {
10292 do {
10393 let gas = try await client? . eth_gasPrice ( )
10494 XCTAssertNotNil ( gas, " Gas not available " )
@@ -107,7 +97,7 @@ extension EthereumClientTests {
10797 }
10898 }
10999
110- func testEthBlockNumber_Async ( ) async {
100+ func testEthBlockNumber ( ) async {
111101 do {
112102 let block = try await client? . eth_blockNumber ( )
113103 XCTAssertNotNil ( block, " Block not available " )
@@ -116,7 +106,7 @@ extension EthereumClientTests {
116106 }
117107 }
118108
119- func testEthGetCode_Async ( ) async {
109+ func testEthGetCode ( ) async {
120110 do {
121111 let code = try await client? . eth_getCode ( address: EthereumAddress ( " 0x112234455c3a32fd11230c42e7bccd4a84e02010 " ) )
122112 XCTAssertNotNil ( code, " Contract code not available " )
@@ -125,7 +115,7 @@ extension EthereumClientTests {
125115 }
126116 }
127117
128- func testEthSendRawTransaction_Async ( ) async {
118+ func testEthSendRawTransaction ( ) async {
129119 do {
130120 let tx = EthereumTransaction ( from: nil , to: EthereumAddress ( " 0x3c1bd6b420448cf16a389c8b0115ccb3660bb854 " ) , value: BigUInt ( 1600000 ) , data: nil , nonce: 2 , gasPrice: BigUInt ( 4000000 ) , gasLimit: BigUInt ( 500000 ) , chainId: EthereumNetwork . Ropsten. intValue)
131121
@@ -136,7 +126,7 @@ extension EthereumClientTests {
136126 }
137127 }
138128
139- func testEthGetTransactionReceipt_Async ( ) async {
129+ func testEthGetTransactionReceipt ( ) async {
140130 do {
141131 let txHash = " 0xc51002441dc669ad03697fd500a7096c054b1eb2ce094821e68831a3666fc878 "
142132 let receipt = try await client? . eth_getTransactionReceipt ( txHash: txHash)
@@ -146,7 +136,7 @@ extension EthereumClientTests {
146136 }
147137 }
148138
149- func testEthCall_Async ( ) async {
139+ func testEthCall ( ) async {
150140 do {
151141 let tx = EthereumTransaction ( from: nil , to: EthereumAddress ( " 0x3c1bd6b420448cf16a389c8b0115ccb3660bb854 " ) , value: BigUInt ( 1800000 ) , data: nil , nonce: 2 , gasPrice: BigUInt ( 400000 ) , gasLimit: BigUInt ( 50000 ) , chainId: EthereumNetwork . Ropsten. intValue)
152142 let txHash = try await client? . eth_call ( tx, block: . Latest)
@@ -156,7 +146,7 @@ extension EthereumClientTests {
156146 }
157147 }
158148
159- func testSimpleEthGetLogs_Async ( ) async {
149+ func testSimpleEthGetLogs ( ) async {
160150 do {
161151 let logs = try await client? . eth_getLogs ( addresses: [ EthereumAddress ( " 0x23d0a442580c01e420270fba6ca836a8b2353acb " ) ] , topics: nil , fromBlock: . Earliest, toBlock: . Latest)
162152 XCTAssertNotNil ( logs, " Logs not available " )
@@ -165,7 +155,7 @@ extension EthereumClientTests {
165155 }
166156 }
167157
168- func testOrTopicsEthGetLogs_Async ( ) async {
158+ func testOrTopicsEthGetLogs ( ) async {
169159 do {
170160 let logs = try await client? . eth_getLogs ( addresses: nil , orTopics: [ [ " 0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c " , " 0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65 " ] , [ " 0x000000000000000000000000655ef694b98e55977a93259cb3b708560869a8f3 " ] ] , fromBlock: . Number( 6540313 ) , toBlock: . Number( 6540397 ) )
171161 XCTAssertEqual ( logs? . count, 2 )
@@ -175,7 +165,7 @@ extension EthereumClientTests {
175165 }
176166 }
177167
178- func testGivenGenesisBlock_ThenReturnsByNumber_Async ( ) async {
168+ func testGivenGenesisBlock_ThenReturnsByNumber ( ) async {
179169 do {
180170 let block = try await client? . eth_getBlockByNumber ( . Number( 0 ) )
181171 XCTAssertEqual ( block? . timestamp. timeIntervalSince1970, 0 )
@@ -186,7 +176,7 @@ extension EthereumClientTests {
186176 }
187177 }
188178
189- func testGivenLatestBlock_ThenReturnsByNumber_Async ( ) async {
179+ func testGivenLatestBlock_ThenReturnsByNumber ( ) async {
190180 do {
191181 let block = try await client? . eth_getBlockByNumber ( . Latest)
192182 XCTAssertNotNil ( block? . number. intValue)
@@ -195,7 +185,7 @@ extension EthereumClientTests {
195185 }
196186 }
197187
198- func testGivenExistingBlock_ThenGetsBlockByNumber_Async ( ) async {
188+ func testGivenExistingBlock_ThenGetsBlockByNumber ( ) async {
199189 do {
200190 let block = try await client? . eth_getBlockByNumber ( . Number( 3415757 ) )
201191 XCTAssertEqual ( block? . number, . Number( 3415757 ) )
@@ -207,7 +197,7 @@ extension EthereumClientTests {
207197 }
208198 }
209199
210- func testGivenUnexistingBlockNumber_ThenGetBlockByNumberReturnsError_Async ( ) async {
200+ func testGivenUnexistingBlockNumber_ThenGetBlockByNumberReturnsError ( ) async {
211201 do {
212202 let _ = try await client? . eth_getBlockByNumber ( . Number( Int . max) )
213203 XCTFail ( " Expected to throw while awaiting, but succeeded " )
@@ -216,7 +206,7 @@ extension EthereumClientTests {
216206 }
217207 }
218208
219- func testGivenMinedTransactionHash_ThenGetsTransactionByHash_Async ( ) async {
209+ func testGivenMinedTransactionHash_ThenGetsTransactionByHash ( ) async {
220210 do {
221211 let transaction = try await client? . eth_getTransaction ( byHash: " 0x014726c783ab2fd6828a9ca556850bccfc66f70926f411274eaf886385c704af " )
222212 XCTAssertEqual ( transaction? . from? . value, " 0xbbf5029fd710d227630c8b7d338051b8e76d50b3 " )
@@ -232,7 +222,7 @@ extension EthereumClientTests {
232222 }
233223 }
234224
235- func testGivenUnexistingTransactionHash_ThenErrorsGetTransactionByHash_Async ( ) async {
225+ func testGivenUnexistingTransactionHash_ThenErrorsGetTransactionByHash ( ) async {
236226 do {
237227 let _ = try await client? . eth_getTransaction ( byHash: " 0x01234 " )
238228 XCTFail ( " Expected to throw while awaiting, but succeeded " )
@@ -241,7 +231,7 @@ extension EthereumClientTests {
241231 }
242232 }
243233
244- func testGivenNoFilters_WhenMatchingSingleTransferEvents_AllEventsReturned_Async ( ) async {
234+ func testGivenNoFilters_WhenMatchingSingleTransferEvents_AllEventsReturned ( ) async {
245235 do {
246236 let to = try ! ABIEncoder . encode ( EthereumAddress ( " 0x3C1Bd6B420448Cf16A389C8b0115CCB3660bB854 " ) )
247237
@@ -257,7 +247,7 @@ extension EthereumClientTests {
257247 }
258248 }
259249
260- func testGivenNoFilters_WhenMatchingMultipleTransferEvents_BothEventsReturned_Async ( ) async {
250+ func testGivenNoFilters_WhenMatchingMultipleTransferEvents_BothEventsReturned ( ) async {
261251 do {
262252 let to = try ! ABIEncoder . encode ( EthereumAddress ( " 0x3C1Bd6B420448Cf16A389C8b0115CCB3660bB854 " ) )
263253
@@ -273,7 +263,7 @@ extension EthereumClientTests {
273263 }
274264 }
275265
276- func testGivenContractFilter_WhenMatchingSingleTransferEvents_OnlyMatchingSourceEventReturned_Async ( ) async {
266+ func testGivenContractFilter_WhenMatchingSingleTransferEvents_OnlyMatchingSourceEventReturned ( ) async {
277267 do {
278268 let to = try ! ABIEncoder . encodeRaw ( " 0x3C1Bd6B420448Cf16A389C8b0115CCB3660bB854 " , forType: ABIRawType . FixedAddress)
279269 let filters = [
@@ -292,7 +282,7 @@ extension EthereumClientTests {
292282 }
293283 }
294284
295- func testGivenContractFilter_WhenMatchingMultipleTransferEvents_OnlyMatchingSourceEventsReturned_Async ( ) async {
285+ func testGivenContractFilter_WhenMatchingMultipleTransferEvents_OnlyMatchingSourceEventsReturned ( ) async {
296286 do {
297287 let to = try ! ABIEncoder . encode ( EthereumAddress ( " 0x3C1Bd6B420448Cf16A389C8b0115CCB3660bB854 " ) )
298288 let filters = [
@@ -312,7 +302,7 @@ extension EthereumClientTests {
312302 }
313303 }
314304
315- func test_GivenDynamicArrayResponse_ThenCallReceivesData_Async ( ) async {
305+ func test_GivenDynamicArrayResponse_ThenCallReceivesData ( ) async {
316306 do {
317307 let function = GetGuardians ( wallet: EthereumAddress ( " 0x2A6295C34b4136F2C3c1445c6A0338D784fe0ddd " ) )
318308
@@ -323,7 +313,7 @@ extension EthereumClientTests {
323313 }
324314 }
325315
326- func test_GivenUnimplementedMethod_WhenCallingContract_ThenFailsWithExecutionError_Async ( ) async {
316+ func test_GivenUnimplementedMethod_WhenCallingContract_ThenFailsWithExecutionError ( ) async {
327317 do {
328318 let function = InvalidMethodA ( param: . zero)
329319 let _ = try await function. call (
@@ -340,7 +330,7 @@ extension EthereumClientTests {
340330 }
341331 }
342332
343- func test_GivenValidTransaction_ThenEstimatesGas_Async ( ) async {
333+ func test_GivenValidTransaction_ThenEstimatesGas ( ) async {
344334 do {
345335 let function = TransferToken ( wallet: EthereumAddress ( " 0xD18dE36e6FB4a5A069f673723Fab71cc00C6CE5F " ) ,
346336 token: EthereumAddress ( " 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE " ) ,
@@ -358,8 +348,6 @@ extension EthereumClientTests {
358348 }
359349}
360350
361- #endif
362-
363351struct GetGuardians : ABIFunction {
364352 static let name = " getGuardians "
365353 let contract = EthereumAddress ( " 0x25BD64224b7534f7B9e3E16dd10b6dED1A412b90 " )
0 commit comments