@@ -52,4 +52,74 @@ class RelaySelectorWrapperTests: XCTestCase {
52
52
let selectedRelays = try wrapper. selectRelays ( with: RelayConstraints ( ) , connectionAttemptCount: 0 )
53
53
XCTAssertNotNil ( selectedRelays. entry)
54
54
}
55
+
56
+ func testCanSelectRelayWithMultihopOnAndDaitaOn( ) throws {
57
+ let wrapper = RelaySelectorWrapper (
58
+ relayCache: relayCache,
59
+ multihopUpdater: multihopUpdater
60
+ )
61
+
62
+ multihopStateListener. onNewMultihop ? ( . on)
63
+ wrapper. setDatita ( state: . on)
64
+
65
+ let constraints = RelayConstraints (
66
+ entryLocations: . only( UserSelectedRelays ( locations: [ . country( " es " ) ] ) ) , // Relay with DAITA.
67
+ exitLocations: . only( UserSelectedRelays ( locations: [ . country( " us " ) ] ) )
68
+ )
69
+
70
+ XCTAssertNoThrow ( try wrapper. selectRelays ( with: constraints, connectionAttemptCount: 0 ) )
71
+ }
72
+
73
+ func testCannotSelectRelayWithMultihopOnAndDaitaOn( ) throws {
74
+ let wrapper = RelaySelectorWrapper (
75
+ relayCache: relayCache,
76
+ multihopUpdater: multihopUpdater
77
+ )
78
+
79
+ multihopStateListener. onNewMultihop ? ( . on)
80
+ wrapper. setDatita ( state: . on)
81
+
82
+ let constraints = RelayConstraints (
83
+ entryLocations: . only( UserSelectedRelays ( locations: [ . country( " se " ) ] ) ) , // Relay without DAITA.
84
+ exitLocations: . only( UserSelectedRelays ( locations: [ . country( " us " ) ] ) )
85
+ )
86
+
87
+ XCTAssertThrowsError ( try wrapper. selectRelays ( with: constraints, connectionAttemptCount: 0 ) )
88
+ }
89
+
90
+ func testCanSelectRelayWithMultihopOffAndDaitaOn( ) throws {
91
+ let wrapper = RelaySelectorWrapper (
92
+ relayCache: relayCache,
93
+ multihopUpdater: multihopUpdater
94
+ )
95
+
96
+ multihopStateListener. onNewMultihop ? ( . off)
97
+ wrapper. setDatita ( state: . on)
98
+
99
+ let constraints = RelayConstraints (
100
+ exitLocations: . only( UserSelectedRelays ( locations: [ . country( " es " ) ] ) ) // Relay with DAITA.
101
+ )
102
+
103
+ let selectedRelays = try wrapper. selectRelays ( with: constraints, connectionAttemptCount: 0 )
104
+ XCTAssertNil ( selectedRelays. entry)
105
+ }
106
+
107
+ // If DAITA is enabled and no supported relays are found, we should try to find the nearest
108
+ // available relay that supports DAITA and use it as entry in a multihop selection.
109
+ func testCanSelectRelayWithMultihopOffAndDaitaOnThroughMultihop( ) throws {
110
+ let wrapper = RelaySelectorWrapper (
111
+ relayCache: relayCache,
112
+ multihopUpdater: multihopUpdater
113
+ )
114
+
115
+ multihopStateListener. onNewMultihop ? ( . off)
116
+ wrapper. setDatita ( state: . on)
117
+
118
+ let constraints = RelayConstraints (
119
+ exitLocations: . only( UserSelectedRelays ( locations: [ . country( " se " ) ] ) ) // Relay without DAITA.
120
+ )
121
+
122
+ let selectedRelays = try wrapper. selectRelays ( with: constraints, connectionAttemptCount: 0 )
123
+ XCTAssertNotNil ( selectedRelays. entry)
124
+ }
55
125
}
0 commit comments