Apply Global.Instance pattern to test project
MODIFY
WalletWasabi.Tests/KeyManagementTests.cs
WalletWasabi.Tests/KeyManagementTests.cs
@@ -88,7 +88,7 @@ namespace WalletWasabi.Tests
{
string password = "password";
- var filePath = Path.Combine(Global.DataDir, nameof(CanSerialize), "Wallet.json");
+ var filePath = Path.Combine(Global.Instance.DataDir, nameof(CanSerialize), "Wallet.json");
DeleteFileAndDirectoryIfExists(filePath);
Logger.TurnOff();

MODIFY
WalletWasabi.Tests/LiveServerTests.cs
WalletWasabi.Tests/LiveServerTests.cs
@@ -23,7 +23,7 @@ namespace WalletWasabi.Tests
{
LiveServerTestsFixture = liveServerTestsFixture;
- var torManager = new TorProcessManager(Global.TorSocks5Endpoint, Global.TorLogsFile);
+ var torManager = new TorProcessManager(Global.Instance.TorSocks5Endpoint, Global.Instance.TorLogsFile);
torManager.Start(ensureRunning: true, dataDir: Path.GetFullPath(AppContext.BaseDirectory));
Task.Delay(3000).GetAwaiter().GetResult();
}
@@ -35,7 +35,7 @@ namespace WalletWasabi.Tests
[InlineData(NetworkType.Testnet)]
public async Task GetFeesAsync(NetworkType networkType)
{
- using (var client = new WasabiClient(LiveServerTestsFixture.UriMappings[networkType], Global.TorSocks5Endpoint))
+ using (var client = new WasabiClient(LiveServerTestsFixture.UriMappings[networkType], Global.Instance.TorSocks5Endpoint))
{
var feeEstimationPairs = await client.GetFeesAsync(1000);
@@ -48,7 +48,7 @@ namespace WalletWasabi.Tests
[InlineData(NetworkType.Testnet)]
public async Task GetFiltersAsync(NetworkType networkType)
{
- using (var client = new WasabiClient(LiveServerTestsFixture.UriMappings[networkType], Global.TorSocks5Endpoint))
+ using (var client = new WasabiClient(LiveServerTestsFixture.UriMappings[networkType], Global.Instance.TorSocks5Endpoint))
{
var filterModel = StartingFilters.GetStartingFilter(Network.GetNetwork(networkType.ToString()));
@@ -64,7 +64,7 @@ namespace WalletWasabi.Tests
[InlineData(NetworkType.Testnet)]
public async Task GetAllRoundStatesAsync(NetworkType networkType)
{
- using (var client = new SatoshiClient(LiveServerTestsFixture.UriMappings[networkType], Global.TorSocks5Endpoint))
+ using (var client = new SatoshiClient(LiveServerTestsFixture.UriMappings[networkType], Global.Instance.TorSocks5Endpoint))
{
var states = await client.GetAllRoundStatesAsync();
Assert.True(states.NotNullAndNotEmpty());
@@ -81,7 +81,7 @@ namespace WalletWasabi.Tests
[InlineData(NetworkType.Testnet)]
public async Task GetExchangeRateAsync(NetworkType networkType) // xunit wtf: If this function is called GetExchangeRatesAsync, it'll stuck on 1 CPU VMs (Manjuro, Fedora)
{
- using (var client = new WasabiClient(LiveServerTestsFixture.UriMappings[networkType], Global.TorSocks5Endpoint))
+ using (var client = new WasabiClient(LiveServerTestsFixture.UriMappings[networkType], Global.Instance.TorSocks5Endpoint))
{
var exchangeRates = await client.GetExchangeRatesAsync();

MODIFY
WalletWasabi.Tests/NodeBuilding/NodeBuilder.cs
WalletWasabi.Tests/NodeBuilding/NodeBuilder.cs
@@ -26,7 +26,7 @@ namespace WalletWasabi.Tests.NodeBuilding
{
using (await Lock.LockAsync())
{
- WorkingDirectory = Path.Combine(Global.DataDir, caller);
+ WorkingDirectory = Path.Combine(Global.Instance.DataDir, caller);
version = version ?? "0.18.0";
var path = await EnsureDownloadedAsync(version);
return new NodeBuilder(WorkingDirectory, path);
@@ -61,7 +61,7 @@ namespace WalletWasabi.Tests.NodeBuilding
string bitcoindFolderName = $"bitcoin-{version}";
// Remove old bitcoind folders.
- IEnumerable<string> existingBitcoindFolderPaths = Directory.EnumerateDirectories(Global.DataDir, "bitcoin-*", SearchOption.TopDirectoryOnly);
+ IEnumerable<string> existingBitcoindFolderPaths = Directory.EnumerateDirectories(Global.Instance.DataDir, "bitcoin-*", SearchOption.TopDirectoryOnly);
foreach (string dirPath in existingBitcoindFolderPaths)
{
string dirName = Path.GetFileName(dirPath);
@@ -73,13 +73,13 @@ namespace WalletWasabi.Tests.NodeBuilding
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
- bitcoind = Path.Combine(Global.DataDir, bitcoindFolderName, "bin", "bitcoind.exe");
+ bitcoind = Path.Combine(Global.Instance.DataDir, bitcoindFolderName, "bin", "bitcoind.exe");
if (File.Exists(bitcoind))
{
return bitcoind;
}
- zip = Path.Combine(Global.DataDir, $"bitcoin-{version}-win64.zip");
+ zip = Path.Combine(Global.Instance.DataDir, $"bitcoin-{version}-win64.zip");
string url = string.Format("https://bitcoincore.org/bin/bitcoin-core-{0}/" + Path.GetFileName(zip), version);
using (var client = new HttpClient())
{
@@ -91,15 +91,15 @@ namespace WalletWasabi.Tests.NodeBuilding
}
else
{
- bitcoind = Path.Combine(Global.DataDir, bitcoindFolderName, "bin", "bitcoind");
+ bitcoind = Path.Combine(Global.Instance.DataDir, bitcoindFolderName, "bin", "bitcoind");
if (File.Exists(bitcoind))
{
return bitcoind;
}
zip = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ?
- Path.Combine(Global.DataDir, $"bitcoin-{version}-x86_64-linux-gnu.tar.gz")
- : Path.Combine(Global.DataDir, $"bitcoin-{version}-osx64.tar.gz");
+ Path.Combine(Global.Instance.DataDir, $"bitcoin-{version}-x86_64-linux-gnu.tar.gz")
+ : Path.Combine(Global.Instance.DataDir, $"bitcoin-{version}-osx64.tar.gz");
string url = string.Format("https://bitcoincore.org/bin/bitcoin-core-{0}/" + Path.GetFileName(zip), version);
using (var client = new HttpClient())
@@ -108,7 +108,7 @@ namespace WalletWasabi.Tests.NodeBuilding
var data = await client.GetByteArrayAsync(url);
await File.WriteAllBytesAsync(zip, data);
- using (var process = Process.Start("tar", "-zxvf " + zip + " -C " + Global.DataDir))
+ using (var process = Process.Start("tar", "-zxvf " + zip + " -C " + Global.Instance.DataDir))
{
process.WaitForExit();
}

MODIFY
WalletWasabi.Tests/P2pTests.cs
WalletWasabi.Tests/P2pTests.cs
@@ -49,9 +49,9 @@ namespace WalletWasabi.Tests
throw new NotSupportedException(network.ToString());
}
- var addressManagerFolderPath = Path.Combine(Global.DataDir, "AddressManager");
+ var addressManagerFolderPath = Path.Combine(Global.Instance.DataDir, "AddressManager");
var addressManagerFilePath = Path.Combine(addressManagerFolderPath, $"AddressManager{network}.dat");
- var blocksFolderPath = Path.Combine(Global.DataDir, "Blocks", network.ToString());
+ var blocksFolderPath = Path.Combine(Global.Instance.DataDir, "Blocks", network.ToString());
var connectionParameters = new NodeConnectionParameters();
AddressManager addressManager = null;
try
@@ -79,18 +79,18 @@ namespace WalletWasabi.Tests
var nodes = new NodesGroup(network, connectionParameters, requirements: Helpers.Constants.NodeRequirements);
BitcoinStore bitcoinStore = new BitcoinStore();
- await bitcoinStore.InitializeAsync(Path.Combine(Global.DataDir, nameof(TestServicesAsync)), network);
+ await bitcoinStore.InitializeAsync(Path.Combine(Global.Instance.DataDir, nameof(TestServicesAsync)), network);
KeyManager keyManager = KeyManager.CreateNew(out _, "password");
- WasabiSynchronizer syncer = new WasabiSynchronizer(network, bitcoinStore, new Uri("http://localhost:12345"), Global.TorSocks5Endpoint);
+ WasabiSynchronizer syncer = new WasabiSynchronizer(network, bitcoinStore, new Uri("http://localhost:12345"), Global.Instance.TorSocks5Endpoint);
WalletService walletService = new WalletService(
bitcoinStore,
keyManager,
syncer,
- new CcjClient(syncer, network, keyManager, new Uri("http://localhost:12345"), Global.TorSocks5Endpoint),
+ new CcjClient(syncer, network, keyManager, new Uri("http://localhost:12345"), Global.Instance.TorSocks5Endpoint),
memPoolService,
nodes,
- Global.DataDir,
+ Global.Instance.DataDir,
new ServiceConfiguration(50, 2, 21, 50, new IPEndPoint(IPAddress.Loopback, network.DefaultPort), Money.Coins(0.0001m)));
Assert.True(Directory.Exists(blocksFolderPath));

MODIFY
WalletWasabi.Tests/RegTests.cs
WalletWasabi.Tests/RegTests.cs
@@ -84,7 +84,7 @@ namespace WalletWasabi.Tests
var network = Backend.Global.RpcClient.Network;
var serviceConfiguration = new ServiceConfiguration(2, 2, 21, 50, RegTestFixture.BackendRegTestNode.Endpoint, Money.Coins(0.0001m));
var bitcoinStore = new BitcoinStore();
- var dir = Path.Combine(Global.DataDir, caller);
+ var dir = Path.Combine(Global.Instance.DataDir, caller);
await bitcoinStore.InitializeAsync(dir, network);
return ("password", Backend.Global.RpcClient, network, Backend.Global.Coordinator, serviceConfiguration, bitcoinStore);
}
@@ -162,7 +162,7 @@ namespace WalletWasabi.Tests
{
(string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore) = await InitializeTestEnvironmentAsync(1);
- var indexBuilderServiceDir = Path.Combine(Global.DataDir, nameof(IndexBuilderService));
+ var indexBuilderServiceDir = Path.Combine(Global.Instance.DataDir, nameof(IndexBuilderService));
var indexFilePath = Path.Combine(indexBuilderServiceDir, $"Index{rpc.Network}.dat");
var utxoSetFilePath = Path.Combine(indexBuilderServiceDir, $"UtxoSet{rpc.Network}.dat");
@@ -541,7 +541,7 @@ namespace WalletWasabi.Tests
var chaumianClient = new CcjClient(synchronizer, rpc.Network, keyManager, new Uri(RegTestFixture.BackendEndPoint), null);
// 5. Create wallet service.
- var workDir = Path.Combine(Global.DataDir, nameof(WalletTestsAsync));
+ var workDir = Path.Combine(Global.Instance.DataDir, nameof(WalletTestsAsync));
var wallet = new WalletService(bitcoinStore, keyManager, synchronizer, chaumianClient, memPoolService, nodes, workDir, serviceConfiguration);
wallet.NewFilterProcessed += Wallet_NewFilterProcessed;
@@ -769,7 +769,7 @@ namespace WalletWasabi.Tests
var chaumianClient = new CcjClient(synchronizer, rpc.Network, keyManager, new Uri(RegTestFixture.BackendEndPoint), null);
// 6. Create wallet service.
- var workDir = Path.Combine(Global.DataDir, nameof(SendTestsFromHiddenWalletAsync));
+ var workDir = Path.Combine(Global.Instance.DataDir, nameof(SendTestsFromHiddenWalletAsync));
var wallet = new WalletService(bitcoinStore, keyManager, synchronizer, chaumianClient, memPoolService, nodes, workDir, serviceConfiguration);
wallet.NewFilterProcessed += Wallet_NewFilterProcessed;
@@ -1212,7 +1212,7 @@ namespace WalletWasabi.Tests
var chaumianClient = new CcjClient(synchronizer, rpc.Network, keyManager, new Uri(RegTestFixture.BackendEndPoint), null);
// 6. Create wallet service.
- var workDir = Path.Combine(Global.DataDir, nameof(SendTestsFromHiddenWalletAsync));
+ var workDir = Path.Combine(Global.Instance.DataDir, nameof(SendTestsFromHiddenWalletAsync));
var wallet = new WalletService(bitcoinStore, keyManager, synchronizer, chaumianClient, memPoolService, nodes, workDir, serviceConfiguration);
wallet.NewFilterProcessed += Wallet_NewFilterProcessed;
@@ -1375,7 +1375,7 @@ namespace WalletWasabi.Tests
var chaumianClient = new CcjClient(synchronizer, rpc.Network, keyManager, new Uri(RegTestFixture.BackendEndPoint), null);
// 6. Create wallet service.
- var workDir = Path.Combine(Global.DataDir, nameof(SendTestsFromHiddenWalletAsync));
+ var workDir = Path.Combine(Global.Instance.DataDir, nameof(SendTestsFromHiddenWalletAsync));
var wallet = new WalletService(bitcoinStore, keyManager, synchronizer, chaumianClient, memPoolService, nodes, workDir, serviceConfiguration);
wallet.NewFilterProcessed += Wallet_NewFilterProcessed;
@@ -1539,7 +1539,7 @@ namespace WalletWasabi.Tests
var chaumianClient = new CcjClient(synchronizer, rpc.Network, keyManager, new Uri(RegTestFixture.BackendEndPoint), null);
// 6. Create wallet service.
- var workDir = Path.Combine(Global.DataDir, nameof(SendTestsFromHiddenWalletAsync));
+ var workDir = Path.Combine(Global.Instance.DataDir, nameof(SendTestsFromHiddenWalletAsync));
var wallet = new WalletService(bitcoinStore, keyManager, synchronizer, chaumianClient, memPoolService, nodes, workDir, serviceConfiguration);
wallet.NewFilterProcessed += Wallet_NewFilterProcessed;
@@ -1705,7 +1705,7 @@ namespace WalletWasabi.Tests
var chaumianClient = new CcjClient(synchronizer, rpc.Network, keyManager, new Uri(RegTestFixture.BackendEndPoint), null);
// 6. Create wallet service.
- var workDir = Path.Combine(Global.DataDir, nameof(SendTestsFromHiddenWalletAsync));
+ var workDir = Path.Combine(Global.Instance.DataDir, nameof(SendTestsFromHiddenWalletAsync));
var wallet = new WalletService(bitcoinStore, keyManager, synchronizer, chaumianClient, memPoolService, nodes, workDir, serviceConfiguration);
wallet.NewFilterProcessed += Wallet_NewFilterProcessed;
@@ -1799,7 +1799,7 @@ namespace WalletWasabi.Tests
var offchainTxId = network.Consensus.ConsensusFactory.CreateTransaction().GetHash();
var mempoolTxId = rpc.SendToAddress(new Key().PubKey.GetSegwitAddress(network), Money.Coins(1));
- var folder = Path.Combine(Global.DataDir, nameof(CcjCoordinatorCtorTestsAsync));
+ var folder = Path.Combine(Global.Instance.DataDir, nameof(CcjCoordinatorCtorTestsAsync));
await IoHelpers.DeleteRecursivelyWithMagicDustAsync(folder);
Directory.CreateDirectory(folder);
var cjfile = Path.Combine(folder, $"CoinJoins{network}.txt");
@@ -1850,7 +1850,7 @@ namespace WalletWasabi.Tests
coordinator.AbortAllRoundsInInputRegistration(nameof(RegTests), "");
Uri baseUri = new Uri(RegTestFixture.BackendEndPoint);
- using (var torClient = new TorHttpClient(baseUri, Global.TorSocks5Endpoint))
+ using (var torClient = new TorHttpClient(baseUri, Global.Instance.TorSocks5Endpoint))
using (var satoshiClient = new SatoshiClient(baseUri, null))
{
#region PostInputsGetStates
@@ -2369,7 +2369,7 @@ namespace WalletWasabi.Tests
coordinator.AbortAllRoundsInInputRegistration(nameof(RegTests), "");
Uri baseUri = new Uri(RegTestFixture.BackendEndPoint);
- using (var torClient = new TorHttpClient(baseUri, Global.TorSocks5Endpoint))
+ using (var torClient = new TorHttpClient(baseUri, Global.Instance.TorSocks5Endpoint))
using (var satoshiClient = new SatoshiClient(baseUri, null))
{
var round = coordinator.GetCurrentInputRegisterableRoundOrDefault();
@@ -3316,7 +3316,7 @@ namespace WalletWasabi.Tests
// 3. Create wasabi synchronizer service.
var synchronizer = new WasabiSynchronizer(network, bitcoinStore, new Uri(RegTestFixture.BackendEndPoint), null);
- var indexFilePath2 = Path.Combine(Global.DataDir, nameof(CoinJoinMultipleRoundTestsAsync), $"Index{network}2.dat");
+ var indexFilePath2 = Path.Combine(Global.Instance.DataDir, nameof(CoinJoinMultipleRoundTestsAsync), $"Index{network}2.dat");
var synchronizer2 = new WasabiSynchronizer(network, bitcoinStore, new Uri(RegTestFixture.BackendEndPoint), null);
// 4. Create key manager service.
@@ -3330,11 +3330,11 @@ namespace WalletWasabi.Tests
var chaumianClient2 = new CcjClient(synchronizer, network, keyManager2, new Uri(RegTestFixture.BackendEndPoint), null);
// 6. Create wallet service.
- var workDir = Path.Combine(Global.DataDir, nameof(CoinJoinMultipleRoundTestsAsync));
+ var workDir = Path.Combine(Global.Instance.DataDir, nameof(CoinJoinMultipleRoundTestsAsync));
var wallet = new WalletService(bitcoinStore, keyManager, synchronizer, chaumianClient, memPoolService, nodes, workDir, serviceConfiguration);
wallet.NewFilterProcessed += Wallet_NewFilterProcessed;
- var workDir2 = Path.Combine(Global.DataDir, $"{nameof(CoinJoinMultipleRoundTestsAsync)}2");
+ var workDir2 = Path.Combine(Global.Instance.DataDir, $"{nameof(CoinJoinMultipleRoundTestsAsync)}2");
var wallet2 = new WalletService(bitcoinStore, keyManager2, synchronizer2, chaumianClient2, memPoolService2, nodes2, workDir2, serviceConfiguration);
// Get some money, make it confirm.

MODIFY
WalletWasabi.Tests/StoreTests.cs
WalletWasabi.Tests/StoreTests.cs
@@ -174,7 +174,7 @@ namespace WalletWasabi.Tests
{
var indexStore = new IndexStore();
- var dir = Path.Combine(Global.DataDir, nameof(IndexStoreTestsAsync));
+ var dir = Path.Combine(Global.Instance.DataDir, nameof(IndexStoreTestsAsync));
var network = Network.Main;
await indexStore.InitializeAsync(dir, network, new HashChain());
}
@@ -339,8 +339,8 @@ namespace WalletWasabi.Tests
[Fact]
public async Task IoManagerTestsAsync()
{
- var file1 = Path.Combine(Global.DataDir, nameof(IoManagerTestsAsync), $"file1.dat");
- var file2 = Path.Combine(Global.DataDir, nameof(IoManagerTestsAsync), $"file2.dat");
+ var file1 = Path.Combine(Global.Instance.DataDir, nameof(IoManagerTestsAsync), $"file1.dat");
+ var file2 = Path.Combine(Global.Instance.DataDir, nameof(IoManagerTestsAsync), $"file2.dat");
Random random = new Random();
List<string> lines = new List<string>();
@@ -540,7 +540,7 @@ namespace WalletWasabi.Tests
[Fact]
public async Task IoTestsAsync()
{
- var file = Path.Combine(Global.DataDir, nameof(IoTestsAsync), $"file.dat");
+ var file = Path.Combine(Global.Instance.DataDir, nameof(IoTestsAsync), $"file.dat");
IoManager ioman = new IoManager(file);
ioman.DeleteMe();

Apply Global.Instance pattern to test project