Skip to content

Commit f5a3534

Browse files
committed
Clean nested blocks fix abstract constructors remove shadowing
1 parent 4c90d70 commit f5a3534

13 files changed

Lines changed: 247 additions & 135 deletions

Monero.IntegrationTests/TestMoneroConnectionManager.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,10 @@ public void TestConnectionManager()
305305
{
306306
TestUtils.StopWalletRpcProcess(wallet);
307307
}
308-
catch { }
308+
catch
309+
{
310+
// ignore
311+
}
309312
}
310313
}
311314
}

Monero.IntegrationTests/TestMoneroDaemonRpc.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1244,7 +1244,10 @@ public void TestGetMiningStatus()
12441244
{
12451245
// stop mining at end of test
12461246
try { daemon.StopMining(); }
1247-
catch (MoneroError e) { }
1247+
catch (MoneroError e)
1248+
{
1249+
// ignore
1250+
}
12481251
}
12491252
}
12501253

Monero.IntegrationTests/TestMoneroWalletCommon.cs

Lines changed: 67 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -49,27 +49,27 @@ public void TestCreateWalletRandom()
4949
try
5050
{
5151
// create random wallet
52-
MoneroWallet wallet = CreateWallet(new MoneroWalletConfig());
53-
string path = wallet.GetPath();
52+
MoneroWallet moneroWallet = CreateWallet(new MoneroWalletConfig());
53+
string path = moneroWallet.GetPath();
5454
Exception? e2 = null;
5555
try
5656
{
57-
MoneroUtils.ValidateAddress(wallet.GetPrimaryAddress());
58-
MoneroUtils.ValidatePrivateViewKey(wallet.GetPrivateViewKey());
59-
MoneroUtils.ValidatePrivateSpendKey(wallet.GetPrivateSpendKey());
60-
MoneroUtils.ValidateMnemonic(wallet.GetSeed());
61-
if (wallet.GetWalletType() != MoneroWalletType.RPC)
57+
MoneroUtils.ValidateAddress(moneroWallet.GetPrimaryAddress());
58+
MoneroUtils.ValidatePrivateViewKey(moneroWallet.GetPrivateViewKey());
59+
MoneroUtils.ValidatePrivateSpendKey(moneroWallet.GetPrivateSpendKey());
60+
MoneroUtils.ValidateMnemonic(moneroWallet.GetSeed());
61+
if (moneroWallet.GetWalletType() != MoneroWalletType.RPC)
6262
{
6363
Assert.True(MoneroWallet.DEFAULT_LANGUAGE ==
64-
wallet.GetSeedLanguage()); // TODO monero-wallet-rpc: get seed language
64+
moneroWallet.GetSeedLanguage()); // TODO monero-wallet-rpc: get seed language
6565
}
6666
}
6767
catch (Exception e)
6868
{
6969
e2 = e;
7070
}
7171

72-
CloseWallet(wallet);
72+
CloseWallet(moneroWallet);
7373
if (e2 != null)
7474
{
7575
throw e2;
@@ -121,47 +121,47 @@ public void TestCreateWalletFromSeed()
121121
string privateViewKey = this.wallet.GetPrivateViewKey();
122122
string privateSpendKey = this.wallet.GetPrivateSpendKey();
123123

124-
// recreate test wallet from seed
125-
MoneroWallet wallet = CreateWallet(new MoneroWalletConfig().SetSeed(TestUtils.SEED)
124+
// recreate the test wallet from seed
125+
MoneroWallet moneroWallet = CreateWallet(new MoneroWalletConfig().SetSeed(TestUtils.SEED)
126126
.SetRestoreHeight(TestUtils.FIRST_RECEIVE_HEIGHT));
127-
string path = wallet.GetPath();
127+
string path = moneroWallet.GetPath();
128128
Exception? e2 = null;
129129
try
130130
{
131-
Assert.True(primaryAddress == wallet.GetPrimaryAddress());
132-
Assert.True(privateViewKey == wallet.GetPrivateViewKey());
133-
Assert.True(privateSpendKey == wallet.GetPrivateSpendKey());
134-
Assert.True(TestUtils.SEED == wallet.GetSeed());
135-
if (wallet.GetWalletType() != MoneroWalletType.RPC)
131+
Assert.True(primaryAddress == moneroWallet.GetPrimaryAddress());
132+
Assert.True(privateViewKey == moneroWallet.GetPrivateViewKey());
133+
Assert.True(privateSpendKey == moneroWallet.GetPrivateSpendKey());
134+
Assert.True(TestUtils.SEED == moneroWallet.GetSeed());
135+
if (moneroWallet.GetWalletType() != MoneroWalletType.RPC)
136136
{
137-
Assert.True(MoneroWallet.DEFAULT_LANGUAGE == wallet.GetSeedLanguage());
137+
Assert.True(MoneroWallet.DEFAULT_LANGUAGE == moneroWallet.GetSeedLanguage());
138138
}
139139
}
140140
catch (Exception e)
141141
{
142142
e2 = e;
143143
}
144144

145-
CloseWallet(wallet);
145+
CloseWallet(moneroWallet);
146146
if (e2 != null)
147147
{
148148
throw e2;
149149
}
150150

151-
// attempt to create wallet with two missing words
151+
// attempt to create a wallet with two missing words
152152
try
153153
{
154154
string invalidMnemonic =
155155
"memoir desk algebra inbound innocent unplugs fully okay five inflamed giant factual ritual toyed topic snake unhappy guarded tweezers haunted inundate giant";
156-
wallet = CreateWallet(new MoneroWalletConfig().SetSeed(invalidMnemonic)
156+
moneroWallet = CreateWallet(new MoneroWalletConfig().SetSeed(invalidMnemonic)
157157
.SetRestoreHeight(TestUtils.FIRST_RECEIVE_HEIGHT));
158158
}
159159
catch (Exception e)
160160
{
161161
Assert.True("Invalid mnemonic" == e.Message);
162162
}
163163

164-
// attempt to create wallet at same path
164+
// attempt to create a wallet at the same path
165165
try
166166
{
167167
CreateWallet(new MoneroWalletConfig().SetPath(path));
@@ -242,76 +242,76 @@ public void TestCreateWalletFromKeys()
242242
string privateViewKey = this.wallet.GetPrivateViewKey();
243243
string privateSpendKey = this.wallet.GetPrivateSpendKey();
244244

245-
// recreate test wallet from keys
246-
MoneroWallet wallet = CreateWallet(new MoneroWalletConfig().SetPrimaryAddress(primaryAddress)
245+
// recreate the test wallet from keys
246+
MoneroWallet moneroWallet = CreateWallet(new MoneroWalletConfig().SetPrimaryAddress(primaryAddress)
247247
.SetPrivateViewKey(privateViewKey).SetPrivateSpendKey(privateSpendKey)
248248
.SetRestoreHeight(daemon.GetHeight()));
249-
string path = wallet.GetPath();
249+
string path = moneroWallet.GetPath();
250250
Exception? e2 = null;
251251
try
252252
{
253-
Assert.True(primaryAddress == wallet.GetPrimaryAddress());
254-
Assert.True(privateViewKey == wallet.GetPrivateViewKey());
255-
Assert.True(privateSpendKey == wallet.GetPrivateSpendKey());
256-
if (!wallet.IsConnectedToDaemon())
253+
Assert.True(primaryAddress == moneroWallet.GetPrimaryAddress());
254+
Assert.True(privateViewKey == moneroWallet.GetPrivateViewKey());
255+
Assert.True(privateSpendKey == moneroWallet.GetPrivateSpendKey());
256+
if (!moneroWallet.IsConnectedToDaemon())
257257
{
258258
MoneroUtils.Log(0,
259259
"WARNING: wallet created from keys is not connected to authenticated daemon"); // TODO monero-project: keys wallets not connected
260260
}
261261

262-
Assert.True(wallet.IsConnectedToDaemon(),
262+
Assert.True(moneroWallet.IsConnectedToDaemon(),
263263
"Wallet created from keys is not connected to authenticated daemon");
264-
if (wallet.GetWalletType() != MoneroWalletType.RPC)
264+
if (moneroWallet.GetWalletType() != MoneroWalletType.RPC)
265265
{
266-
MoneroUtils.ValidateMnemonic(wallet
266+
MoneroUtils.ValidateMnemonic(moneroWallet
267267
.GetSeed()); // TODO monero-wallet-rpc: cannot get seed from wallet created from keys?
268-
Assert.True(MoneroWallet.DEFAULT_LANGUAGE == wallet.GetSeedLanguage());
268+
Assert.True(MoneroWallet.DEFAULT_LANGUAGE == moneroWallet.GetSeedLanguage());
269269
}
270270
}
271271
catch (Exception e)
272272
{
273273
e2 = e;
274274
}
275275

276-
CloseWallet(wallet);
276+
CloseWallet(moneroWallet);
277277
if (e2 != null)
278278
{
279279
throw e2;
280280
}
281281

282282
// recreate test wallet from spend key
283-
if (wallet.GetWalletType() != MoneroWalletType.RPC)
283+
if (moneroWallet.GetWalletType() != MoneroWalletType.RPC)
284284
{
285285
// TODO monero-wallet-rpc: cannot create wallet from spend key?
286-
wallet = CreateWallet(new MoneroWalletConfig().SetPrivateSpendKey(privateSpendKey)
286+
moneroWallet = CreateWallet(new MoneroWalletConfig().SetPrivateSpendKey(privateSpendKey)
287287
.SetRestoreHeight(daemon.GetHeight()));
288288
e2 = null;
289289
try
290290
{
291-
Assert.True(primaryAddress == wallet.GetPrimaryAddress());
292-
Assert.True(privateViewKey == wallet.GetPrivateViewKey());
293-
Assert.True(privateSpendKey == wallet.GetPrivateSpendKey());
294-
if (!wallet.IsConnectedToDaemon())
291+
Assert.True(primaryAddress == moneroWallet.GetPrimaryAddress());
292+
Assert.True(privateViewKey == moneroWallet.GetPrivateViewKey());
293+
Assert.True(privateSpendKey == moneroWallet.GetPrivateSpendKey());
294+
if (!moneroWallet.IsConnectedToDaemon())
295295
{
296296
MoneroUtils.Log(0,
297297
"WARNING: wallet created from keys is not connected to authenticated daemon"); // TODO monero-project: keys wallets not connected
298298
}
299299

300-
Assert.True(wallet.IsConnectedToDaemon(),
300+
Assert.True(moneroWallet.IsConnectedToDaemon(),
301301
"Wallet created from keys is not connected to authenticated daemon");
302-
if (wallet.GetWalletType() != MoneroWalletType.RPC)
302+
if (moneroWallet.GetWalletType() != MoneroWalletType.RPC)
303303
{
304-
MoneroUtils.ValidateMnemonic(wallet
304+
MoneroUtils.ValidateMnemonic(moneroWallet
305305
.GetSeed()); // TODO monero-wallet-rpc: cannot get seed from wallet created from keys?
306-
Assert.True(MoneroWallet.DEFAULT_LANGUAGE == wallet.GetSeedLanguage());
306+
Assert.True(MoneroWallet.DEFAULT_LANGUAGE == moneroWallet.GetSeedLanguage());
307307
}
308308
}
309309
catch (Exception e)
310310
{
311311
e2 = e;
312312
}
313313

314-
CloseWallet(wallet);
314+
CloseWallet(moneroWallet);
315315
if (e2 != null)
316316
{
317317
throw e2;
@@ -505,59 +505,59 @@ public void TestConnectionManager()
505505
connectionManager.AddConnection(connection2);
506506

507507
// create wallet with connection manager
508-
MoneroWallet wallet =
508+
MoneroWallet moneroWallet =
509509
CreateWallet(new MoneroWalletConfig().SetServerUri("").SetConnectionManager(connectionManager));
510-
Assert.True(TestUtils.GetDaemonRpc().GetRpcConnection() == wallet.GetDaemonConnection());
511-
Assert.True(wallet.IsConnectedToDaemon());
510+
Assert.True(TestUtils.GetDaemonRpc().GetRpcConnection() == moneroWallet.GetDaemonConnection());
511+
Assert.True(moneroWallet.IsConnectedToDaemon());
512512

513513
// set manager's connection
514514
connectionManager.SetConnection(connection2);
515515
Thread.Sleep(TestUtils.AUTO_CONNECT_TIMEOUT_MS);
516-
Assert.True(connection2 == wallet.GetDaemonConnection());
516+
Assert.True(connection2 == moneroWallet.GetDaemonConnection());
517517

518518
// reopen wallet with connection manager
519-
string path = wallet.GetPath();
520-
CloseWallet(wallet);
521-
wallet = OpenWallet(new MoneroWalletConfig().SetServerUri("").SetConnectionManager(connectionManager)
519+
string path = moneroWallet.GetPath();
520+
CloseWallet(moneroWallet);
521+
moneroWallet = OpenWallet(new MoneroWalletConfig().SetServerUri("").SetConnectionManager(connectionManager)
522522
.SetPath(path));
523-
Assert.True(connection2 == wallet.GetDaemonConnection());
523+
Assert.True(connection2 == moneroWallet.GetDaemonConnection());
524524

525525
// disconnect
526526
connectionManager.SetConnection(null);
527-
Assert.Null(wallet.GetDaemonConnection());
528-
Assert.False(wallet.IsConnectedToDaemon());
527+
Assert.Null(moneroWallet.GetDaemonConnection());
528+
Assert.False(moneroWallet.IsConnectedToDaemon());
529529

530530
// start polling connections
531531
connectionManager.StartPolling((ulong)TestUtils.SYNC_PERIOD_IN_MS);
532532

533533
// test that wallet auto connects
534534
Thread.Sleep(TestUtils.AUTO_CONNECT_TIMEOUT_MS);
535-
Assert.True(connection1.Equals(wallet.GetDaemonConnection()));
536-
Assert.True(wallet.IsConnectedToDaemon());
535+
Assert.True(connection1.Equals(moneroWallet.GetDaemonConnection()));
536+
Assert.True(moneroWallet.IsConnectedToDaemon());
537537

538538
// test override with bad connection
539-
wallet.AddListener(new MoneroWalletListener());
539+
moneroWallet.AddListener(new MoneroWalletListener());
540540
connectionManager.SetAutoSwitch(false);
541541
connectionManager.SetConnection("http://foo.bar.xyz");
542-
Assert.True("http://foo.bar.xyz" == wallet.GetDaemonConnection().GetUri());
543-
Assert.False(wallet.IsConnectedToDaemon());
542+
Assert.True("http://foo.bar.xyz" == moneroWallet.GetDaemonConnection().GetUri());
543+
Assert.False(moneroWallet.IsConnectedToDaemon());
544544
Thread.Sleep(5000);
545-
Assert.False(wallet.IsConnectedToDaemon());
545+
Assert.False(moneroWallet.IsConnectedToDaemon());
546546

547547
// set to another connection manager
548548
MoneroConnectionManager connectionManager2 = new();
549549
connectionManager2.SetConnection(connection2);
550-
wallet.SetConnectionManager(connectionManager2);
551-
Assert.True(connection2 == wallet.GetDaemonConnection());
550+
moneroWallet.SetConnectionManager(connectionManager2);
551+
Assert.True(connection2 == moneroWallet.GetDaemonConnection());
552552

553553
// unset connection manager
554-
wallet.SetConnectionManager(null);
555-
Assert.Null(wallet.GetConnectionManager());
556-
Assert.True(connection2 == wallet.GetDaemonConnection());
554+
moneroWallet.SetConnectionManager(null);
555+
Assert.Null(moneroWallet.GetConnectionManager());
556+
Assert.True(connection2 == moneroWallet.GetDaemonConnection());
557557

558558
// stop polling and close
559559
connectionManager.StopPolling();
560-
CloseWallet(wallet);
560+
CloseWallet(moneroWallet);
561561
}
562562

563563
// Can get the seed

Monero.IntegrationTests/Utils/WalletTxTracker.cs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,15 @@ public void Reset()
1717

1818
public void WaitForWalletTxsToClearPool(MoneroWallet wallet)
1919
{
20-
WaitForWalletTxsToClearPool([wallet]);
21-
}
22-
23-
public void WaitForWalletTxsToClearPool(List<MoneroWallet> wallets)
24-
{
20+
List<MoneroWallet> wallets = [wallet];
2521
// get wallet tx hashes
2622
List<string> txHashesWallet = [];
27-
foreach (MoneroWallet wallet in wallets)
23+
foreach (MoneroWallet wallet1 in wallets)
2824
{
29-
if (!clearedWallets.Contains(wallet))
25+
if (!clearedWallets.Contains(wallet1))
3026
{
31-
wallet.Sync();
32-
foreach (MoneroTxWallet tx in wallet.GetTxs())
27+
wallet1.Sync();
28+
foreach (MoneroTxWallet tx in wallet1.GetTxs())
3329
{
3430
string? txHash = tx.GetHash();
3531
if (txHash == null)
@@ -42,7 +38,7 @@ public void WaitForWalletTxsToClearPool(List<MoneroWallet> wallets)
4238
}
4339
}
4440

45-
// loop until all wallet txs clear from pool
41+
// loop until all wallet txs clear from the pool
4642
bool isFirst = true;
4743
bool miningStarted = false;
4844
MoneroDaemon daemon = TestUtils.GetDaemonRpc();
@@ -76,7 +72,7 @@ public void WaitForWalletTxsToClearPool(List<MoneroWallet> wallets)
7672
break;
7773
}
7874

79-
// if first time waiting, log message and start mining
75+
// if first time waiting, log a message and start mining
8076
if (isFirst)
8177
{
8278
isFirst = false;
@@ -90,7 +86,10 @@ public void WaitForWalletTxsToClearPool(List<MoneroWallet> wallets)
9086
StartMining.Start();
9187
miningStarted = true;
9288
}
93-
catch (Exception e) { } // no problem
89+
catch (Exception e)
90+
{
91+
// no problem
92+
}
9493
}
9594
}
9695

@@ -106,10 +105,10 @@ public void WaitForWalletTxsToClearPool(List<MoneroWallet> wallets)
106105
}
107106

108107
// sync wallets with the pool
109-
foreach (MoneroWallet wallet in wallets)
108+
foreach (MoneroWallet wallet2 in wallets)
110109
{
111-
wallet.Sync();
112-
clearedWallets.Add(wallet);
110+
wallet2.Sync();
111+
clearedWallets.Add(wallet2);
113112
}
114113
}
115114
}

Monero/Common/GenUtils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Monero.Common;
44

5-
public class GenUtils
5+
public static class GenUtils
66
{
77
public static T? Reconcile<T>(T? val1, T? val2, bool? resolveDefined = null, bool? resolveTrue = null,
88
bool? resolveMax = null)

0 commit comments

Comments
 (0)