Permalink
Browse files

Merge branch 'master' into tormonitor

  • Loading branch information...
nopara73 committed Oct 20, 2018
2 parents 2cdb381 + 5005e68 commit 393733c3abd5230ff0ac4e99c4f7bc2c04033c74
@@ -16,23 +16,29 @@ namespace WalletWasabi.Tests.NodeBuilding
public class NodeBuilder : IDisposable
{
public static readonly AsyncLock Lock = new AsyncLock();
public static string WorkingDirectory { get; private set; }
public static async Task<NodeBuilder> CreateAsync([CallerMemberName]string caller = null, string version = "0.17.0")
{
using (await Lock.LockAsync())
{
var directory = Path.Combine(SharedFixture.DataDir, caller);
WorkingDirectory = Path.Combine(SharedFixture.DataDir, caller);
version = version ?? "0.17.0";
var path = await EnsureDownloadedAsync(version);
try
{
await IoHelpers.DeleteRecursivelyWithMagicDustAsync(directory);
}
catch (DirectoryNotFoundException)
{
}
Directory.CreateDirectory(directory);
return new NodeBuilder(directory, path);
await TryRemoveWorkingDirectoryAsync();
Directory.CreateDirectory(WorkingDirectory);
return new NodeBuilder(WorkingDirectory, path);
}
}
private static async Task TryRemoveWorkingDirectoryAsync()
{
try
{
await IoHelpers.DeleteRecursivelyWithMagicDustAsync(WorkingDirectory);
}
catch (DirectoryNotFoundException)
{
}
}
@@ -46,11 +52,27 @@ private static async Task<string> EnsureDownloadedAsync(string version)
string zip;
string bitcoind;
string bitcoindFolderName = $"bitcoin-{version}";
// Remove old bitcoind folders.
IEnumerable<string> existingBitcoindFolderPaths = Directory.EnumerateDirectories(SharedFixture.DataDir, "bitcoin-*", SearchOption.TopDirectoryOnly);
foreach (string dirPath in existingBitcoindFolderPaths)
{
string dirName = Path.GetFileName(dirPath);
if (bitcoindFolderName != dirName)
{
await IoHelpers.DeleteRecursivelyWithMagicDustAsync(dirPath);
}
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
bitcoind = Path.Combine(SharedFixture.DataDir, $"bitcoin-{version}", "bin", "bitcoind.exe");
bitcoind = Path.Combine(SharedFixture.DataDir, bitcoindFolderName, "bin", "bitcoind.exe");
if (File.Exists(bitcoind))
{
return bitcoind;
}
zip = Path.Combine(SharedFixture.DataDir, $"bitcoin-{version}-win32.zip");
var url = string.Format("https://bitcoincore.org/bin/bitcoin-core-{0}/" + Path.GetFileName(zip), version);
using (var client = new HttpClient())
@@ -63,9 +85,11 @@ private static async Task<string> EnsureDownloadedAsync(string version)
}
else
{
bitcoind = Path.Combine(SharedFixture.DataDir, $"bitcoin-{version}", "bin", "bitcoind");
bitcoind = Path.Combine(SharedFixture.DataDir, bitcoindFolderName, "bin", "bitcoind");
if (File.Exists(bitcoind))
{
return bitcoind;
}
zip = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ?
Path.Combine(SharedFixture.DataDir, $"bitcoin-{version}-x86_64-linux-gnu.tar.gz")
@@ -128,10 +152,17 @@ public Task StartAllAsync()
public void Dispose()
{
foreach (var node in Nodes)
foreach (CoreNode node in Nodes)
{
node.Kill();
foreach (var disposable in _disposables)
}
foreach (IDisposable disposable in _disposables)
{
disposable.Dispose();
}
TryRemoveWorkingDirectoryAsync().GetAwaiter().GetResult();
}
private List<IDisposable> _disposables = new List<IDisposable>();
@@ -479,6 +479,7 @@ public async Task WalletTestsAsync()
await rpc.GenerateAsync(1);
await WaitForFiltersToBeProcessedAsync(TimeSpan.FromSeconds(120), 2);
// ToDo: randomly fails, times: 5/10
Assert.Equal(3, await wallet.CountBlocksAsync());
Assert.Equal(3, wallet.Coins.Count);
@@ -527,6 +528,7 @@ public async Task WalletTestsAsync()
Interlocked.Exchange(ref _filtersProcessedByWalletCount, 0);
await rpc.GenerateAsync(2);
await WaitForFiltersToBeProcessedAsync(TimeSpan.FromSeconds(120), 2);
// ToDo: randomly fails, times: 1/10
Assert.NotEmpty(wallet.Coins.Where(x => x.TransactionId == txid4));
var tip = await rpc.GetBestBlockHashAsync();
await rpc.InvalidateBlockAsync(tip); // Reorg 1
@@ -537,6 +539,7 @@ public async Task WalletTestsAsync()
await rpc.GenerateAsync(3);
await WaitForFiltersToBeProcessedAsync(TimeSpan.FromSeconds(120), 3);
// ToDo: randomly fails, times: 4/10
Assert.Equal(4, await wallet.CountBlocksAsync());
Assert.Equal(4, wallet.Coins.Count);
@@ -22,7 +22,7 @@ public class RegTestFixture : IDisposable
public RegTestFixture()
{
BackendNodeBuilder = NodeBuilder.CreateAsync().GetAwaiter().GetResult();
BackendNodeBuilder = NodeBuilder.CreateAsync(nameof(RegTestFixture)).GetAwaiter().GetResult();
BackendNodeBuilder.CreateNodeAsync().GetAwaiter().GetResult();
BackendNodeBuilder.StartAllAsync().GetAwaiter().GetResult();
BackendRegTestNode = BackendNodeBuilder.Nodes[0];
@@ -18,7 +18,7 @@
<ItemGroup>
<PackageReference Include="ConcurrentHashSet" Version="1.0.2" />
<PackageReference Include="NBitcoin" Version="4.1.1.57" />
<PackageReference Include="NBitcoin" Version="4.1.1.52" />
<PackageReference Include="Nito.AsyncEx.Coordination" Version="1.0.2" />
<PackageReference Include="Portable.BouncyCastle" Version="1.8.3.37" />
</ItemGroup>

0 comments on commit 393733c

Please sign in to comment.