BackendTests use ClearnetHttpClient now.
MODIFY
WalletWasabi.Tests/RegressionTests/BackendTests.cs
WalletWasabi.Tests/RegressionTests/BackendTests.cs
@@ -29,17 +29,20 @@ namespace WalletWasabi.Tests.RegressionTests
public BackendTests(RegTestFixture regTestFixture)
{
RegTestFixture = regTestFixture;
+ HttpClient = ClearnetHttpClient.Instance;
}
private RegTestFixture RegTestFixture { get; }
+ /// <summary>Clearnet HTTP client.</summary>
+ private IHttpClient HttpClient { get; }
+
#region BackendTests
[Fact]
public async Task GetExchangeRatesAsync()
{
- using var client = new TorHttpClient(new Uri(RegTestFixture.BackendEndPoint), null);
- using var response = await client.SendAsync(HttpMethod.Get, $"/api/v{WalletWasabi.Helpers.Constants.BackendMajorVersion}/btc/offchain/exchange-rates");
+ using var response = await HttpClient.SendAsync(HttpMethod.Get, new Uri(RegTestFixture.BackendEndPointApiUri, "btc/offchain/exchange-rates"));
Assert.True(response.StatusCode == HttpStatusCode.OK);
var exchangeRates = await response.Content.ReadAsJsonAsync<List<ExchangeRate>>();
@@ -70,12 +73,11 @@ namespace WalletWasabi.Tests.RegressionTests
var content = new StringContent($"'{tx.ToHex()}'", Encoding.UTF8, "application/json");
Logger.TurnOff();
- using (var client = new TorHttpClient(new Uri(RegTestFixture.BackendEndPoint), null))
- using (var response = await client.SendAsync(HttpMethod.Post, $"/api/v{WalletWasabi.Helpers.Constants.BackendMajorVersion}/btc/blockchain/broadcast", content))
- {
+
+ using var response = await HttpClient.SendAsync(HttpMethod.Post, new Uri(RegTestFixture.BackendEndPointApiUri, "btc/blockchain/broadcast"), content);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Equal("Transaction is already in the blockchain.", await response.Content.ReadAsJsonAsync<string>());
- }
+
Logger.TurnOn();
}
@@ -87,13 +89,13 @@ namespace WalletWasabi.Tests.RegressionTests
var content = new StringContent($"''", Encoding.UTF8, "application/json");
Logger.TurnOff();
- using (var client = new TorHttpClient(new Uri(RegTestFixture.BackendEndPoint), null))
- using (var response = await client.SendAsync(HttpMethod.Post, $"/api/v{WalletWasabi.Helpers.Constants.BackendMajorVersion}/btc/blockchain/broadcast", content))
- {
+
+ var response = await HttpClient.SendAsync(HttpMethod.Post, new Uri(RegTestFixture.BackendEndPointApiUri, "btc/blockchain/broadcast"), content);
+
Assert.NotEqual(HttpStatusCode.OK, response.StatusCode);
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
Assert.Contains("The hex field is required.", await response.Content.ReadAsStringAsync());
- }
+
Logger.TurnOn();
}
@@ -168,7 +170,8 @@ namespace WalletWasabi.Tests.RegressionTests
[Fact]
public async Task StatusRequestTestAsync()
{
- string request = $"/api/v{WasabiClient.ApiVersion}/btc/Blockchain/status";
+ var requestUri = new Uri(RegTestFixture.BackendEndPointApiUri, "btc/Blockchain/status");
+
(_, IRPCClient rpc, _, _, _, _, Backend.Global global) = await Common.InitializeTestEnvironmentAsync(RegTestFixture, 1);
var indexBuilderService = global.IndexBuilderService;
@@ -188,9 +191,10 @@ namespace WalletWasabi.Tests.RegressionTests
times++;
}
- using var client = new WasabiClient(new Uri(RegTestFixture.BackendEndPoint), null);
- var response = await client.TorClient.SendAsync(HttpMethod.Get, request);
- using (HttpContent content = response.Content)
+ HttpResponseMessage? response = await HttpClient.SendAsync(HttpMethod.Get, requestUri);
+ Assert.NotNull(response);
+
+ using (HttpContent content = response!.Content)
{
var resp = await content.ReadAsJsonAsync<StatusResponse>();
Assert.True(resp.FilterCreationActive);
@@ -202,8 +206,10 @@ namespace WalletWasabi.Tests.RegressionTests
await rpc.GenerateAsync(1);
- response = await client.TorClient.SendAsync(HttpMethod.Get, request);
- using (HttpContent content = response.Content)
+ response = await HttpClient.SendAsync(HttpMethod.Get, requestUri);
+ Assert.NotNull(response);
+
+ using (HttpContent content = response!.Content)
{
var resp = await content.ReadAsJsonAsync<StatusResponse>();
Assert.True(resp.FilterCreationActive);
@@ -217,8 +223,10 @@ namespace WalletWasabi.Tests.RegressionTests
// Set back the time to trigger timeout in BlockchainController.GetStatusAsync.
global.IndexBuilderService.LastFilterBuildTime = DateTimeOffset.UtcNow - BlockchainController.FilterTimeout;
- response = await client.TorClient.SendAsync(HttpMethod.Get, request);
- using (HttpContent content = response.Content)
+ response = await HttpClient.SendAsync(HttpMethod.Get, requestUri);
+ Assert.NotNull(response);
+
+ using (HttpContent content = response!.Content)
{
var resp = await content.ReadAsJsonAsync<StatusResponse>();
Assert.False(resp.FilterCreationActive);

MODIFY
WalletWasabi.Tests/XunitConfiguration/RegTestFixture.cs
WalletWasabi.Tests/XunitConfiguration/RegTestFixture.cs
@@ -56,6 +56,8 @@ namespace WalletWasabi.Tests.XunitConfiguration
.AddInMemoryCollection(new[] { new KeyValuePair<string, string>("datadir", testnetBackendDir) })
.Build();
BackendEndPoint = $"http://localhost:{new Random().Next(37130, 38000)}/";
+ BackendEndPointUri = new Uri(BackendEndPoint);
+ BackendEndPointApiUri = new Uri(BackendEndPointUri, $"/api/v{Constants.BackendMajorVersion}/");
BackendHost = Host.CreateDefaultBuilder()
.ConfigureWebHostDefaults(webBuilder => webBuilder
@@ -74,7 +76,15 @@ namespace WalletWasabi.Tests.XunitConfiguration
Task.WaitAny(delayTask, hostInitializationTask); // Wait for server to initialize (Without this OSX CI will fail)
}
- public string BackendEndPoint { get; internal set; }
+ /// <summary>String representation of backend URI: <c>http://localhost:RANDOM_PORT</c>.</summary>
+ public string BackendEndPoint { get; }
+
+ /// <summary>URI in form: <c>http://localhost:RANDOM_PORT</c>.</summary>
+ public Uri BackendEndPointUri { get; }
+
+ /// <summary>URI in form: <c>http://localhost:RANDOM_PORT/api/vAPI_VERSION</c>.</summary>
+ public Uri BackendEndPointApiUri { get; }
+
public IHost BackendHost { get; internal set; }
public CoreNode BackendRegTestNode { get; internal set; }
public Global Global { get; }

MODIFY
WalletWasabi/Tor/Http/IHttpClient.cs
WalletWasabi/Tor/Http/IHttpClient.cs
+using System;
+using System.Net;
using System.Net.Http;
using System.Security.Authentication;
using System.Threading;
@@ -15,5 +17,17 @@ namespace WalletWasabi.Tor.Http
/// <inheritdoc cref="HttpClient.SendAsync(HttpRequestMessage, CancellationToken)"/>
Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken token = default);
+
+ Task<HttpResponseMessage> SendAsync(HttpMethod method, Uri requestUri, HttpContent? content = null, CancellationToken token = default)
+ {
+ var httpRequestMessage = new HttpRequestMessage(method, requestUri);
+
+ if (content is { })
+ {
+ httpRequestMessage.Content = content;
+ }
+
+ return SendAsync(httpRequestMessage);
+ }
}
}

MODIFY
WalletWasabi/WebClients/Wasabi/WasabiClient.cs
WalletWasabi/WebClients/Wasabi/WasabiClient.cs
@@ -36,7 +36,7 @@ namespace WalletWasabi.WebClients.Wasabi
TorClient = torHttpClient;
}
- public ITorHttpClient TorClient { get; }
+ private ITorHttpClient TorClient { get; }
public static Dictionary<uint256, Transaction> TransactionCache { get; } = new Dictionary<uint256, Transaction>();
private static Queue<uint256> TransactionIdQueue { get; } = new Queue<uint256>();

BackendTests use ClearnetHttpClient now.