@@ -24,184 +24,7 @@ class ENSTests: XCTestCase {
24
24
XCTAssertEqual ( nameHash, " 0x3e58ef7a2e196baf0b9d36a65cc590ac9edafb3395b7cdeb8f39206049b4534c " )
25
25
}
26
26
27
- func testGivenRopstenRegistry_WhenExistingDomainName_ResolvesOwnerAddressCorrectly( ) {
28
- let expect = expectation ( description: " Get the ENS owner " )
29
-
30
- do {
31
- let function = ENSContracts . ENSRegistryFunctions. owner ( contract: ENSContracts . RopstenAddress, _node: EthereumNameService . nameHash ( name: " test " ) . web3. hexData ?? Data ( ) )
32
-
33
- let tx = try function. transaction ( )
34
-
35
- client? . eth_call ( tx, block: . Latest, completion: { ( error, dataStr) in
36
- guard let dataStr = dataStr else {
37
- XCTFail ( )
38
- expect. fulfill ( )
39
- return
40
- }
41
- let owner = String ( dataStr [ dataStr. index ( dataStr. endIndex, offsetBy: - 40 ) ... ] )
42
- XCTAssertEqual ( owner. web3. noHexPrefix, " 09b5bd82f3351a4c8437fc6d7772a9e6cd5d25a1 " )
43
- expect. fulfill ( )
44
- } )
45
-
46
- } catch {
47
- XCTFail ( )
48
- expect. fulfill ( )
49
- }
50
-
51
- waitForExpectations ( timeout: 20 )
52
- }
53
-
54
- func testGivenRopstenRegistry_WhenExistingAddress_ThenResolvesCorrectly( ) {
55
- let expect = expectation ( description: " Get the ENS address " )
56
-
57
- let nameService = EthereumNameService ( client: client!)
58
- nameService. resolve ( address: EthereumAddress ( " 0xb0b874220ff95d62a676f58d186c832b3e6529c8 " ) , completion: { ( error, ens) in
59
- XCTAssertEqual ( " julien.argent.test " , ens)
60
- expect. fulfill ( )
61
- } )
62
-
63
- waitForExpectations ( timeout: 20 )
64
- }
65
-
66
- func testGivenRopstenRegistry_WhenNotExistingAddress_ThenFailsCorrectly( ) {
67
- let expect = expectation ( description: " Get the ENS address " )
68
-
69
- let nameService = EthereumNameService ( client: client!)
70
- nameService. resolve ( address: EthereumAddress ( " 0xb0b874220ff95d62a676f58d186c832b3e6529c9 " ) , completion: { ( error, ens) in
71
- XCTAssertNil ( ens)
72
- XCTAssertEqual ( error, . ensUnknown)
73
- expect. fulfill ( )
74
- } )
75
-
76
- waitForExpectations ( timeout: 20 )
77
- }
78
-
79
- func testGivenCustomRegistry_WhenNotExistingAddress_ThenResolvesFailsCorrectly( ) {
80
- let expect = expectation ( description: " Get the ENS address " )
81
-
82
- let nameService = EthereumNameService ( client: client!, registryAddress: EthereumAddress ( " 0x7D7C04B7A05539a92541105806e0971E45969F85 " ) )
83
- nameService. resolve ( address: EthereumAddress ( " 0xb0b874220ff95d62a676f58d186c832b3e6529c9 " ) , completion: { ( error, ens) in
84
- XCTAssertNil ( ens)
85
- XCTAssertEqual ( error, . ensUnknown)
86
- expect. fulfill ( )
87
- } )
88
-
89
- waitForExpectations ( timeout: 20 )
90
- }
91
-
92
- func testGivenRopstenRegistry_WhenExistingENS_ThenResolvesAddressCorrectly( ) {
93
- let expect = expectation ( description: " Get the ENS reverse lookup address " )
94
-
95
- let nameService = EthereumNameService ( client: client!)
96
- nameService. resolve ( ens: " julien.argent.test " , completion: { ( error, ens) in
97
- XCTAssertEqual ( EthereumAddress ( " 0xb0b874220ff95d62a676f58d186c832b3e6529c8 " ) , ens)
98
- expect. fulfill ( )
99
- } )
100
-
101
- waitForExpectations ( timeout: 20 )
102
- }
103
-
104
- func testGivenRopstenRegistry_WhenInvalidENS_ThenErrorsRequest( ) {
105
- let expect = expectation ( description: " Get the ENS reverse lookup address " )
106
-
107
- let nameService = EthereumNameService ( client: client!)
108
- nameService. resolve ( ens: " **somegarbage)_!! " , completion: { ( error, ens) in
109
- XCTAssertNil ( ens)
110
- XCTAssertEqual ( error, . ensUnknown)
111
- expect. fulfill ( )
112
- } )
113
-
114
- waitForExpectations ( timeout: 20 )
115
- }
116
-
117
- func testGivenCustomRegistry_WhenInvalidENS_ThenErrorsRequest( ) {
118
- let expect = expectation ( description: " Get the ENS reverse lookup address " )
119
-
120
- let nameService = EthereumNameService ( client: client!, registryAddress: EthereumAddress ( " 0x7D7C04B7A05539a92541105806e0971E45969F85 " ) )
121
- nameService. resolve ( ens: " **somegarbage)_!! " , completion: { ( error, ens) in
122
- XCTAssertNil ( ens)
123
- XCTAssertEqual ( error, . ensUnknown)
124
- expect. fulfill ( )
125
- } )
126
-
127
- waitForExpectations ( timeout: 20 )
128
- }
129
-
130
- func testGivenRopstenRegistry_ThenResolvesMultipleAddressesInOneCall( ) {
131
- let expect = expectation ( description: " Get the ENS reverse lookup address " )
132
-
133
- let nameService = EthereumNameService ( client: client!)
134
-
135
- var results : [ EthereumNameService . ResolveOutput < String > ] ?
136
-
137
- nameService. resolve ( addresses: [
138
- EthereumAddress ( " 0xb0b874220ff95d62a676f58d186c832b3e6529c8 " ) ,
139
- EthereumAddress ( " 0x09b5bd82f3351a4c8437fc6d7772a9e6cd5d25a1 " ) ,
140
- EthereumAddress ( " 0x7e691d7ffb007abe91d8a24d7f22fc74307dab06 " )
141
-
142
- ] ) { result in
143
- switch result {
144
- case . success( let resolutions) :
145
- results = resolutions. map { $0. output }
146
- case . failure:
147
- break
148
- }
149
- expect. fulfill ( )
150
- }
151
-
152
- waitForExpectations ( timeout: 5 )
153
-
154
- XCTAssertEqual (
155
- results,
156
- [
157
- . resolved( " julien.argent.test " ) ,
158
- . couldNotBeResolved( . ensUnknown) ,
159
- . resolved( " davidtests.argent.xyz " )
160
- ]
161
- )
162
- }
163
-
164
- func testGivenRopstenRegistry_ThenResolvesMultipleNamesInOneCall( ) {
165
- let expect = expectation ( description: " Get the ENS reverse lookup address " )
166
-
167
- let nameService = EthereumNameService ( client: client!)
168
-
169
- var results : [ EthereumNameService . ResolveOutput < EthereumAddress > ] ?
170
-
171
- nameService. resolve ( names: [
172
- " julien.argent.test " ,
173
- " davidtests.argent.xyz " ,
174
- " somefakeens.argent.xyz "
175
-
176
- ] ) { result in
177
- switch result {
178
- case . success( let resolutions) :
179
- results = resolutions. map { $0. output }
180
- case . failure:
181
- break
182
- }
183
- expect. fulfill ( )
184
- }
185
-
186
- waitForExpectations ( timeout: 5 )
187
-
188
- XCTAssertEqual (
189
- results,
190
- [
191
- . resolved( EthereumAddress ( " 0xb0b874220ff95d62a676f58d186c832b3e6529c8 " ) ) ,
192
- . resolved( EthereumAddress ( " 0x7e691d7ffb007abe91d8a24d7f22fc74307dab06 " ) ) ,
193
- . couldNotBeResolved( . ensUnknown)
194
- ]
195
- )
196
- }
197
- }
198
-
199
-
200
- #if compiler(>=5.5) && canImport(_Concurrency)
201
-
202
- @available ( macOS 10 . 15 , iOS 13 , watchOS 6 , tvOS 13 , * )
203
- extension ENSTests {
204
- func testGivenRopstenRegistry_WhenExistingDomainName_ResolvesOwnerAddressCorrectly_Async( ) async {
27
+ func testGivenRopstenRegistry_WhenExistingDomainName_ResolvesOwnerAddressCorrectly( ) async {
205
28
do {
206
29
let function = ENSContracts . ENSRegistryFunctions. owner ( contract: ENSContracts . RopstenAddress, _node: EthereumNameService . nameHash ( name: " test " ) . web3. hexData ?? Data ( ) )
207
30
@@ -220,67 +43,85 @@ extension ENSTests {
220
43
}
221
44
}
222
45
223
- func testGivenRopstenRegistry_WhenExistingAddress_ThenResolvesCorrectly_Async ( ) async {
46
+ func testGivenRopstenRegistry_WhenExistingAddress_ThenResolvesCorrectly ( ) async {
224
47
do {
225
48
let nameService = EthereumNameService ( client: client!)
226
- let ens = try await nameService. resolve ( address: EthereumAddress ( " 0xb0b874220ff95d62a676f58d186c832b3e6529c8 " ) )
49
+ let ens = try await nameService. resolve (
50
+ address: EthereumAddress ( " 0xb0b874220ff95d62a676f58d186c832b3e6529c8 " ) ,
51
+ mode: . onchain
52
+ )
227
53
XCTAssertEqual ( " julien.argent.test " , ens)
228
54
} catch {
229
55
XCTFail ( " Expected ens but failed \( error) . " )
230
56
}
231
57
}
232
58
233
- func testGivenRopstenRegistry_WhenNotExistingAddress_ThenFailsCorrectly_Async ( ) async {
59
+ func testGivenRopstenRegistry_WhenNotExistingAddress_ThenFailsCorrectly ( ) async {
234
60
do {
235
61
let nameService = EthereumNameService ( client: client!)
236
- _ = try await nameService. resolve ( address: EthereumAddress ( " 0xb0b874220ff95d62a676f58d186c832b3e6529c9 " ) )
62
+ _ = try await nameService. resolve (
63
+ address: EthereumAddress ( " 0xb0b874220ff95d62a676f58d186c832b3e6529c9 " ) ,
64
+ mode: . onchain
65
+ )
237
66
XCTFail ( " Expected to throw while awaiting, but succeeded " )
238
67
} catch {
239
68
XCTAssertEqual ( error as? EthereumNameServiceError , . ensUnknown)
240
69
}
241
70
}
242
71
243
- func testGivenCustomRegistry_WhenNotExistingAddress_ThenResolvesFailsCorrectly_Async ( ) async {
72
+ func testGivenCustomRegistry_WhenNotExistingAddress_ThenResolvesFailsCorrectly ( ) async {
244
73
do {
245
74
let nameService = EthereumNameService ( client: client!, registryAddress: EthereumAddress ( " 0x7D7C04B7A05539a92541105806e0971E45969F85 " ) )
246
- _ = try await nameService. resolve ( address: EthereumAddress ( " 0xb0b874220ff95d62a676f58d186c832b3e6529c9 " ) )
75
+ _ = try await nameService. resolve (
76
+ address: EthereumAddress ( " 0xb0b874220ff95d62a676f58d186c832b3e6529c9 " ) ,
77
+ mode: . onchain
78
+ )
247
79
XCTFail ( " Expected to throw while awaiting, but succeeded " )
248
80
} catch {
249
81
XCTAssertEqual ( error as? EthereumNameServiceError , . ensUnknown)
250
82
}
251
83
}
252
84
253
- func testGivenRopstenRegistry_WhenExistingENS_ThenResolvesAddressCorrectly_Async ( ) async {
85
+ func testGivenRopstenRegistry_WhenExistingENS_ThenResolvesAddressCorrectly ( ) async {
254
86
do {
255
87
let nameService = EthereumNameService ( client: client!)
256
- let ens = try await nameService. resolve ( ens: " julien.argent.test " )
88
+ let ens = try await nameService. resolve (
89
+ ens: " julien.argent.test " ,
90
+ mode: . onchain
91
+ )
257
92
XCTAssertEqual ( EthereumAddress ( " 0xb0b874220ff95d62a676f58d186c832b3e6529c8 " ) , ens)
258
93
} catch {
259
94
XCTFail ( " Expected ens but failed \( error) . " )
260
95
}
261
96
}
262
97
263
- func testGivenRopstenRegistry_WhenInvalidENS_ThenErrorsRequest_Async ( ) async {
98
+ func testGivenRopstenRegistry_WhenInvalidENS_ThenErrorsRequest ( ) async {
264
99
do {
265
100
let nameService = EthereumNameService ( client: client!)
266
- _ = try await nameService. resolve ( ens: " **somegarbage)_!! " )
101
+ _ = try await nameService. resolve (
102
+ ens: " **somegarbage)_!! " ,
103
+ mode: . onchain
104
+ )
267
105
XCTFail ( " Expected to throw while awaiting, but succeeded " )
268
106
} catch {
269
107
XCTAssertEqual ( error as? EthereumNameServiceError , . ensUnknown)
270
108
}
271
109
}
272
110
273
- func testGivenCustomRegistry_WhenInvalidENS_ThenErrorsRequest_Async ( ) async {
111
+ func testGivenCustomRegistry_WhenInvalidENS_ThenErrorsRequest ( ) async {
274
112
do {
275
113
let nameService = EthereumNameService ( client: client!, registryAddress: EthereumAddress ( " 0x7D7C04B7A05539a92541105806e0971E45969F85 " ) )
276
- _ = try await nameService. resolve ( ens: " **somegarbage)_!! " )
114
+ _ = try await nameService. resolve (
115
+ ens: " **somegarbage)_!! " ,
116
+ mode: . onchain
117
+ )
277
118
XCTFail ( " Expected to throw while awaiting, but succeeded " )
278
119
} catch {
279
120
XCTAssertEqual ( error as? EthereumNameServiceError , . ensUnknown)
280
121
}
281
122
}
282
123
283
- func testGivenRopstenRegistry_ThenResolvesMultipleAddressesInOneCall_Async ( ) async {
124
+ func testGivenRopstenRegistry_ThenResolvesMultipleAddressesInOneCall ( ) async {
284
125
let nameService = EthereumNameService ( client: client!)
285
126
286
127
var results : [ EthereumNameService . ResolveOutput < String > ] ?
@@ -308,7 +149,7 @@ extension ENSTests {
308
149
)
309
150
}
310
151
311
- func testGivenRopstenRegistry_ThenResolvesMultipleNamesInOneCall_Async ( ) async {
152
+ func testGivenRopstenRegistry_ThenResolvesMultipleNamesInOneCall ( ) async {
312
153
let nameService = EthereumNameService ( client: client!)
313
154
314
155
var results : [ EthereumNameService . ResolveOutput < EthereumAddress > ] ?
@@ -337,4 +178,3 @@ extension ENSTests {
337
178
}
338
179
}
339
180
340
- #endif
0 commit comments