11using Monero . Common ;
22using Monero . Test . Utils ;
33
4- namespace Monero . Test
4+ namespace Monero . Test ;
5+
6+ public class TestMoneroRpcConnection
57{
6- public class TestMoneroRpcConnection
8+ // Can copy connection
9+ [ Fact ]
10+ public void TestClone ( )
711 {
8- // Can copy connection
9- [ Fact ]
10- public void TestClone ( )
11- {
12- var connection = new MoneroRpcConnection ( "test" , "user" , "pass123" , "test_zmq" , 2 ) ;
12+ var connection = new MoneroRpcConnection ( "test" , "user" , "pass123" , "test_zmq" , 2 ) ;
1313
14- var copy = connection . Clone ( ) ;
15-
16- Assert . True ( connection . Equals ( copy ) ) ;
14+ var copy = connection . Clone ( ) ;
1715
18- connection = new MoneroRpcConnection ( TestUtils . DAEMON_RPC_URI ) ;
19-
20- TestConnection ( connection , TestUtils . DAEMON_RPC_URI , true ) ;
16+ Assert . True ( connection . Equals ( copy ) ) ;
2117
22- copy = connection . Clone ( ) ;
18+ connection = new MoneroRpcConnection ( TestUtils . DAEMON_RPC_URI ) ;
2319
24- Assert . True ( connection . Equals ( copy ) ) ;
25- }
20+ TestConnection ( connection , TestUtils . DAEMON_RPC_URI , true ) ;
2621
27- // Can connect to node
28- [ Fact ]
29- public void TestNodeRpcConnection ( )
30- {
31- var connection = new MoneroRpcConnection ( TestUtils . DAEMON_RPC_URI ) ;
32-
33- TestConnection ( connection , TestUtils . DAEMON_RPC_URI , true ) ;
34- }
35-
36- // Can connect to wallet
37- [ Fact ]
38- public void TestWalletRpcConnection ( )
39- {
40- var connection = new MoneroRpcConnection ( TestUtils . WALLET_RPC_URI ) ;
41-
42- TestConnection ( connection , TestUtils . WALLET_RPC_URI , true ) ;
43- }
44-
45- // Test invalid url
46- [ Fact ]
47- public void TestInvalidConnection ( )
48- {
49- var connection = new MoneroRpcConnection ( "" ) ;
22+ copy = connection . Clone ( ) ;
5023
51- TestConnection ( connection , "" , false ) ;
52- }
53-
54- // Can send request to RPC
55- [ Fact ]
56- public void TestSendRequest ( )
57- {
58- // Setup connection
24+ Assert . True ( connection . Equals ( copy ) ) ;
25+ }
26+
27+ // Can connect to node
28+ [ Fact ]
29+ public void TestNodeRpcConnection ( )
30+ {
31+ var connection = new MoneroRpcConnection ( TestUtils . DAEMON_RPC_URI ) ;
32+
33+ TestConnection ( connection , TestUtils . DAEMON_RPC_URI , true ) ;
34+ }
35+
36+ // Can connect to wallet
37+ [ Fact ]
38+ public void TestWalletRpcConnection ( )
39+ {
40+ var connection = new MoneroRpcConnection ( TestUtils . WALLET_RPC_URI ) ;
41+
42+ TestConnection ( connection , TestUtils . WALLET_RPC_URI , true ) ;
43+ }
44+
45+ // Test invalid url
46+ [ Fact ]
47+ public void TestInvalidConnection ( )
48+ {
49+ var connection = new MoneroRpcConnection ( "" ) ;
5950
60- var connection = new MoneroRpcConnection ( TestUtils . DAEMON_RPC_URI ) ;
51+ TestConnection ( connection , "" , false ) ;
52+ }
6153
62- TestConnection ( connection , TestUtils . DAEMON_RPC_URI , true ) ;
54+ // Can send request to RPC
55+ [ Fact ]
56+ public void TestSendRequest ( )
57+ {
58+ // Setup connection
6359
64- // Test monerod JSON request
60+ var connection = new MoneroRpcConnection ( TestUtils . DAEMON_RPC_URI ) ;
6561
66- var jsonResponse = connection . SendJsonRequest ( "get_info" ) ;
62+ TestConnection ( connection , TestUtils . DAEMON_RPC_URI , true ) ;
6763
68- Assert . NotNull ( jsonResponse ) ;
69- Assert . Null ( jsonResponse . Error ) ;
70- Assert . NotNull ( jsonResponse . Result ) ;
64+ // Test monerod JSON request
7165
72- // Test monerod PATH request
66+ var jsonResponse = connection . SendJsonRequest ( "get_info" ) ;
7367
74- var pathResponse = connection . SendPathRequest ( "get_info" ) ;
68+ Assert . NotNull ( jsonResponse ) ;
69+ Assert . Null ( jsonResponse . Error ) ;
70+ Assert . NotNull ( jsonResponse . Result ) ;
7571
76- Assert . NotNull ( pathResponse ) ;
77- Assert . Null ( pathResponse . GetValueOrDefault ( "error" ) ) ;
72+ // Test monerod PATH request
7873
79- // Test monerod BINARY request
74+ var pathResponse = connection . SendPathRequest ( "get_info" ) ;
8075
81- // TODO implement MoneroRpcConnection.SendBinaryRequest()
76+ Assert . NotNull ( pathResponse ) ;
77+ Assert . Null ( pathResponse . GetValueOrDefault ( "error" ) ) ;
8278
83- //var binaryResponse = connection.SendBinaryRequest("get_outs.bin");
84- //Assert.NotNull(binaryResponse);
85- }
79+ // Test monerod BINARY request
8680
87- private static void TestConnection ( MoneroRpcConnection ? connection , string ? uri , bool online )
81+ // TODO implement MoneroRpcConnection.SendBinaryRequest()
82+
83+ //var binaryResponse = connection.SendBinaryRequest("get_outs.bin");
84+ //Assert.NotNull(binaryResponse);
85+ }
86+
87+ private static void TestConnection ( MoneroRpcConnection ? connection , string ? uri , bool online )
88+ {
89+ Assert . NotNull ( connection ) ;
90+
91+ if ( online )
92+ {
93+ Assert . NotNull ( uri ) ;
94+ Assert . NotEmpty ( uri ) ;
95+ Assert . Equal ( uri , connection . GetUri ( ) ) ;
96+ Assert . True ( connection . IsClearnet ( ) ) ;
97+ Assert . False ( connection . IsOnion ( ) ) ;
98+ Assert . False ( connection . IsI2P ( ) ) ;
99+ Assert . True ( connection . CheckConnection ( ) ) ;
100+ Assert . True ( connection . IsOnline ( ) ) ;
101+ Assert . True ( connection . IsAuthenticated ( ) ) ;
102+ Assert . True ( connection . IsConnected ( ) ) ;
103+ }
104+ else
88105 {
89- Assert . NotNull ( connection ) ;
90-
91- if ( online )
92- {
93- Assert . NotNull ( uri ) ;
94- Assert . NotEmpty ( uri ) ;
95- Assert . Equal ( uri , connection . GetUri ( ) ) ;
96- Assert . True ( connection . IsClearnet ( ) ) ;
97- Assert . False ( connection . IsOnion ( ) ) ;
98- Assert . False ( connection . IsI2P ( ) ) ;
99- Assert . True ( connection . CheckConnection ( ) ) ;
100- Assert . True ( connection . IsOnline ( ) ) ;
101- Assert . True ( connection . IsAuthenticated ( ) ) ;
102- Assert . True ( connection . IsConnected ( ) ) ;
103- }
104- else
105- {
106- Assert . Equal ( uri , connection . GetUri ( ) ) ;
107- Assert . False ( connection . IsClearnet ( ) ) ;
108- Assert . False ( connection . IsOnion ( ) ) ;
109- Assert . False ( connection . IsI2P ( ) ) ;
110- Assert . True ( connection . CheckConnection ( ) ) ;
111- Assert . False ( connection . IsOnline ( ) ) ;
112- Assert . Null ( connection . IsAuthenticated ( ) ) ;
113- Assert . False ( connection . IsConnected ( ) ) ;
114- }
106+ Assert . Equal ( uri , connection . GetUri ( ) ) ;
107+ Assert . False ( connection . IsClearnet ( ) ) ;
108+ Assert . False ( connection . IsOnion ( ) ) ;
109+ Assert . False ( connection . IsI2P ( ) ) ;
110+ Assert . True ( connection . CheckConnection ( ) ) ;
111+ Assert . False ( connection . IsOnline ( ) ) ;
112+ Assert . Null ( connection . IsAuthenticated ( ) ) ;
113+ Assert . False ( connection . IsConnected ( ) ) ;
115114 }
116-
117115 }
118- }
116+
117+ }
0 commit comments