Remove references to Backend.Global.Instance
MODIFY
WalletWasabi.Backend/Controllers/BatchController.cs
WalletWasabi.Backend/Controllers/BatchController.cs
@@ -19,6 +19,11 @@ namespace WalletWasabi.Backend.Controllers
[Route("api/v" + Helpers.Constants.BackendMajorVersion + "/btc/[controller]")]
public class BatchController : Controller
{
+ public BatchController(Global backendGlobal)
+ {
+ Global = backendGlobal;
+ }
+ public Global Global { get; }
public BlockchainController BlockchainController { get; }
public ChaumianCoinJoinController ChaumianCoinJoinController { get; }
public HomeController HomeController { get; }
@@ -52,7 +57,7 @@ namespace WalletWasabi.Backend.Controllers
var knownHash = new uint256(bestKnownBlockHash);
- (Height bestHeight, IEnumerable<FilterModel> filters) = Global.Instance.IndexBuilderService.GetFilterLinesExcluding(knownHash, maxNumberOfFilters, out bool found);
+ (Height bestHeight, IEnumerable<FilterModel> filters) = Global.IndexBuilderService.GetFilterLinesExcluding(knownHash, maxNumberOfFilters, out bool found);
var response = new SynchronizeResponse { Filters = Enumerable.Empty<FilterModel>(), BestHeight = bestHeight };

MODIFY
WalletWasabi.Backend/Controllers/BlockchainController.cs
WalletWasabi.Backend/Controllers/BlockchainController.cs
@@ -24,9 +24,14 @@ namespace WalletWasabi.Backend.Controllers
{
private IMemoryCache Cache { get; }
- private static RPCClient RpcClient => Global.Instance.RpcClient;
+ BlockchainController(Global backendGlobal)
+ {
+ Global = backendGlobal;
+ }
+ public Global Global { get; }
+ private RPCClient RpcClient => Global.RpcClient;
- private static Network Network => Global.Instance.Config.Network;
+ private Network Network => Global.Config.Network;
public BlockchainController(IMemoryCache memoryCache)
{
@@ -183,7 +188,7 @@ namespace WalletWasabi.Backend.Controllers
if (!Cache.TryGetValue(cacheKey, out IEnumerable<string> hashes))
{
- uint256[] transactionHashes = await Global.Instance.RpcClient.GetRawMempoolAsync();
+ uint256[] transactionHashes = await Global.RpcClient.GetRawMempoolAsync();
hashes = transactionHashes.Select(x => x.ToString());
@@ -279,7 +284,7 @@ namespace WalletWasabi.Backend.Controllers
var knownHash = new uint256(bestKnownBlockHash);
- (Height bestHeight, IEnumerable<FilterModel> filters) = Global.Instance.IndexBuilderService.GetFilterLinesExcluding(knownHash, count, out bool found);
+ (Height bestHeight, IEnumerable<FilterModel> filters) = Global.IndexBuilderService.GetFilterLinesExcluding(knownHash, count, out bool found);
if (!found)
{

MODIFY
WalletWasabi.Backend/Controllers/ChaumianCoinJoinController.cs
WalletWasabi.Backend/Controllers/ChaumianCoinJoinController.cs
@@ -34,11 +34,16 @@ namespace WalletWasabi.Backend.Controllers
[Route("api/v" + Constants.BackendMajorVersion + "/btc/[controller]")]
public class ChaumianCoinJoinController : Controller
{
- private static RPCClient RpcClient => Global.Instance.RpcClient;
+ public ChaumianCoinJoinController(Global backendGlobal)
+ {
+ Global = backendGlobal;
+ }
+ public Global Global { get; }
+ private RPCClient RpcClient => Global.RpcClient;
- private static Network Network => Global.Instance.Config.Network;
+ private Network Network => Global.Config.Network;
- private static CcjCoordinator Coordinator => Global.Instance.Coordinator;
+ private CcjCoordinator Coordinator => Global.Coordinator;
/// <summary>
/// Satoshi gets various status information.
@@ -54,7 +59,7 @@ namespace WalletWasabi.Backend.Controllers
return Ok(response);
}
- public static IEnumerable<CcjRunningRoundState> GetStatesCollection()
+ public IEnumerable<CcjRunningRoundState> GetStatesCollection()
{
var response = new List<CcjRunningRoundState>();

MODIFY
WalletWasabi.Backend/Global.cs
WalletWasabi.Backend/Global.cs
@@ -15,7 +15,6 @@ namespace WalletWasabi.Backend
{
public class Global
{
- public static Global Instance { get; } = new Global();
public string DataDir { get; }
public RPCClient RpcClient { get; private set; }

MODIFY
WalletWasabi.Backend/Program.cs
WalletWasabi.Backend/Program.cs
@@ -25,17 +25,18 @@ namespace WalletWasabi.Backend
{
try
{
- Logger.InitializeDefaults(Path.Combine(Global.Instance.DataDir, "Logs.txt"));
+ var backendGlobal = new Global();
+ Logger.InitializeDefaults(Path.Combine(backendGlobal.DataDir, "Logs.txt"));
Logger.LogStarting("Wasabi Backend");
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
- var configFilePath = Path.Combine(Global.Instance.DataDir, "Config.json");
+ var configFilePath = Path.Combine(backendGlobal.DataDir, "Config.json");
var config = new Config(configFilePath);
await config.LoadOrCreateDefaultFileAsync();
Logger.LogInfo<Config>("Config is successfully initialized.");
- var roundConfigFilePath = Path.Combine(Global.Instance.DataDir, "CcjRoundConfig.json");
+ var roundConfigFilePath = Path.Combine(backendGlobal.DataDir, "CcjRoundConfig.json");
var roundConfig = new CcjRoundConfig(roundConfigFilePath);
await roundConfig.LoadOrCreateDefaultFileAsync();
Logger.LogInfo<CcjRoundConfig>("RoundConfig is successfully initialized.");
@@ -44,7 +45,7 @@ namespace WalletWasabi.Backend
credentials: RPCCredentialString.Parse(config.BitcoinRpcConnectionString),
network: config.Network);
- await Global.Instance.InitializeAsync(config, roundConfig, rpc);
+ await backendGlobal.InitializeAsync(config, roundConfig, rpc);
try
{
@@ -52,14 +53,14 @@ namespace WalletWasabi.Backend
UnversionedWebBuilder.CreateDownloadTextWithVersionHtml();
UnversionedWebBuilder.CloneAndUpdateOnionIndexHtml();
- if (File.Exists(Global.Instance.Coordinator.CoinJoinsFilePath))
+ if (File.Exists(backendGlobal.Coordinator.CoinJoinsFilePath))
{
- string[] allLines = File.ReadAllLines(Global.Instance.Coordinator.CoinJoinsFilePath);
+ string[] allLines = File.ReadAllLines(backendGlobal.Coordinator.CoinJoinsFilePath);
Last5CoinJoins = allLines.TakeLast(5).Reverse().ToList();
- UnversionedWebBuilder.UpdateCoinJoinsHtml(Last5CoinJoins);
+ UnversionedWebBuilder.UpdateCoinJoinsHtml(backendGlobal, Last5CoinJoins);
}
- Global.Instance.Coordinator.CoinJoinBroadcasted += Coordinator_CoinJoinBroadcasted;
+ backendGlobal.Coordinator.CoinJoinBroadcasted += (s, a) => Coordinator_CoinJoinBroadcasted(s, a, backendGlobal);
}
catch (Exception ex)
{
@@ -93,7 +94,7 @@ namespace WalletWasabi.Backend
Logger.LogWarning(e?.ExceptionObject as Exception, "UnhandledException");
}
- private static void Coordinator_CoinJoinBroadcasted(object sender, Transaction tx)
+ private static void Coordinator_CoinJoinBroadcasted(object sender, Transaction tx, Global backendGlobal)
{
try
{
@@ -104,7 +105,7 @@ namespace WalletWasabi.Backend
Last5CoinJoins.RemoveLast();
}
Last5CoinJoins.Insert(0, tx.GetHash().ToString());
- UnversionedWebBuilder.UpdateCoinJoinsHtml(Last5CoinJoins);
+ UnversionedWebBuilder.UpdateCoinJoinsHtml(backendGlobal, Last5CoinJoins);
}
}
catch (Exception ex)

MODIFY
WalletWasabi.Backend/Startup.cs
WalletWasabi.Backend/Startup.cs
@@ -49,6 +49,7 @@ namespace WalletWasabi.Backend
services.AddLogging(Logging => Logging.AddFilter((s, level) => level >= Microsoft.Extensions.Logging.LogLevel.Warning));
services.AddSingleton<IExchangeRateProvider>(new ExchangeRateProvider());
+ services.AddSingleton<Global>(new Global());
services.AddResponseCompression();
}
@@ -56,7 +57,7 @@ namespace WalletWasabi.Backend
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
#pragma warning disable IDE0060 // Remove unused parameter
- public void Configure(IApplicationBuilder app, IHostingEnvironment env)
+ public void Configure(IApplicationBuilder app, IHostingEnvironment env, Global backendGlobal)
#pragma warning restore IDE0060 // Remove unused parameter
{
app.UseStaticFiles();
@@ -80,34 +81,34 @@ namespace WalletWasabi.Backend
app.UseMvc();
var applicationLifetime = app.ApplicationServices.GetRequiredService<IApplicationLifetime>();
- applicationLifetime.ApplicationStopping.Register(OnShutdown); // Do not register async, that won't hold up the shutdown
+ applicationLifetime.ApplicationStopping.Register(() => OnShutdown(backendGlobal)); // Don't register async, that won't hold up the shutdown
}
- private void OnShutdown()
+ private void OnShutdown(Global backendGlobal)
{
- CleanupAsync().GetAwaiter().GetResult(); // This is needed, if async function is registered then it won't wait until it finishes
+ CleanupAsync(backendGlobal).GetAwaiter().GetResult(); // This is needed, if async function is registered then it won't wait until it finishes
}
- private async Task CleanupAsync()
+ private async Task CleanupAsync(Global backendGlobal)
{
- Global.Instance.Coordinator?.Dispose();
+ backendGlobal.Coordinator?.Dispose();
Logger.LogInfo<Startup>("Coordinator is disposed.");
- if (Global.Instance.IndexBuilderService != null)
+ if (backendGlobal.IndexBuilderService != null)
{
- await Global.Instance.IndexBuilderService.StopAsync();
+ await backendGlobal.IndexBuilderService.StopAsync();
Logger.LogInfo<Startup>("IndexBuilderService is disposed.");
}
- if (Global.Instance.RoundConfigWatcher != null)
+ if (backendGlobal.RoundConfigWatcher != null)
{
- await Global.Instance.RoundConfigWatcher.StopAsync();
+ await backendGlobal.RoundConfigWatcher.StopAsync();
Logger.LogInfo<Startup>("RoundConfigWatcher is disposed.");
}
- if (Global.Instance.LocalNode != null)
+ if (backendGlobal.LocalNode != null)
{
- Global.Instance.DisconnectDisposeNullLocalNode();
+ backendGlobal.DisconnectDisposeNullLocalNode();
Logger.LogInfo<Startup>("LocalNode is disposed.");
}

MODIFY
WalletWasabi.Backend/UnversionedWebBuilder.cs
WalletWasabi.Backend/UnversionedWebBuilder.cs
@@ -41,7 +41,7 @@ namespace WalletWasabi.Backend
File.WriteAllText(onionPath, content);
}
- public static void UpdateCoinJoinsHtml(IEnumerable<string> coinJoins)
+ public static void UpdateCoinJoinsHtml(Global backendGlobal, IEnumerable<string> coinJoins)
{
var filePath = CreateFilePath("coinjoins-table.html");
var onionFilePath = CreateFilePath("onion-coinjoins-table.html");
@@ -51,7 +51,7 @@ namespace WalletWasabi.Backend
var endContent = "</ul>";
string blockstreamPath;
string onionBlockstreamPath;
- if (Global.Instance.Config.Network == Network.TestNet)
+ if (backendGlobal.Config.Network == Network.TestNet)
{
blockstreamPath = "https://blockstream.info/testnet/tx/";
onionBlockstreamPath = "http://explorerzydxu5ecjrkwceayqybizmpjjznk5izmitf2modhcusuqlid.onion/testnet/tx/";

MODIFY
WalletWasabi.Tests/RegTests.cs
WalletWasabi.Tests/RegTests.cs
@@ -49,9 +49,9 @@ namespace WalletWasabi.Tests
RegTestFixture = regTestFixture;
}
- private async Task AssertFiltersInitializedAsync()
+ private async Task AssertFiltersInitializedAsync(Backend.Global global)
{
- var firstHash = await Backend.Global.Instance.RpcClient.GetBlockHashAsync(0);
+ var firstHash = await global.RpcClient.GetBlockHashAsync(0);
while (true)
{
using (var client = new WasabiClient(new Uri(RegTestFixture.BackendEndPoint), null))
@@ -72,21 +72,22 @@ namespace WalletWasabi.Tests
}
}
- private async Task<(string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore)> InitializeTestEnvironmentAsync(int numberOfBlocksToGenerate, [CallerMemberName] string caller = null)
+ private async Task<(string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore, Backend.Global backendGlobal)> InitializeTestEnvironmentAsync(int numberOfBlocksToGenerate, [CallerMemberName] string caller = null)
{
- await AssertFiltersInitializedAsync(); // Make sure fitlers are created on the server side.
+ var global = new Backend.Global();
+ await AssertFiltersInitializedAsync(global); // Make sure fitlers are created on the server side.
if (numberOfBlocksToGenerate != 0)
{
- await Backend.Global.Instance.RpcClient.GenerateAsync(numberOfBlocksToGenerate); // Make sure everything is confirmed.
+ await global.RpcClient.GenerateAsync(numberOfBlocksToGenerate); // Make sure everything is confirmed.
}
- Backend.Global.Instance.Coordinator.UtxoReferee.Clear();
+ global.Coordinator.UtxoReferee.Clear();
- var network = Backend.Global.Instance.RpcClient.Network;
+ var network = 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.Instance.DataDir, caller);
await bitcoinStore.InitializeAsync(dir, network);
- return ("password", Backend.Global.Instance.RpcClient, network, Backend.Global.Instance.Coordinator, serviceConfiguration, bitcoinStore);
+ return ("password", global.RpcClient, network, global.Coordinator, serviceConfiguration, bitcoinStore, global);
}
#region BackendTests
@@ -122,7 +123,7 @@ namespace WalletWasabi.Tests
[Fact]
public async Task BroadcastReplayTxAsync()
{
- (string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore) = await InitializeTestEnvironmentAsync(1);
+ (string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore, Backend.Global backendGlobal) = await InitializeTestEnvironmentAsync(1);
var utxos = await rpc.ListUnspentAsync();
var utxo = utxos[0];
@@ -142,7 +143,7 @@ namespace WalletWasabi.Tests
[Fact]
public async Task BroadcastInvalidTxAsync()
{
- (string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore) = await InitializeTestEnvironmentAsync(1);
+ (string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore, Backend.Global backendGlobal) = await InitializeTestEnvironmentAsync(1);
var content = new StringContent($"''", Encoding.UTF8, "application/json");
@@ -160,13 +161,13 @@ namespace WalletWasabi.Tests
[Fact]
public async Task FilterBuilderTestAsync()
{
- (string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore) = await InitializeTestEnvironmentAsync(1);
+ (string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore, Backend.Global backendGlobal) = await InitializeTestEnvironmentAsync(1);
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");
- var indexBuilderService = new IndexBuilderService(rpc, Backend.Global.Instance.TrustedNodeNotifyingBehavior, indexFilePath, utxoSetFilePath);
+ var indexBuilderService = new IndexBuilderService(rpc, backendGlobal.TrustedNodeNotifyingBehavior, indexFilePath, utxoSetFilePath);
try
{
indexBuilderService.Synchronize();
@@ -229,7 +230,7 @@ namespace WalletWasabi.Tests
[Fact]
public async Task AllFeeEstimateRpcAsync()
{
- (string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore) = await InitializeTestEnvironmentAsync(1);
+ (string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore, Backend.Global backendGlobal) = await InitializeTestEnvironmentAsync(1);
var estimations = await rpc.EstimateAllFeeAsync(EstimateSmartFeeMode.Conservative, simulateIfRegTest: true, tolerateBitcoinCoreBrainfuck: true);
Assert.Equal(Constants.OneDayConfirmationTarget, estimations.Estimations.Count);
@@ -255,7 +256,7 @@ namespace WalletWasabi.Tests
[Fact]
public async Task MempoolAsync()
{
- (string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore) = await InitializeTestEnvironmentAsync(1);
+ (string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore, Backend.Global backendGlobal) = await InitializeTestEnvironmentAsync(1);
var mempoolService = new MempoolService();
Node node = await RegTestFixture.BackendRegTestNode.CreateNodeClientAsync();
@@ -303,7 +304,7 @@ namespace WalletWasabi.Tests
[Fact]
public async Task FilterDownloaderTestAsync()
{
- (string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore) = await InitializeTestEnvironmentAsync(1);
+ (string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore, Backend.Global backendGlobal) = await InitializeTestEnvironmentAsync(1);
var synchronizer = new WasabiSynchronizer(rpc.Network, bitcoinStore, new Uri(RegTestFixture.BackendEndPoint), null);
try
@@ -368,7 +369,7 @@ namespace WalletWasabi.Tests
[Fact]
public async Task ReorgTestAsync()
{
- (string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore) = await InitializeTestEnvironmentAsync(1);
+ (string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore, Backend.Global backendGlobal) = await InitializeTestEnvironmentAsync(1);
var keyManager = KeyManager.CreateNew(out _, password);
@@ -397,14 +398,14 @@ namespace WalletWasabi.Tests
bitcoinStore.IndexStore.Reorged += ReorgTestAsync_Downloader_Reorged;
// Test initial synchronization.
- await WaitForIndexesToSyncAsync(TimeSpan.FromSeconds(90), bitcoinStore);
+ await WaitForIndexesToSyncAsync(backendGlobal, TimeSpan.FromSeconds(90), bitcoinStore);
var tip = await rpc.GetBestBlockHashAsync();
Assert.Equal(tip, bitcoinStore.HashChain.TipHash);
var tipBlock = await rpc.GetBlockHeaderAsync(tip);
Assert.Equal(tipBlock.HashPrevBlock, bitcoinStore.HashChain.GetChain().Select(x => x.hash).ToArray()[bitcoinStore.HashChain.HashCount - 2]);
- var utxoPath = Backend.Global.Instance.IndexBuilderService.Bech32UtxoSetFilePath;
+ var utxoPath = backendGlobal.IndexBuilderService.Bech32UtxoSetFilePath;
var utxoLines = await File.ReadAllTextAsync(utxoPath);
Assert.Contains(tx1.ToString(), utxoLines);
Assert.Contains(tx2.ToString(), utxoLines);
@@ -419,7 +420,7 @@ namespace WalletWasabi.Tests
var tx1bumpRes = await rpc.BumpFeeAsync(tx1); // RBF it
await rpc.GenerateAsync(5);
- await WaitForIndexesToSyncAsync(TimeSpan.FromSeconds(90), bitcoinStore);
+ await WaitForIndexesToSyncAsync(backendGlobal, TimeSpan.FromSeconds(90), bitcoinStore);
utxoLines = await File.ReadAllTextAsync(utxoPath);
Assert.Contains(tx1bumpRes.TransactionId.ToString(), utxoLines); // assert the tx1bump is the correct tx
@@ -487,9 +488,9 @@ namespace WalletWasabi.Tests
}
}
- private async Task WaitForIndexesToSyncAsync(TimeSpan timeout, BitcoinStore bitcoinStore)
+ private async Task WaitForIndexesToSyncAsync(Backend.Global backendGlobal, TimeSpan timeout, BitcoinStore bitcoinStore)
{
- var bestHash = await Backend.Global.Instance.RpcClient.GetBestBlockHashAsync();
+ var bestHash = await backendGlobal.RpcClient.GetBestBlockHashAsync();
var times = 0;
while (bitcoinStore.HashChain.TipHash != bestHash)
@@ -518,11 +519,11 @@ namespace WalletWasabi.Tests
[Fact]
public async Task WalletTestsAsync()
{
- (string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore) = await InitializeTestEnvironmentAsync(1);
+ (string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore, Backend.Global backendGlobal) = await InitializeTestEnvironmentAsync(1);
// Create the services.
// 1. Create connection service.
- var nodes = new NodesGroup(Backend.Global.Instance.Config.Network, requirements: Constants.NodeRequirements);
+ var nodes = new NodesGroup(backendGlobal.Config.Network, requirements: Constants.NodeRequirements);
nodes.ConnectedNodes.Add(await RegTestFixture.BackendRegTestNode.CreateNodeClientAsync());
// 2. Create mempool service.
@@ -750,11 +751,11 @@ namespace WalletWasabi.Tests
[Fact]
public async Task SendTestsFromHiddenWalletAsync() // These tests are taken from HiddenWallet, they were tests on the testnet.
{
- (string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore) = await InitializeTestEnvironmentAsync(1);
+ (string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore, Backend.Global backendGlobal) = await InitializeTestEnvironmentAsync(1);
// Create the services.
// 1. Create connection service.
- var nodes = new NodesGroup(Backend.Global.Instance.Config.Network, requirements: Constants.NodeRequirements);
+ var nodes = new NodesGroup(backendGlobal.Config.Network, requirements: Constants.NodeRequirements);
nodes.ConnectedNodes.Add(await RegTestFixture.BackendRegTestNode.CreateNodeClientAsync());
// 2. Create mempool service.
@@ -1196,11 +1197,11 @@ namespace WalletWasabi.Tests
[Fact]
public async Task BuildTransactionValidationsTestAsync()
{
- (string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore) = await InitializeTestEnvironmentAsync(1);
+ (string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore, Backend.Global backendGlobal) = await InitializeTestEnvironmentAsync(1);
// Create the services.
// 1. Create connection service.
- var nodes = new NodesGroup(Backend.Global.Instance.Config.Network, requirements: Constants.NodeRequirements);
+ var nodes = new NodesGroup(backendGlobal.Config.Network, requirements: Constants.NodeRequirements);
nodes.ConnectedNodes.Add(await RegTestFixture.BackendRegTestNode.CreateNodeClientAsync());
// 2. Create mempool service.
@@ -1362,11 +1363,11 @@ namespace WalletWasabi.Tests
[Fact]
public async Task BuildTransactionReorgsTestAsync()
{
- (string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore) = await InitializeTestEnvironmentAsync(1);
+ (string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore, Backend.Global backendGlobal) = await InitializeTestEnvironmentAsync(1);
// Create the services.
// 1. Create connection service.
- var nodes = new NodesGroup(Backend.Global.Instance.Config.Network, requirements: Constants.NodeRequirements);
+ var nodes = new NodesGroup(backendGlobal.Config.Network, requirements: Constants.NodeRequirements);
nodes.ConnectedNodes.Add(await RegTestFixture.BackendRegTestNode.CreateNodeClientAsync());
// 2. Create mempool service.
@@ -1529,11 +1530,11 @@ namespace WalletWasabi.Tests
[Fact]
public async Task SpendUnconfirmedTxTestAsync()
{
- (string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore) = await InitializeTestEnvironmentAsync(1);
+ (string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore, Backend.Global backendGlobal) = await InitializeTestEnvironmentAsync(1);
// Create the services.
// 1. Create connection service.
- var nodes = new NodesGroup(Backend.Global.Instance.Config.Network, requirements: Constants.NodeRequirements);
+ var nodes = new NodesGroup(backendGlobal.Config.Network, requirements: Constants.NodeRequirements);
nodes.ConnectedNodes.Add(await RegTestFixture.BackendRegTestNode.CreateNodeClientAsync());
// 2. Create mempool service.
@@ -1698,11 +1699,11 @@ namespace WalletWasabi.Tests
[Fact]
public async Task ReplaceByFeeTxTestAsync()
{
- (string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore) = await InitializeTestEnvironmentAsync(1);
+ (string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore, Backend.Global backendGlobal) = await InitializeTestEnvironmentAsync(1);
// Create the services.
// 1. Create connection service.
- var nodes = new NodesGroup(Backend.Global.Instance.Config.Network, requirements: Constants.NodeRequirements);
+ var nodes = new NodesGroup(backendGlobal.Config.Network, requirements: Constants.NodeRequirements);
nodes.ConnectedNodes.Add(await RegTestFixture.BackendRegTestNode.CreateNodeClientAsync());
// 2. Create mempool service.
@@ -1807,7 +1808,7 @@ namespace WalletWasabi.Tests
[Fact]
public async Task CcjCoordinatorCtorTestsAsync()
{
- (string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore) = await InitializeTestEnvironmentAsync(1);
+ (string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore, Backend.Global backendGlobal) = await InitializeTestEnvironmentAsync(1);
Logger.TurnOff(); // turn off at the end, otherwise, the tests logs would have of warnings
@@ -1827,7 +1828,7 @@ namespace WalletWasabi.Tests
mempoolTxId.ToString()
});
- using (var coordinatorToTest = new CcjCoordinator(network, Backend.Global.Instance.TrustedNodeNotifyingBehavior, folder, rpc, coordinator.RoundConfig))
+ using (var coordinatorToTest = new CcjCoordinator(network, backendGlobal.TrustedNodeNotifyingBehavior, folder, rpc, coordinator.RoundConfig))
{
var txIds = await File.ReadAllLinesAsync(cjfile);
@@ -1842,7 +1843,7 @@ namespace WalletWasabi.Tests
"This line is invalid (the file is corrupted)",
offchainTxId.ToString(),
});
- var coordinatorToTest2 = new CcjCoordinator(network, Backend.Global.Instance.TrustedNodeNotifyingBehavior, folder, rpc, coordinatorToTest.RoundConfig);
+ var coordinatorToTest2 = new CcjCoordinator(network, backendGlobal.TrustedNodeNotifyingBehavior, folder, rpc, coordinatorToTest.RoundConfig);
coordinatorToTest2?.Dispose();
txIds = await File.ReadAllLinesAsync(cjfile);
Assert.Single(txIds);
@@ -1857,7 +1858,7 @@ namespace WalletWasabi.Tests
[Fact]
public async Task CcjTestsAsync()
{
- (string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore) = await InitializeTestEnvironmentAsync(1);
+ (string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore, Backend.Global backendGlobal) = await InitializeTestEnvironmentAsync(1);
Money denomination = Money.Coins(0.2m);
decimal coordinatorFeePercent = 0.2m;
@@ -2376,7 +2377,7 @@ namespace WalletWasabi.Tests
[Fact]
public async Task CcjEqualInputTestsAsync()
{
- (string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore) = await InitializeTestEnvironmentAsync(1);
+ (string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore, Backend.Global backendGlobal) = await InitializeTestEnvironmentAsync(1);
Money denomination = Money.Coins(0.1m);
decimal coordinatorFeePercent = 0.0002m;
@@ -2524,7 +2525,7 @@ namespace WalletWasabi.Tests
[Fact]
public async Task NotingTestsAsync()
{
- (string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore) = await InitializeTestEnvironmentAsync(1);
+ (string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore, Backend.Global backendGlobal) = await InitializeTestEnvironmentAsync(1);
Money denomination = Money.Coins(1m);
decimal coordinatorFeePercent = 0.1m;
@@ -2605,7 +2606,7 @@ namespace WalletWasabi.Tests
[Fact]
public async Task BanningTestsAsync()
{
- (string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore) = await InitializeTestEnvironmentAsync(1);
+ (string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore, Backend.Global backendGlobal) = await InitializeTestEnvironmentAsync(1);
Money denomination = Money.Coins(0.1m);
decimal coordinatorFeePercent = 0.1m;
@@ -2807,7 +2808,7 @@ namespace WalletWasabi.Tests
[Fact]
public async Task Ccj100ParticipantsTestsAsync()
{
- (string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore) = await InitializeTestEnvironmentAsync(1);
+ (string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore, Backend.Global backendGlobal) = await InitializeTestEnvironmentAsync(1);
Money denomination = Money.Coins(0.1m);
decimal coordinatorFeePercent = 0.003m;
@@ -3024,7 +3025,7 @@ namespace WalletWasabi.Tests
[Fact]
public async Task CcjFeeTestsAsync()
{
- (string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore) = await InitializeTestEnvironmentAsync(1);
+ (string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore, Backend.Global backendGlobal) = await InitializeTestEnvironmentAsync(1);
var synchronizer = new WasabiSynchronizer(network, bitcoinStore, new Uri(RegTestFixture.BackendEndPoint), null);
synchronizer.Start(requestInterval: TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(5), 10000); // Start wasabi synchronizer service.
@@ -3148,7 +3149,7 @@ namespace WalletWasabi.Tests
[Fact]
public async Task CcjClientTestsAsync()
{
- (string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore) = await InitializeTestEnvironmentAsync(1);
+ (string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore, Backend.Global backendGlobal) = await InitializeTestEnvironmentAsync(1);
var synchronizer = new WasabiSynchronizer(network, bitcoinStore, new Uri(RegTestFixture.BackendEndPoint), null);
synchronizer.Start(requestInterval: TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(5), 10000); // Start wasabi synchronizer service.
@@ -3304,7 +3305,7 @@ namespace WalletWasabi.Tests
[Fact]
public async Task CoinJoinMultipleRoundTestsAsync()
{
- (string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore) = await InitializeTestEnvironmentAsync(3);
+ (string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore, Backend.Global backendGlobal) = await InitializeTestEnvironmentAsync(3);
Money denomination = Money.Coins(0.1m);
decimal coordinatorFeePercent = 0.1m;
@@ -3316,10 +3317,10 @@ namespace WalletWasabi.Tests
// Create the services.
// 1. Create connection service.
- var nodes = new NodesGroup(Backend.Global.Instance.Config.Network, requirements: Constants.NodeRequirements);
+ var nodes = new NodesGroup(backendGlobal.Config.Network, requirements: Constants.NodeRequirements);
nodes.ConnectedNodes.Add(await RegTestFixture.BackendRegTestNode.CreateNodeClientAsync());
- var nodes2 = new NodesGroup(Backend.Global.Instance.Config.Network, requirements: Constants.NodeRequirements);
+ var nodes2 = new NodesGroup(backendGlobal.Config.Network, requirements: Constants.NodeRequirements);
nodes2.ConnectedNodes.Add(await RegTestFixture.BackendRegTestNode.CreateNodeClientAsync());
// 2. Create mempool service.

MODIFY
WalletWasabi.Tests/XunitConfiguration/RegTestFixture.cs
WalletWasabi.Tests/XunitConfiguration/RegTestFixture.cs
@@ -36,7 +36,8 @@ namespace WalletWasabi.Tests.XunitConfiguration
var roundConfig = CreateRoundConfig(Money.Coins(0.1m), Constants.OneDayConfirmationTarget, 0.7, 0.1m, 100, 120, 60, 60, 60, 1, 24, true, 11);
- Backend.Global.Instance.InitializeAsync(config, roundConfig, rpc).GetAwaiter().GetResult();
+ var backendGlobal = new Backend.Global();
+ backendGlobal.InitializeAsync(config, roundConfig, rpc).GetAwaiter().GetResult();
BackendEndPoint = $"http://localhost:{new Random().Next(37130, 38000)}/";
BackendHost = WebHost.CreateDefaultBuilder()

Remove references to Backend.Global.Instance