Cleanup tests based on VS2019
MODIFY
WalletWasabi.Tests/CryptoTests.cs
WalletWasabi.Tests/CryptoTests.cs
@@ -70,7 +70,7 @@ namespace WalletWasabi.Tests
}
count++;
}
- var rate = (double)errorCount / (double)count;
+ var rate = errorCount / (double)count;
Assert.True(rate < 0.000001 && rate > -0.000001);
}

MODIFY
WalletWasabi.Tests/ExtPubKeyExplorerTests.cs
WalletWasabi.Tests/ExtPubKeyExplorerTests.cs
+using NBitcoin;
using System;
-using System.Linq;
using System.Collections.Generic;
-using Xunit;
-using NBitcoin;
-using WalletWasabi.Services;
-using WalletWasabi.Backend.Models;
using System.IO;
+using System.Linq;
+using WalletWasabi.Backend.Models;
+using WalletWasabi.Services;
+using Xunit;
namespace WalletWasabi.Tests
{
public class ExtPubKeyExplorerTests
{
- private ExtKey _extKey;
- private ExtPubKey _extPubKey;
- private Random _random;
+ private ExtKey ExtKey { get; }
+ private ExtPubKey ExtPubKey { get; }
+ private Random Random { get; }
public ExtPubKeyExplorerTests()
{
- _random = new Random(Seed: 6439);
+ Random = new Random(Seed: 6439);
var mnemonic = new Mnemonic("abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about");
- _extKey = mnemonic.DeriveExtKey();
- _extPubKey = _extKey.Derive(new KeyPath("m/84'/0'/0'/1/0")).Neuter();
+ ExtKey = mnemonic.DeriveExtKey();
+ ExtPubKey = ExtKey.Derive(new KeyPath("m/84'/0'/0'/1/0")).Neuter();
}
[Fact]
@@ -31,7 +31,7 @@ namespace WalletWasabi.Tests
FilterModel.FromHeightlessLine("000000000000de90e633e1b1330859842795d39018d033044e8b003e8cbf58e4:050a2f58828c9820642769ae320a40", 0)
};
- var unusedKeyIndex = ExtPubKeyExplorer.GetUnusedBech32Keys(1, true, _extPubKey.GetWif(Network.Main), filters).First().ScriptPubKey.ToCompressedBytes();
+ var unusedKeyIndex = ExtPubKeyExplorer.GetUnusedBech32Keys(1, true, ExtPubKey.GetWif(Network.Main), filters).First().ScriptPubKey.ToCompressedBytes();
Assert.Equal(DerivateScript(true, 0), unusedKeyIndex);
}
@@ -44,7 +44,7 @@ namespace WalletWasabi.Tests
CreateFiltersWith(GetScripts(false, 10, 10))
};
- var unusedKeyIndex = ExtPubKeyExplorer.GetUnusedBech32Keys(1, false, _extPubKey.GetWif(Network.Main), filters).First().ScriptPubKey.ToCompressedBytes();
+ var unusedKeyIndex = ExtPubKeyExplorer.GetUnusedBech32Keys(1, false, ExtPubKey.GetWif(Network.Main), filters).First().ScriptPubKey.ToCompressedBytes();
Assert.Equal(DerivateScript(false, 20), unusedKeyIndex);
}
@@ -57,7 +57,7 @@ namespace WalletWasabi.Tests
CreateFiltersWith(GetScripts(true, 500, 499))
};
- var unusedKeyIndex = ExtPubKeyExplorer.GetUnusedBech32Keys(1, true, _extPubKey.GetWif(Network.Main), filters).First().ScriptPubKey.ToCompressedBytes();
+ var unusedKeyIndex = ExtPubKeyExplorer.GetUnusedBech32Keys(1, true, ExtPubKey.GetWif(Network.Main), filters).First().ScriptPubKey.ToCompressedBytes();
Assert.Equal(DerivateScript(true, 999), unusedKeyIndex);
}
@@ -71,7 +71,7 @@ namespace WalletWasabi.Tests
CreateFiltersWith(GetScripts(true, 27, 3)),
};
- var unusedKeyIndex = ExtPubKeyExplorer.GetUnusedBech32Keys(1, true, _extPubKey.GetWif(Network.Main), filters).First().ScriptPubKey.ToCompressedBytes();
+ var unusedKeyIndex = ExtPubKeyExplorer.GetUnusedBech32Keys(1, true, ExtPubKey.GetWif(Network.Main), filters).First().ScriptPubKey.ToCompressedBytes();
Assert.Equal(DerivateScript(true, 30), unusedKeyIndex);
}
@@ -86,7 +86,7 @@ namespace WalletWasabi.Tests
CreateFiltersWith(GetScripts(true, 750, 250))
};
- var unusedKeyIndex = ExtPubKeyExplorer.GetUnusedBech32Keys(1, true, _extPubKey.GetWif(Network.Main), filters).First().ScriptPubKey.ToCompressedBytes();
+ var unusedKeyIndex = ExtPubKeyExplorer.GetUnusedBech32Keys(1, true, ExtPubKey.GetWif(Network.Main), filters).First().ScriptPubKey.ToCompressedBytes();
Assert.Equal(DerivateScript(true, 1_000), unusedKeyIndex);
}
@@ -96,14 +96,14 @@ namespace WalletWasabi.Tests
{
var filters = Enumerable.Range(0, 100).Select(x => CreateFiltersWith(GetScripts(true, x * 250, 250))).ToArray();
- var unusedKeyIndex = ExtPubKeyExplorer.GetUnusedBech32Keys(1, true, _extPubKey.GetWif(Network.Main), filters).First().ScriptPubKey.ToCompressedBytes();
+ var unusedKeyIndex = ExtPubKeyExplorer.GetUnusedBech32Keys(1, true, ExtPubKey.GetWif(Network.Main), filters).First().ScriptPubKey.ToCompressedBytes();
Assert.Equal(DerivateScript(true, 25_000), unusedKeyIndex);
}
private FilterModel CreateFiltersWith(IEnumerable<byte[]> scripts)
{
var keyBuffer = new byte[32];
- _random.NextBytes(keyBuffer);
+ Random.NextBytes(keyBuffer);
var blockHash = new uint256(keyBuffer);
var builder = new GolombRiceFilterBuilder()
@@ -125,7 +125,7 @@ namespace WalletWasabi.Tests
var scripts = new byte[count][];
for (var i = 0; i < count; i++)
{
- var pubKey = _extPubKey.Derive(change, false).Derive(offset + i, false).PubKey;
+ var pubKey = ExtPubKey.Derive(change, false).Derive(offset + i, false).PubKey;
var bytes = pubKey.WitHash.ScriptPubKey.ToCompressedBytes();
scripts[i] = bytes;
}
@@ -135,7 +135,7 @@ namespace WalletWasabi.Tests
private IEnumerable<byte> DerivateScript(bool isInternal, int index)
{
var change = isInternal ? 1 : 0;
- return _extPubKey.Derive(change, false).Derive(index, false).PubKey.WitHash.ScriptPubKey.ToCompressedBytes();
+ return ExtPubKey.Derive(change, false).Derive(index, false).PubKey.WitHash.ScriptPubKey.ToCompressedBytes();
}
}
}

MODIFY
WalletWasabi.Tests/LiveServerTests.cs
WalletWasabi.Tests/LiveServerTests.cs
+using NBitcoin;
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
-using NBitcoin;
using WalletWasabi.Backend.Models.Responses;
using WalletWasabi.Services;
using WalletWasabi.Tests.XunitConfiguration;

MODIFY
WalletWasabi.Tests/ModelTests.cs
WalletWasabi.Tests/ModelTests.cs
@@ -105,7 +105,6 @@ namespace WalletWasabi.Tests
Assert.True(smartTx.Equals(deserialized2.Transaction));
object sto = deserialized;
Assert.True(smartTx.Equals(sto));
- object to = deserialized.Transaction;
Assert.True(smartTx.Equals(deserialized.Transaction));
// ToDo: Assert.True(smartTx.Equals(to));
@@ -197,7 +196,6 @@ namespace WalletWasabi.Tests
[Fact]
public void InputsResponseSerialization()
{
- uint256[] bigIntegers = new uint256[] { uint256.One, uint256.One, uint256.Zero };
var resp = new InputsResponse
{
UniqueId = Guid.NewGuid(),

MODIFY
WalletWasabi.Tests/NodeBuilding/CoreNode.cs
WalletWasabi.Tests/NodeBuilding/CoreNode.cs
@@ -16,10 +16,10 @@ namespace WalletWasabi.Tests.NodeBuilding
{
public class CoreNode
{
- private readonly NodeBuilder _Builder;
+ private NodeBuilder Builder { get; }
public string Folder { get; }
- public IPEndPoint Endpoint => new IPEndPoint(IPAddress.Parse("127.0.0.1"), _ports[0]);
+ public IPEndPoint Endpoint => new IPEndPoint(IPAddress.Parse("127.0.0.1"), Ports[0]);
public string Config { get; }
@@ -27,7 +27,7 @@ namespace WalletWasabi.Tests.NodeBuilding
private CoreNode(string folder, NodeBuilder builder)
{
- _Builder = builder;
+ Builder = builder;
Folder = folder;
State = CoreNodeState.Stopped;
DataDir = Path.Combine(folder, "data");
@@ -36,8 +36,8 @@ namespace WalletWasabi.Tests.NodeBuilding
Creds = new NetworkCredential(pass, pass);
Config = Path.Combine(DataDir, "bitcoin.conf");
ConfigParameters.Import(builder.ConfigParameters);
- _ports = new int[2];
- FindPorts(_ports);
+ Ports = new int[2];
+ FindPorts(Ports);
}
public Block[] Generate(int blockCount)
@@ -60,18 +60,24 @@ namespace WalletWasabi.Tests.NodeBuilding
public CoreNodeState State { get; private set; }
- private readonly int[] _ports;
+ private int[] Ports { get; }
private readonly NetworkCredential Creds;
public RPCClient CreateRpcClient()
{
- return new RPCClient(Creds, new Uri("http://127.0.0.1:" + _ports[1] + "/"), Network.RegTest);
+ return new RPCClient(Creds, new Uri("http://127.0.0.1:" + Ports[1] + "/"), Network.RegTest);
}
- public async Task<Node> CreateNodeClientAsync() => await Node.ConnectAsync(Network.RegTest, new IPEndPoint(IPAddress.Loopback, _ports[0]));
+ public async Task<Node> CreateNodeClientAsync()
+ {
+ return await Node.ConnectAsync(Network.RegTest, new IPEndPoint(IPAddress.Loopback, Ports[0]));
+ }
- public async Task<Node> CreateNodeClientAsync(NodeConnectionParameters parameters) => await Node.ConnectAsync(Network.RegTest, new IPEndPoint(IPAddress.Loopback, _ports[0]), parameters);
+ public async Task<Node> CreateNodeClientAsync(NodeConnectionParameters parameters)
+ {
+ return await Node.ConnectAsync(Network.RegTest, new IPEndPoint(IPAddress.Loopback, Ports[0]), parameters);
+ }
public async Task StartAsync()
{
@@ -84,23 +90,23 @@ namespace WalletWasabi.Tests.NodeBuilding
{"regtest.txindex", "1"},
{"regtest.rpcuser", Creds.UserName},
{"regtest.rpcpassword", Creds.Password},
- {"regtest.whitebind", "127.0.0.1:" + _ports[0].ToString()},
- {"regtest.rpcport", _ports[1].ToString()},
+ {"regtest.whitebind", "127.0.0.1:" + Ports[0].ToString()},
+ {"regtest.rpcport", Ports[1].ToString()},
{"regtest.printtoconsole", "0"}, // Set it to one if don't mind loud debug logs
{"regtest.keypool", "10"},
{"regtest.pid", "bitcoind.pid"}
};
config.Import(ConfigParameters);
File.WriteAllText(Config, config.ToString());
- using (await _l.LockAsync())
+ using (await KillerLock.LockAsync())
{
- _process = Process.Start(new FileInfo(_Builder.BitcoinD).FullName, "-conf=bitcoin.conf" + " -datadir=" + DataDir + " -debug=1");
+ Process = Process.Start(new FileInfo(Builder.BitcoinD).FullName, "-conf=bitcoin.conf" + " -datadir=" + DataDir + " -debug=1");
State = CoreNodeState.Starting;
string pidFile = Path.Combine(DataDir, "regtest", "bitcoind.pid");
if (!File.Exists(pidFile))
{
Directory.CreateDirectory(Path.Combine(DataDir, "regtest"));
- File.WriteAllText(pidFile, _process.Id.ToString());
+ File.WriteAllText(pidFile, Process.Id.ToString());
}
}
while (true)
@@ -114,13 +120,15 @@ namespace WalletWasabi.Tests.NodeBuilding
catch
{
}
- if (_process is null || _process.HasExited)
+ if (Process is null || Process.HasExited)
+ {
break;
}
}
+ }
- private Process _process;
- private readonly string DataDir;
+ private Process Process { get; set; }
+ private string DataDir { get; }
private static void FindPorts(int[] portArray)
{
@@ -128,9 +136,12 @@ namespace WalletWasabi.Tests.NodeBuilding
while (i < portArray.Length)
{
var port = RandomUtils.GetUInt32() % 4000;
- port = port + 10000;
+ port += 10000;
if (portArray.Any(p => p == port))
+ {
continue;
+ }
+
try
{
var listener = new TcpListener(IPAddress.Loopback, (int)port);
@@ -145,16 +156,16 @@ namespace WalletWasabi.Tests.NodeBuilding
}
}
- private readonly AsyncLock _l = new AsyncLock();
+ private readonly AsyncLock KillerLock = new AsyncLock();
public async Task KillAsync(bool cleanFolder = true)
{
- using (await _l.LockAsync())
+ using (await KillerLock.LockAsync())
{
try
{
await CreateRpcClient().StopAsync();
- if (!_process.WaitForExit(20000))
+ if (!Process.WaitForExit(20000))
{
//log this
}

MODIFY
WalletWasabi.Tests/NodeBuilding/NodeBuilder.cs
WalletWasabi.Tests/NodeBuilding/NodeBuilder.cs
@@ -113,12 +113,12 @@ namespace WalletWasabi.Tests.NodeBuilding
return bitcoind;
}
- private int _last = 0;
- private readonly string _root;
+ private int Last { get; set; }
+ private string Root { get; }
public NodeBuilder(string root, string bitcoindPath)
{
- _root = root;
+ Root = root;
BitcoinD = bitcoindPath;
}
@@ -128,8 +128,8 @@ namespace WalletWasabi.Tests.NodeBuilding
public async Task<CoreNode> CreateNodeAsync(bool start = false)
{
- var child = Path.Combine(_root, _last.ToString());
- _last++;
+ var child = Path.Combine(Root, Last.ToString());
+ Last++;
try
{
var cfgPath = Path.Combine(child, "data", "bitcoin.conf");

MODIFY
WalletWasabi.Tests/NodeBuilding/NodeConfigParameters.cs
WalletWasabi.Tests/NodeBuilding/NodeConfigParameters.cs
@@ -11,15 +11,20 @@ namespace WalletWasabi.Tests.NodeBuilding
foreach (var kv in configParameters)
{
if (!ContainsKey(kv.Key))
+ {
Add(kv.Key, kv.Value);
}
}
+ }
public override string ToString()
{
StringBuilder builder = new StringBuilder();
foreach (var kv in this)
+ {
builder.AppendLine(kv.Key + "=" + kv.Value);
+ }
+
return builder.ToString();
}

MODIFY
WalletWasabi.Tests/P2pTests.cs
WalletWasabi.Tests/P2pTests.cs
@@ -159,7 +159,6 @@ namespace WalletWasabi.Tests
private void ConnectedNodes_Added(object sender, NodeEventArgs e)
{
- var nodes = sender as NodesCollection;
long nodeCount = Interlocked.Increment(ref _nodeCount);
if (nodeCount == 8)
{
@@ -171,7 +170,6 @@ namespace WalletWasabi.Tests
private void ConnectedNodes_Removed(object sender, NodeEventArgs e)
{
- var nodes = sender as NodesCollection;
var nodeCount = Interlocked.Decrement(ref _nodeCount);
// Trace is fine here, building the connections is more exciting than removing them.
Logger.LogTrace<P2pTests>($"Node count: {nodeCount}.");

MODIFY
WalletWasabi.Tests/RegTests.cs
WalletWasabi.Tests/RegTests.cs
@@ -39,6 +39,7 @@ namespace WalletWasabi.Tests
[Collection("RegTest collection")]
public class RegTests
{
+#pragma warning disable IDE0059 // Value assigned to symbol is never used
private RegTestFixture RegTestFixture { get; }
public RegTests(RegTestFixture regTestFixture)
@@ -1546,7 +1547,10 @@ namespace WalletWasabi.Tests
var tx0Id = await rpc.SendToAddressAsync(key.GetP2wpkhAddress(network), Money.Coins(1m),
replaceable: true);
while (wallet.Coins.Count == 0)
+ {
await Task.Delay(500); // Waits for the funding transaction get to the mempool.
+ }
+
Assert.Single(wallet.Coins);
// Test mixin
@@ -1564,7 +1568,9 @@ namespace WalletWasabi.Tests
await wallet.SendTransactionAsync(tx1Res.Transaction);
while (wallet.Coins.Count != 3)
+ {
await Task.Delay(500); // Waits for the funding transaction get to the mempool.
+ }
// There is a coin created by the latest spending transaction
Assert.Contains(wallet.Coins, x => x.TransactionId == tx1Res.Transaction.GetHash());
@@ -1584,7 +1590,9 @@ namespace WalletWasabi.Tests
await wallet.SendTransactionAsync(tx2Res.Transaction);
while (wallet.Coins.Count != 4)
+ {
await Task.Delay(500); // Waits for the transaction get to the mempool.
+ }
// There is a coin created by the latest spending transaction
Assert.Contains(wallet.Coins, x => x.TransactionId == tx2Res.Transaction.GetHash());
@@ -1705,7 +1713,10 @@ namespace WalletWasabi.Tests
var tx0Id = await rpc.SendToAddressAsync(key.GetP2wpkhAddress(network), Money.Coins(1m), replaceable: true);
while (wallet.Coins.Count == 0)
+ {
await Task.Delay(500); // Waits for the funding transaction get to the mempool.
+ }
+
Assert.Single(wallet.Coins);
Assert.True(wallet.Coins.First().IsReplaceable);
@@ -3386,7 +3397,10 @@ namespace WalletWasabi.Tests
{
await Task.Delay(1000);
times++;
- if (times >= 21) throw new TimeoutException("Wallet spends were not recognized.");
+ if (times >= 21)
+ {
+ throw new TimeoutException("Wallet spends were not recognized.");
+ }
}
SmartCoin[] unspentChanges = wallet.Coins.Where(x => x.Label == "ZeroLink Change" && x.Unspent).ToArray();
await wallet.ChaumianClient.DequeueCoinsFromMixAsync(unspentChanges);
@@ -3430,5 +3444,7 @@ namespace WalletWasabi.Tests
}
#endregion ClientTests
+
+#pragma warning restore IDE0059 // Value assigned to symbol is never used
}
}

MODIFY
WalletWasabi.Tests/TorTests.cs
WalletWasabi.Tests/TorTests.cs
@@ -67,7 +67,7 @@ namespace WalletWasabi.Tests
}
[Fact]
- private async Task TorIpIsNotTheRealOneAsync()
+ public async Task TorIpIsNotTheRealOneAsync()
{
var requestUri = "https://api.ipify.org/";
IPAddress realIp;

Cleanup tests based on VS2019