@@ -35,7 +35,6 @@ struct TransferMatchingSignatureEvent: ABIEvent {
35
35
class EthereumClientTests : XCTestCase {
36
36
var client : EthereumClient ?
37
37
var account : EthereumAccount ?
38
- let timeout = 10.0
39
38
40
39
override func setUp( ) {
41
40
super. setUp ( )
@@ -44,34 +43,25 @@ class EthereumClientTests: XCTestCase {
44
43
print ( " Public address: \( self . account? . address. value ?? " NONE " ) " )
45
44
}
46
45
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
+ }
56
53
}
57
54
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
+ }
67
62
}
68
- }
69
-
70
- #if compiler(>=5.5) && canImport(_Concurrency)
71
63
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 {
75
65
do {
76
66
let balance = try await client? . eth_getBalance ( address: account? . address ?? . zero, block: . Latest)
77
67
XCTAssertNotNil ( balance, " Balance not available " )
@@ -80,7 +70,7 @@ extension EthereumClientTests {
80
70
}
81
71
}
82
72
83
- func testEthGetBalanceIncorrectAddress_Async ( ) async {
73
+ func testEthGetBalanceIncorrectAddress ( ) async {
84
74
do {
85
75
_ = try await client? . eth_getBalance ( address: EthereumAddress ( " 0xnig42niog2 " ) , block: . Latest)
86
76
XCTFail ( " Expected to throw while awaiting, but succeeded " )
@@ -89,7 +79,7 @@ extension EthereumClientTests {
89
79
}
90
80
}
91
81
92
- func testNetVersion_Async ( ) async {
82
+ func testNetVersion ( ) async {
93
83
do {
94
84
let network = try await client? . net_version ( )
95
85
XCTAssertEqual ( network, EthereumNetwork . Ropsten, " Network incorrect " )
@@ -98,7 +88,7 @@ extension EthereumClientTests {
98
88
}
99
89
}
100
90
101
- func testEthGasPrice_Async ( ) async {
91
+ func testEthGasPrice ( ) async {
102
92
do {
103
93
let gas = try await client? . eth_gasPrice ( )
104
94
XCTAssertNotNil ( gas, " Gas not available " )
@@ -107,7 +97,7 @@ extension EthereumClientTests {
107
97
}
108
98
}
109
99
110
- func testEthBlockNumber_Async ( ) async {
100
+ func testEthBlockNumber ( ) async {
111
101
do {
112
102
let block = try await client? . eth_blockNumber ( )
113
103
XCTAssertNotNil ( block, " Block not available " )
@@ -116,7 +106,7 @@ extension EthereumClientTests {
116
106
}
117
107
}
118
108
119
- func testEthGetCode_Async ( ) async {
109
+ func testEthGetCode ( ) async {
120
110
do {
121
111
let code = try await client? . eth_getCode ( address: EthereumAddress ( " 0x112234455c3a32fd11230c42e7bccd4a84e02010 " ) )
122
112
XCTAssertNotNil ( code, " Contract code not available " )
@@ -125,7 +115,7 @@ extension EthereumClientTests {
125
115
}
126
116
}
127
117
128
- func testEthSendRawTransaction_Async ( ) async {
118
+ func testEthSendRawTransaction ( ) async {
129
119
do {
130
120
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)
131
121
@@ -136,7 +126,7 @@ extension EthereumClientTests {
136
126
}
137
127
}
138
128
139
- func testEthGetTransactionReceipt_Async ( ) async {
129
+ func testEthGetTransactionReceipt ( ) async {
140
130
do {
141
131
let txHash = " 0xc51002441dc669ad03697fd500a7096c054b1eb2ce094821e68831a3666fc878 "
142
132
let receipt = try await client? . eth_getTransactionReceipt ( txHash: txHash)
@@ -146,7 +136,7 @@ extension EthereumClientTests {
146
136
}
147
137
}
148
138
149
- func testEthCall_Async ( ) async {
139
+ func testEthCall ( ) async {
150
140
do {
151
141
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)
152
142
let txHash = try await client? . eth_call ( tx, block: . Latest)
@@ -156,7 +146,7 @@ extension EthereumClientTests {
156
146
}
157
147
}
158
148
159
- func testSimpleEthGetLogs_Async ( ) async {
149
+ func testSimpleEthGetLogs ( ) async {
160
150
do {
161
151
let logs = try await client? . eth_getLogs ( addresses: [ EthereumAddress ( " 0x23d0a442580c01e420270fba6ca836a8b2353acb " ) ] , topics: nil , fromBlock: . Earliest, toBlock: . Latest)
162
152
XCTAssertNotNil ( logs, " Logs not available " )
@@ -165,7 +155,7 @@ extension EthereumClientTests {
165
155
}
166
156
}
167
157
168
- func testOrTopicsEthGetLogs_Async ( ) async {
158
+ func testOrTopicsEthGetLogs ( ) async {
169
159
do {
170
160
let logs = try await client? . eth_getLogs ( addresses: nil , orTopics: [ [ " 0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c " , " 0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65 " ] , [ " 0x000000000000000000000000655ef694b98e55977a93259cb3b708560869a8f3 " ] ] , fromBlock: . Number( 6540313 ) , toBlock: . Number( 6540397 ) )
171
161
XCTAssertEqual ( logs? . count, 2 )
@@ -175,7 +165,7 @@ extension EthereumClientTests {
175
165
}
176
166
}
177
167
178
- func testGivenGenesisBlock_ThenReturnsByNumber_Async ( ) async {
168
+ func testGivenGenesisBlock_ThenReturnsByNumber ( ) async {
179
169
do {
180
170
let block = try await client? . eth_getBlockByNumber ( . Number( 0 ) )
181
171
XCTAssertEqual ( block? . timestamp. timeIntervalSince1970, 0 )
@@ -186,7 +176,7 @@ extension EthereumClientTests {
186
176
}
187
177
}
188
178
189
- func testGivenLatestBlock_ThenReturnsByNumber_Async ( ) async {
179
+ func testGivenLatestBlock_ThenReturnsByNumber ( ) async {
190
180
do {
191
181
let block = try await client? . eth_getBlockByNumber ( . Latest)
192
182
XCTAssertNotNil ( block? . number. intValue)
@@ -195,7 +185,7 @@ extension EthereumClientTests {
195
185
}
196
186
}
197
187
198
- func testGivenExistingBlock_ThenGetsBlockByNumber_Async ( ) async {
188
+ func testGivenExistingBlock_ThenGetsBlockByNumber ( ) async {
199
189
do {
200
190
let block = try await client? . eth_getBlockByNumber ( . Number( 3415757 ) )
201
191
XCTAssertEqual ( block? . number, . Number( 3415757 ) )
@@ -207,7 +197,7 @@ extension EthereumClientTests {
207
197
}
208
198
}
209
199
210
- func testGivenUnexistingBlockNumber_ThenGetBlockByNumberReturnsError_Async ( ) async {
200
+ func testGivenUnexistingBlockNumber_ThenGetBlockByNumberReturnsError ( ) async {
211
201
do {
212
202
let _ = try await client? . eth_getBlockByNumber ( . Number( Int . max) )
213
203
XCTFail ( " Expected to throw while awaiting, but succeeded " )
@@ -216,7 +206,7 @@ extension EthereumClientTests {
216
206
}
217
207
}
218
208
219
- func testGivenMinedTransactionHash_ThenGetsTransactionByHash_Async ( ) async {
209
+ func testGivenMinedTransactionHash_ThenGetsTransactionByHash ( ) async {
220
210
do {
221
211
let transaction = try await client? . eth_getTransaction ( byHash: " 0x014726c783ab2fd6828a9ca556850bccfc66f70926f411274eaf886385c704af " )
222
212
XCTAssertEqual ( transaction? . from? . value, " 0xbbf5029fd710d227630c8b7d338051b8e76d50b3 " )
@@ -232,7 +222,7 @@ extension EthereumClientTests {
232
222
}
233
223
}
234
224
235
- func testGivenUnexistingTransactionHash_ThenErrorsGetTransactionByHash_Async ( ) async {
225
+ func testGivenUnexistingTransactionHash_ThenErrorsGetTransactionByHash ( ) async {
236
226
do {
237
227
let _ = try await client? . eth_getTransaction ( byHash: " 0x01234 " )
238
228
XCTFail ( " Expected to throw while awaiting, but succeeded " )
@@ -241,7 +231,7 @@ extension EthereumClientTests {
241
231
}
242
232
}
243
233
244
- func testGivenNoFilters_WhenMatchingSingleTransferEvents_AllEventsReturned_Async ( ) async {
234
+ func testGivenNoFilters_WhenMatchingSingleTransferEvents_AllEventsReturned ( ) async {
245
235
do {
246
236
let to = try ! ABIEncoder . encode ( EthereumAddress ( " 0x3C1Bd6B420448Cf16A389C8b0115CCB3660bB854 " ) )
247
237
@@ -257,7 +247,7 @@ extension EthereumClientTests {
257
247
}
258
248
}
259
249
260
- func testGivenNoFilters_WhenMatchingMultipleTransferEvents_BothEventsReturned_Async ( ) async {
250
+ func testGivenNoFilters_WhenMatchingMultipleTransferEvents_BothEventsReturned ( ) async {
261
251
do {
262
252
let to = try ! ABIEncoder . encode ( EthereumAddress ( " 0x3C1Bd6B420448Cf16A389C8b0115CCB3660bB854 " ) )
263
253
@@ -273,7 +263,7 @@ extension EthereumClientTests {
273
263
}
274
264
}
275
265
276
- func testGivenContractFilter_WhenMatchingSingleTransferEvents_OnlyMatchingSourceEventReturned_Async ( ) async {
266
+ func testGivenContractFilter_WhenMatchingSingleTransferEvents_OnlyMatchingSourceEventReturned ( ) async {
277
267
do {
278
268
let to = try ! ABIEncoder . encodeRaw ( " 0x3C1Bd6B420448Cf16A389C8b0115CCB3660bB854 " , forType: ABIRawType . FixedAddress)
279
269
let filters = [
@@ -292,7 +282,7 @@ extension EthereumClientTests {
292
282
}
293
283
}
294
284
295
- func testGivenContractFilter_WhenMatchingMultipleTransferEvents_OnlyMatchingSourceEventsReturned_Async ( ) async {
285
+ func testGivenContractFilter_WhenMatchingMultipleTransferEvents_OnlyMatchingSourceEventsReturned ( ) async {
296
286
do {
297
287
let to = try ! ABIEncoder . encode ( EthereumAddress ( " 0x3C1Bd6B420448Cf16A389C8b0115CCB3660bB854 " ) )
298
288
let filters = [
@@ -312,7 +302,7 @@ extension EthereumClientTests {
312
302
}
313
303
}
314
304
315
- func test_GivenDynamicArrayResponse_ThenCallReceivesData_Async ( ) async {
305
+ func test_GivenDynamicArrayResponse_ThenCallReceivesData ( ) async {
316
306
do {
317
307
let function = GetGuardians ( wallet: EthereumAddress ( " 0x2A6295C34b4136F2C3c1445c6A0338D784fe0ddd " ) )
318
308
@@ -323,7 +313,7 @@ extension EthereumClientTests {
323
313
}
324
314
}
325
315
326
- func test_GivenUnimplementedMethod_WhenCallingContract_ThenFailsWithExecutionError_Async ( ) async {
316
+ func test_GivenUnimplementedMethod_WhenCallingContract_ThenFailsWithExecutionError ( ) async {
327
317
do {
328
318
let function = InvalidMethodA ( param: . zero)
329
319
let _ = try await function. call (
@@ -340,7 +330,7 @@ extension EthereumClientTests {
340
330
}
341
331
}
342
332
343
- func test_GivenValidTransaction_ThenEstimatesGas_Async ( ) async {
333
+ func test_GivenValidTransaction_ThenEstimatesGas ( ) async {
344
334
do {
345
335
let function = TransferToken ( wallet: EthereumAddress ( " 0xD18dE36e6FB4a5A069f673723Fab71cc00C6CE5F " ) ,
346
336
token: EthereumAddress ( " 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE " ) ,
@@ -358,8 +348,6 @@ extension EthereumClientTests {
358
348
}
359
349
}
360
350
361
- #endif
362
-
363
351
struct GetGuardians : ABIFunction {
364
352
static let name = " getGuardians "
365
353
let contract = EthereumAddress ( " 0x25BD64224b7534f7B9e3E16dd10b6dED1A412b90 " )
0 commit comments