RegTestFixture: Add BackendHttpClient that can be used in tests.
MODIFY
WalletWasabi.Tests/XunitConfiguration/RegTestFixture.cs
WalletWasabi.Tests/XunitConfiguration/RegTestFixture.cs
@@ -6,6 +6,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
+using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using WalletWasabi.Backend;
@@ -15,6 +16,7 @@ using WalletWasabi.Helpers;
using WalletWasabi.Logging;
using WalletWasabi.Services;
using WalletWasabi.Tests.Helpers;
+using WalletWasabi.Tor.Http;
namespace WalletWasabi.Tests.XunitConfiguration
{
@@ -47,7 +49,7 @@ namespace WalletWasabi.Tests.XunitConfiguration
config.SetFilePath(configFilePath);
config.ToFile();
- var roundConfig = CreateRoundConfig(Money.Coins(0.1m), Constants.OneDayConfirmationTarget, 0.7, 0.1m, 100, 120, 60, 60, 60, 1, 24, true, 11);
+ var roundConfig = CreateRoundConfig(Money.Coins(0.1m), WalletWasabi.Helpers.Constants.OneDayConfirmationTarget, 0.7, 0.1m, 100, 120, 60, 60, 60, 1, 24, true, 11);
var roundConfigFilePath = Path.Combine(testnetBackendDir, "CcjRoundConfig.json");
roundConfig.SetFilePath(roundConfigFilePath);
roundConfig.ToFile();
@@ -57,7 +59,7 @@ namespace WalletWasabi.Tests.XunitConfiguration
.Build();
BackendEndPoint = $"http://localhost:{CryptoHelpers.RandomInt(37130, 37999)}/";
BackendEndPointUri = new Uri(BackendEndPoint);
- BackendEndPointApiUri = new Uri(BackendEndPointUri, $"/api/v{Constants.BackendMajorVersion}/");
+ BackendEndPointApiUri = new Uri(BackendEndPointUri, $"/api/v{WalletWasabi.Helpers.Constants.BackendMajorVersion}/");
BackendHost = Host.CreateDefaultBuilder()
.ConfigureWebHostDefaults(webBuilder => webBuilder
@@ -67,11 +69,14 @@ namespace WalletWasabi.Tests.XunitConfiguration
.UseUrls(BackendEndPoint))
.Build();
- Global = (Global)BackendHost.Services.GetService(typeof(Global));
+ Global = (Global)BackendHost.Services.GetService(typeof(Global))!;
Global.HostedServices = hostedServices;
var hostInitializationTask = BackendHost.RunWithTasksAsync();
Logger.LogInfo($"Started Backend webhost: {BackendEndPoint}");
+ HttpClient = new HttpClient();
+ BackendHttpClient = new ClearnetHttpClient(HttpClient, () => BackendEndPointUri);
+
var delayTask = Task.Delay(3000);
Task.WaitAny(delayTask, hostInitializationTask); // Wait for server to initialize (Without this OSX CI will fail)
}
@@ -89,6 +94,12 @@ namespace WalletWasabi.Tests.XunitConfiguration
public CoreNode BackendRegTestNode { get; internal set; }
public Global Global { get; }
+ /// <summary>Underlying HTTP client to be used by <see cref="ClearnetHttpClient"/>.</summary>
+ public HttpClient HttpClient { get; }
+
+ /// <summary>Clearnet HTTP client with predefined base URI for Wasabi Backend (note: <c>/api</c> is not part of base URI).</summary>
+ public ClearnetHttpClient BackendHttpClient { get; }
+
public static CoordinatorRoundConfig CreateRoundConfig(
Money denomination,
int confirmationTarget,
@@ -133,6 +144,7 @@ namespace WalletWasabi.Tests.XunitConfiguration
BackendHost?.StopAsync().GetAwaiter().GetResult();
BackendHost?.Dispose();
BackendRegTestNode?.TryStopAsync().GetAwaiter().GetResult();
+ HttpClient.Dispose();
}
_disposedValue = true;

RegTestFixture: Add BackendHttpClient that can be used in tests.