@@ -138,4 +138,74 @@ class RelaySelectorWrapperTests: XCTestCase {
138
138
let selectedRelays = try wrapper. selectRelays ( connectionAttemptCount: 0 )
139
139
XCTAssertNotNil ( selectedRelays. entry)
140
140
}
141
+
142
+ func testCanSelectRelayWithMultihopOnAndDaitaOn( ) throws {
143
+ let wrapper = RelaySelectorWrapper (
144
+ relayCache: relayCache,
145
+ multihopUpdater: multihopUpdater
146
+ )
147
+
148
+ multihopStateListener. onNewMultihop ? ( . on)
149
+ wrapper. setDaita ( state: . on)
150
+
151
+ let constraints = RelayConstraints (
152
+ entryLocations: . only( UserSelectedRelays ( locations: [ . country( " es " ) ] ) ) , // Relay with DAITA.
153
+ exitLocations: . only( UserSelectedRelays ( locations: [ . country( " us " ) ] ) )
154
+ )
155
+
156
+ XCTAssertNoThrow ( try wrapper. selectRelays ( with: constraints, connectionAttemptCount: 0 ) )
157
+ }
158
+
159
+ func testCannotSelectRelayWithMultihopOnAndDaitaOn( ) throws {
160
+ let wrapper = RelaySelectorWrapper (
161
+ relayCache: relayCache,
162
+ multihopUpdater: multihopUpdater
163
+ )
164
+
165
+ multihopStateListener. onNewMultihop ? ( . on)
166
+ wrapper. setDaita ( state: . on)
167
+
168
+ let constraints = RelayConstraints (
169
+ entryLocations: . only( UserSelectedRelays ( locations: [ . country( " se " ) ] ) ) , // Relay without DAITA.
170
+ exitLocations: . only( UserSelectedRelays ( locations: [ . country( " us " ) ] ) )
171
+ )
172
+
173
+ XCTAssertThrowsError ( try wrapper. selectRelays ( with: constraints, connectionAttemptCount: 0 ) )
174
+ }
175
+
176
+ func testCanSelectRelayWithMultihopOffAndDaitaOn( ) throws {
177
+ let wrapper = RelaySelectorWrapper (
178
+ relayCache: relayCache,
179
+ multihopUpdater: multihopUpdater
180
+ )
181
+
182
+ multihopStateListener. onNewMultihop ? ( . off)
183
+ wrapper. setDaita ( state: . on)
184
+
185
+ let constraints = RelayConstraints (
186
+ exitLocations: . only( UserSelectedRelays ( locations: [ . country( " es " ) ] ) ) // Relay with DAITA.
187
+ )
188
+
189
+ let selectedRelays = try wrapper. selectRelays ( with: constraints, connectionAttemptCount: 0 )
190
+ XCTAssertNil ( selectedRelays. entry)
191
+ }
192
+
193
+ // If DAITA is enabled and no supported relays are found, we should try to find the nearest
194
+ // available relay that supports DAITA and use it as entry in a multihop selection.
195
+ func testCanSelectRelayWithMultihopOffAndDaitaOnThroughMultihop( ) throws {
196
+ let wrapper = RelaySelectorWrapper (
197
+ relayCache: relayCache,
198
+ multihopUpdater: multihopUpdater
199
+ )
200
+
201
+ multihopStateListener. onNewMultihop ? ( . off)
202
+ wrapper. setDaita ( state: . on)
203
+
204
+ let constraints = RelayConstraints (
205
+ exitLocations: . only( UserSelectedRelays ( locations: [ . country( " se " ) ] ) ) // Relay without DAITA.
206
+ )
207
+
208
+ let selectedRelays = try wrapper. selectRelays ( with: constraints, connectionAttemptCount: 0 )
209
+ XCTAssertNotNil ( selectedRelays. entry)
210
+ }
141
211
}
0 commit comments