1- using Monero . Common ;
1+ using Monero . Common ;
22using Monero . Test . Utils ;
33using Monero . Wallet ;
44
@@ -15,7 +15,10 @@ public void TestConnectionManager()
1515 try
1616 {
1717 // start monero-wallet-rpc instances as test server connections (can also use monerod servers)
18- for ( int i = 0 ; i < 5 ; i ++ ) walletRpcs . Add ( TestUtils . StartWalletRpcProcess ( ) ) ;
18+ for ( int i = 0 ; i < 5 ; i ++ )
19+ {
20+ walletRpcs . Add ( TestUtils . StartWalletRpcProcess ( ) ) ;
21+ }
1922
2023 // create connection manager
2124 connectionManager = new MoneroConnectionManager ( ) ;
@@ -29,7 +32,8 @@ public void TestConnectionManager()
2932 connectionManager . AddConnection ( walletRpcs [ 2 ] . GetRpcConnection ( ) . SetPriority ( 2 ) ) ;
3033 connectionManager . AddConnection ( walletRpcs [ 3 ] . GetRpcConnection ( ) . SetPriority ( 2 ) ) ;
3134 connectionManager . AddConnection ( walletRpcs [ 0 ] . GetRpcConnection ( ) ) ; // default priority is lowest
32- connectionManager . AddConnection ( new MoneroRpcConnection ( walletRpcs [ 1 ] . GetRpcConnection ( ) . GetUri ( ) ) ) ; // test unauthenticated
35+ connectionManager . AddConnection (
36+ new MoneroRpcConnection ( walletRpcs [ 1 ] . GetRpcConnection ( ) . GetUri ( ) ) ) ; // test unauthenticated
3337
3438 // test connections and order
3539 List < MoneroRpcConnection > orderedConnections = connectionManager . GetRpcConnections ( ) ;
@@ -38,11 +42,15 @@ public void TestConnectionManager()
3842 Assert . True ( orderedConnections [ 2 ] == walletRpcs [ 3 ] . GetRpcConnection ( ) ) ;
3943 Assert . True ( orderedConnections [ 3 ] == walletRpcs [ 0 ] . GetRpcConnection ( ) ) ;
4044 Assert . True ( orderedConnections [ 4 ] . GetUri ( ) == walletRpcs [ 1 ] . GetRpcConnection ( ) . GetUri ( ) ) ;
41- foreach ( MoneroRpcConnection c in orderedConnections ) Assert . NotNull ( c . IsOnline ( ) ) ;
45+ foreach ( MoneroRpcConnection c in orderedConnections )
46+ {
47+ Assert . NotNull ( c . IsOnline ( ) ) ;
48+ }
4249
4350 // test getting connection by uri
4451 Assert . True ( connectionManager . HasConnection ( walletRpcs [ 0 ] . GetRpcConnection ( ) . GetUri ( ) ) ) ;
45- Assert . True ( connectionManager . GetConnection ( walletRpcs [ 0 ] . GetRpcConnection ( ) . GetUri ( ) ) == walletRpcs [ 0 ] . GetRpcConnection ( ) ) ;
52+ Assert . True ( connectionManager . GetConnection ( walletRpcs [ 0 ] . GetRpcConnection ( ) . GetUri ( ) ) ==
53+ walletRpcs [ 0 ] . GetRpcConnection ( ) ) ;
4654
4755 // test unknown connection
4856 int numExpectedChanges = 0 ;
@@ -66,7 +74,7 @@ public void TestConnectionManager()
6674 Assert . True ( listener . ChangedConnections [ listener . ChangedConnections . Count - 1 ] == null ) ;
6775
6876 // start periodically checking connection without auto switch
69- connectionManager . StartPolling ( ( ulong ) TestUtils . SYNC_PERIOD_IN_MS , false , null , null , null ) ;
77+ connectionManager . StartPolling ( ( ulong ) TestUtils . SYNC_PERIOD_IN_MS , false ) ;
7078
7179 // connect to best available connection in order of priority and response time
7280 connection = connectionManager . GetBestAvailableConnection ( ) ;
@@ -84,7 +92,10 @@ public void TestConnectionManager()
8492 Assert . True ( orderedConnections [ 2 ] == walletRpcs [ 3 ] . GetRpcConnection ( ) ) ;
8593 Assert . True ( orderedConnections [ 3 ] == walletRpcs [ 0 ] . GetRpcConnection ( ) ) ;
8694 Assert . True ( orderedConnections [ 4 ] . GetUri ( ) == walletRpcs [ 1 ] . GetRpcConnection ( ) . GetUri ( ) ) ;
87- for ( int i = 1 ; i < orderedConnections . Count ; i ++ ) Assert . Null ( orderedConnections [ i ] . IsOnline ( ) ) ;
95+ for ( int i = 1 ; i < orderedConnections . Count ; i ++ )
96+ {
97+ Assert . Null ( orderedConnections [ i ] . IsOnline ( ) ) ;
98+ }
8899
89100 // shut down prioritized servers
90101 TestUtils . StopWalletRpcProcess ( walletRpcs [ 2 ] ) ;
@@ -95,7 +106,8 @@ public void TestConnectionManager()
95106 Assert . False ( connectionManager . GetConnection ( ) . IsOnline ( ) ) ;
96107 Assert . Null ( connectionManager . GetConnection ( ) . IsAuthenticated ( ) ) ;
97108 Assert . True ( ++ numExpectedChanges == listener . ChangedConnections . Count ) ;
98- Assert . True ( listener . ChangedConnections [ listener . ChangedConnections . Count - 1 ] == connectionManager . GetConnection ( ) ) ;
109+ Assert . True ( listener . ChangedConnections [ listener . ChangedConnections . Count - 1 ] ==
110+ connectionManager . GetConnection ( ) ) ;
99111
100112 // test connection order
101113 orderedConnections = connectionManager . GetRpcConnections ( ) ;
@@ -121,11 +133,27 @@ public void TestConnectionManager()
121133 {
122134 bool ? IsOnline = orderedConnections [ i ] . IsOnline ( ) ;
123135 bool ? IsAuthenticated = orderedConnections [ i ] . IsAuthenticated ( ) ;
124- if ( i == 1 || i == 2 ) Assert . True ( IsOnline ) ;
125- else Assert . False ( IsOnline ) ;
126- if ( i == 1 ) Assert . True ( IsAuthenticated ) ;
127- else if ( i == 2 ) Assert . False ( IsAuthenticated ) ;
128- else Assert . Null ( IsAuthenticated ) ;
136+ if ( i == 1 || i == 2 )
137+ {
138+ Assert . True ( IsOnline ) ;
139+ }
140+ else
141+ {
142+ Assert . False ( IsOnline ) ;
143+ }
144+
145+ if ( i == 1 )
146+ {
147+ Assert . True ( IsAuthenticated ) ;
148+ }
149+ else if ( i == 2 )
150+ {
151+ Assert . False ( IsAuthenticated ) ;
152+ }
153+ else
154+ {
155+ Assert . Null ( IsAuthenticated ) ;
156+ }
129157 }
130158
131159 // test auto switch when disconnected
@@ -171,7 +199,12 @@ public void TestConnectionManager()
171199 Assert . True ( orderedConnections [ 2 ] == walletRpcs [ 4 ] . GetRpcConnection ( ) ) ;
172200 Assert . True ( orderedConnections [ 3 ] == walletRpcs [ 2 ] . GetRpcConnection ( ) ) ;
173201 Assert . True ( orderedConnections [ 4 ] == walletRpcs [ 3 ] . GetRpcConnection ( ) ) ;
174- for ( int i = 0 ; i < orderedConnections . Count - 1 ; i ++ ) Assert . True ( i <= 1 ? orderedConnections [ i ] . IsOnline ( ) == true : orderedConnections [ i ] . IsOnline ( ) != true ) ;
202+ for ( int i = 0 ; i < orderedConnections . Count - 1 ; i ++ )
203+ {
204+ Assert . True (
205+ i <= 1 ? orderedConnections [ i ] . IsOnline ( ) == true : orderedConnections [ i ] . IsOnline ( ) != true ) ;
206+ }
207+
175208 Assert . False ( orderedConnections [ 4 ] . IsOnline ( ) ) ;
176209
177210 // set connection to existing uri
@@ -184,13 +217,14 @@ public void TestConnectionManager()
184217
185218 if ( rpcConnection . GetType ( ) . IsInstanceOfType ( currentConnection ) )
186219 {
187- rpcConnection = ( MoneroRpcConnection ) currentConnection ;
220+ rpcConnection = currentConnection ;
188221 Assert . True ( TestUtils . WALLET_RPC_USERNAME == rpcConnection . GetUsername ( ) ) ;
189222 Assert . True ( TestUtils . WALLET_RPC_PASSWORD == rpcConnection . GetPassword ( ) ) ;
190223 }
191224
192225 Assert . True ( ++ numExpectedChanges == listener . ChangedConnections . Count ) ;
193- Assert . True ( listener . ChangedConnections [ listener . ChangedConnections . Count - 1 ] == walletRpcs [ 0 ] . GetRpcConnection ( ) ) ;
226+ Assert . True ( listener . ChangedConnections [ listener . ChangedConnections . Count - 1 ] ==
227+ walletRpcs [ 0 ] . GetRpcConnection ( ) ) ;
194228
195229 // set connection to new uri
196230 connectionManager . StopPolling ( ) ;
@@ -222,22 +256,28 @@ public void TestConnectionManager()
222256 connectionManager . SetConnection ( null ) ;
223257 Assert . False ( connectionManager . IsConnected ( ) ) ;
224258 Assert . True ( ++ numExpectedChanges == listener . ChangedConnections . Count ) ;
225- connectionManager . StartPolling ( ( ulong ) TestUtils . SYNC_PERIOD_IN_MS , null , null , MoneroConnectionManager . PollType . CURRENT , null ) ;
259+ connectionManager . StartPolling ( ( ulong ) TestUtils . SYNC_PERIOD_IN_MS , null , null ,
260+ MoneroConnectionManager . PollType . CURRENT ) ;
226261 Thread . Sleep ( TestUtils . AUTO_CONNECT_TIMEOUT_MS ) ;
227262 Assert . True ( connectionManager . IsConnected ( ) ) ;
228263 Assert . True ( ++ numExpectedChanges == listener . ChangedConnections . Count ) ;
229264
230265 // test polling all connections
231266 connectionManager . SetConnection ( null ) ;
232267 Assert . True ( ++ numExpectedChanges == listener . ChangedConnections . Count ) ;
233- connectionManager . StartPolling ( ( ulong ) TestUtils . SYNC_PERIOD_IN_MS , null , null , MoneroConnectionManager . PollType . ALL , null ) ;
268+ connectionManager . StartPolling ( ( ulong ) TestUtils . SYNC_PERIOD_IN_MS , null , null ,
269+ MoneroConnectionManager . PollType . ALL ) ;
234270 Thread . Sleep ( TestUtils . AUTO_CONNECT_TIMEOUT_MS ) ;
235271 Assert . True ( connectionManager . IsConnected ( ) ) ;
236272 Assert . True ( ++ numExpectedChanges == listener . ChangedConnections . Count ) ;
237273
238274 // shut down all connections
239275 connection = connectionManager . GetConnection ( ) ;
240- foreach ( MoneroWalletRpc walletRpc in walletRpcs ) TestUtils . StopWalletRpcProcess ( walletRpc ) ;
276+ foreach ( MoneroWalletRpc walletRpc in walletRpcs )
277+ {
278+ TestUtils . StopWalletRpcProcess ( walletRpc ) ;
279+ }
280+
241281 Thread . Sleep ( TestUtils . SYNC_PERIOD_IN_MS + 100 ) ;
242282 Assert . False ( connection . IsOnline ( ) ) ;
243283 Assert . True ( ++ numExpectedChanges == listener . ChangedConnections . Count ) ;
0 commit comments