Prepare WalletService. Cleanup tests.
MODIFY
MagicalCryptoWallet.Tests/P2pTests.cs
MagicalCryptoWallet.Tests/P2pTests.cs
@@ -58,8 +58,6 @@ namespace MagicalCryptoWallet.Tests
var connectionParameters = new NodeConnectionParameters();
AddressManager addressManager = null;
BlockDownloader downloader = null;
- try
- {
try
{
addressManager = AddressManager.LoadPeerFile(addressManagerFilePath);
@@ -82,13 +80,12 @@ namespace MagicalCryptoWallet.Tests
var memPoolService = new MemPoolService();
connectionParameters.TemplateBehaviors.Add(new MemPoolBehavior(memPoolService));
- using (var nodes = new NodesGroup(network, connectionParameters,
+ var nodes = new NodesGroup(network, connectionParameters,
new NodeRequirement
{
RequiredServices = NodeServices.Network,
MinVersion = ProtocolVersion.WITNESS_VERSION
- }))
- {
+ });
downloader = new BlockDownloader(nodes, blocksFolderPath);
Assert.True(Directory.Exists(blocksFolderPath));
downloader.Start();
@@ -149,11 +146,6 @@ namespace MagicalCryptoWallet.Tests
nodes.ConnectedNodes.Added -= ConnectedNodes_Added;
nodes.ConnectedNodes.Removed -= ConnectedNodes_Removed;
memPoolService.TransactionReceived -= MemPoolService_TransactionReceived;
- }
- }
- }
- finally
- {
downloader?.Stop();
// So next test will download the block.
@@ -169,6 +161,7 @@ namespace MagicalCryptoWallet.Tests
Directory.CreateDirectory(Path.GetDirectoryName(addressManagerFilePath));
addressManager?.SavePeerFile(addressManagerFilePath, network);
Logger.LogInfo<P2pTests>($"Saved {nameof(AddressManager)} to `{addressManagerFilePath}`.");
+ nodes?.Dispose();
}
}

MODIFY
MagicalCryptoWallet.Tests/RegTests.cs
MagicalCryptoWallet.Tests/RegTests.cs
@@ -80,6 +80,8 @@ namespace MagicalCryptoWallet.Tests
}
}
+ #region BackendTests
+
[Fact]
public async void GetExchangeRatesAsyncAsync()
{
@@ -148,6 +150,10 @@ namespace MagicalCryptoWallet.Tests
}
}
+ #endregion
+
+ #region ServicesTests
+
[Fact]
public async Task DownloaderAsync()
{
@@ -159,14 +165,13 @@ namespace MagicalCryptoWallet.Tests
}
var blocksFolderPath = Path.Combine(SharedFixture.DataDir, nameof(DownloaderAsync), $"Blocks");
BlockDownloader downloader = null;
- try
- {
- using (var nodes = new NodesGroup(Global.Config.Network,
+ var nodes = new NodesGroup(Global.Config.Network,
requirements: new NodeRequirement
{
RequiredServices = NodeServices.Network,
MinVersion = ProtocolVersion.WITNESS_VERSION
- }))
+ });
+ try
{
nodes.ConnectedNodes.Add(Fixture.BackendRegTestNode.CreateNodeClient());
@@ -195,7 +200,6 @@ namespace MagicalCryptoWallet.Tests
}
Logger.LogInfo<P2pTests>($"All RegTest block is downloaded.");
}
- }
finally
{
downloader?.Stop();
@@ -209,6 +213,8 @@ namespace MagicalCryptoWallet.Tests
{
Directory.Delete(blocksFolderPath, recursive: true);
}
+
+ nodes?.Dispose();
}
}
@@ -222,7 +228,7 @@ namespace MagicalCryptoWallet.Tests
try
{
- memPoolService.TransactionReceived += MemPoolService_TransactionReceived;
+ memPoolService.TransactionReceived += MempoolAsync_MemPoolService_TransactionReceived;
// Using the interlocked, not because it makes sense in this context, but to
// set an example that these values are often concurrency sensitive
@@ -246,12 +252,12 @@ namespace MagicalCryptoWallet.Tests
}
finally
{
- memPoolService.TransactionReceived -= MemPoolService_TransactionReceived;
+ memPoolService.TransactionReceived -= MempoolAsync_MemPoolService_TransactionReceived;
}
}
private long _mempoolTransactionCount = 0;
- private void MemPoolService_TransactionReceived(object sender, SmartTransaction e)
+ private void MempoolAsync_MemPoolService_TransactionReceived(object sender, SmartTransaction e)
{
Interlocked.Increment(ref _mempoolTransactionCount);
Logger.LogDebug<P2pTests>($"Mempool transaction received: {e.GetHash()}.");
@@ -316,5 +322,76 @@ namespace MagicalCryptoWallet.Tests
downloader.Stop();
}
}
+
+ #endregion
+
+ #region ClientTests
+
+ [Fact]
+ public async Task WalletTestsAsync()
+ {
+ // Make sure fitlers are created on the server side.
+ await AssertFiltersInitializedAsync();
+
+ // Create the services.
+ // 1. Create connection service.
+ var nodes = new NodesGroup(Global.Config.Network,
+ requirements: new NodeRequirement
+ {
+ RequiredServices = NodeServices.Network,
+ MinVersion = ProtocolVersion.WITNESS_VERSION
+ });
+ nodes.ConnectedNodes.Add(Fixture.BackendRegTestNode.CreateNodeClient());
+
+ // 2. Create block downloader service.
+ var blocksFolderPath = Path.Combine(SharedFixture.DataDir, nameof(WalletTestsAsync), $"Blocks");
+ BlockDownloader blockDownloader = new BlockDownloader(nodes, blocksFolderPath);
+
+ // 3. Create mempool service.
+ var memPoolService = new MemPoolService();
+ memPoolService.TransactionReceived += WalletTestsAsync_MemPoolService_TransactionReceived;
+ Node node = Fixture.BackendRegTestNode.CreateNodeClient();
+ node.Behaviors.Add(new MemPoolBehavior(memPoolService));
+
+ // 4. Create index downloader service.
+ var indexFilePath = Path.Combine(SharedFixture.DataDir, nameof(FilterDownloaderTestAsync), $"Index{Global.RpcClient.Network}.dat");
+ var indexDownloader = new IndexDownloader(Global.RpcClient.Network, indexFilePath, new Uri(Fixture.BackendEndPoint));
+
+ try
+ {
+ nodes.Connect(); // Start connection service.
+ blockDownloader.Start(); // Start block downloader service.
+ node.VersionHandshake(); // Start mempool service.
+ indexDownloader.Syncronize(requestInterval: TimeSpan.FromSeconds(3)); // Start index downloader service.
+
+
+
+ }
+ finally
+ {
+ // Dispose index downloader service.
+ indexDownloader?.Stop();
+
+ // Dispose mempool service.
+ memPoolService.TransactionReceived -= WalletTestsAsync_MemPoolService_TransactionReceived;
+
+ // Dispose downloader service
+ blockDownloader?.Stop();
+ if (Directory.Exists(blocksFolderPath))
+ {
+ Directory.Delete(blocksFolderPath, recursive: true);
+ }
+
+ // Dispose connection service.
+ nodes?.Dispose();
+ }
+ }
+
+ private void WalletTestsAsync_MemPoolService_TransactionReceived(object sender, SmartTransaction e)
+ {
+
+ }
+
+ #endregion
}
}

Prepare WalletService. Cleanup tests.