Skip to content

Commit 713bc5c

Browse files
Notification tests implementation for TestMoneroWalletCommon
1 parent 8b2e6d5 commit 713bc5c

7 files changed

Lines changed: 773 additions & 16 deletions

File tree

Monero.Test/TestMoneroConnectionManager.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public void TestConnectionManager()
103103
TestUtils.StopWalletRpcProcess(walletRpcs[2]);
104104
TestUtils.StopWalletRpcProcess(walletRpcs[3]);
105105
TestUtils.StopWalletRpcProcess(walletRpcs[4]);
106-
Thread.Sleep(TestUtils.SYNC_PERIOD_IN_MS + 100); // allow time to poll
106+
GenUtils.WaitFor(TestUtils.SYNC_PERIOD_IN_MS + 100); // allow time to poll
107107
Assert.False(connectionManager.IsConnected());
108108
Assert.False(connectionManager.GetConnection().IsOnline());
109109
Assert.Null(connectionManager.GetConnection().IsAuthenticated());
@@ -143,7 +143,7 @@ public void TestConnectionManager()
143143

144144
// test auto switch when disconnected
145145
connectionManager.SetAutoSwitch(true);
146-
Thread.Sleep(TestUtils.SYNC_PERIOD_IN_MS + 100);
146+
GenUtils.WaitFor(TestUtils.SYNC_PERIOD_IN_MS + 100);
147147
Assert.True(connectionManager.IsConnected());
148148
connection = connectionManager.GetConnection();
149149
Assert.True(connection.IsOnline());
@@ -251,7 +251,7 @@ public void TestConnectionManager()
251251
// shut down all connections
252252
connection = connectionManager.GetConnection();
253253
foreach (MoneroWalletRpc walletRpc in walletRpcs) TestUtils.StopWalletRpcProcess(walletRpc);
254-
Thread.Sleep(TestUtils.SYNC_PERIOD_IN_MS + 100);
254+
GenUtils.WaitFor(TestUtils.SYNC_PERIOD_IN_MS + 100);
255255
Assert.False(connection.IsOnline());
256256
Assert.True(++numExpectedChanges == listener.ChangedConnections.Count);
257257
Assert.True(listener.ChangedConnections[listener.ChangedConnections.Count - 1] == connection);

Monero.Test/TestMoneroDaemonRpc.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,7 @@ public void TestStop()
12271227
daemon.Stop();
12281228

12291229
// give the daemon time to shut down
1230-
Thread.Sleep(TestUtils.SYNC_PERIOD_IN_MS);
1230+
GenUtils.WaitFor(TestUtils.SYNC_PERIOD_IN_MS);
12311231
// try to interact with the daemon
12321232
try
12331233
{

Monero.Test/TestMoneroWalletCommon.cs

Lines changed: 743 additions & 9 deletions
Large diffs are not rendered by default.

Monero.Test/Utils/TestUtils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ internal abstract class TestUtils
4848
public static readonly string SEED = "silk mocked cucumber lettuce hope adrenalin aching lush roles fuel revamp baptism wrist ulong tender teardrop midst pastry pigment equip frying inbound pinched ravine frying";
4949
public static readonly string ADDRESS = "A1y9sbVt8nqhZAVm3me1U18rUVXcjeNKuBd1oE2cTs8biA9cozPMeyYLhe77nPv12JA3ejJN3qprmREriit2fi6tJDi99RR";
5050
public static readonly ulong FIRST_RECEIVE_HEIGHT = 171; // NOTE: this value must be the height of the wallet's first tx for tests
51-
public static readonly int SYNC_PERIOD_IN_MS = 5000; // period between wallet syncs in milliseconds
51+
public static readonly ulong SYNC_PERIOD_IN_MS = 5000; // period between wallet syncs in milliseconds
5252
public static readonly string OFFLINE_SERVER_URI = "offline_server_uri"; // dummy server uri to remain offline because wallet2 connects to default if not given
5353
public static readonly int AUTO_CONNECT_TIMEOUT_MS = 3000;
5454

Monero.Test/Utils/WalletTxTracker.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void WaitForWalletTxsToClearPool(List<MoneroWallet> wallets)
8080
}
8181

8282
// sleep for a moment
83-
try { Thread.Sleep(TestUtils.SYNC_PERIOD_IN_MS); }
83+
try { GenUtils.WaitFor(TestUtils.SYNC_PERIOD_IN_MS); }
8484
catch (Exception e) { throw new MoneroError(e.Message); }
8585
}
8686

@@ -124,7 +124,7 @@ public ulong WaitForUnlockedBalance(MoneroWallet wallet, uint accountIndex, uint
124124
while (unlockedBalance < minAmount)
125125
{
126126
unlockedBalance = wallet.GetUnlockedBalance(accountIndex, subaddressIndex);
127-
try { Thread.Sleep(TestUtils.SYNC_PERIOD_IN_MS); }
127+
try { GenUtils.WaitFor(TestUtils.SYNC_PERIOD_IN_MS); }
128128
catch (ThreadInterruptedException e) { throw new Exception("Thread was interrupted", e); }
129129
}
130130

Monero/Common/GenUtils.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,22 @@ public static int[] Subarray(int[] array, int startIndexInclusive, int endIndexE
106106
Array.Copy(array, startIndexInclusive, subarray, 0, newSize);
107107
return subarray;
108108
}
109+
110+
public static void WaitFor(ulong durationMs) {
111+
WaitFor((int)durationMs);
112+
}
113+
114+
public static void WaitFor(int durationMs)
115+
{
116+
try
117+
{
118+
// brutto, non mi piace
119+
Thread.Sleep((int)durationMs);
120+
}
121+
catch (ThreadInterruptedException)
122+
{
123+
throw new Exception("Thread was interrupted while sleeping");
124+
}
125+
}
109126
}
110127
}

Monero/Wallet/Common/MoneroOutputQuery.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ public override MoneroOutputQuery SetIsSpent(bool? isSpent)
3232
return this;
3333
}
3434

35+
public override MoneroOutputQuery SetIsFrozen(bool? isFrozen)
36+
{
37+
base.SetIsFrozen(isFrozen);
38+
return this;
39+
}
40+
3541
public override MoneroOutputQuery SetAccountIndex(uint? accountIndex)
3642
{
3743
base.SetAccountIndex(accountIndex);

0 commit comments

Comments
 (0)