Fix and simplify tests
MODIFY
WalletWasabi.Tests/UnitTests/Clients/MockTorHttpClient.cs
WalletWasabi.Tests/UnitTests/Clients/MockTorHttpClient.cs
@@ -12,7 +12,7 @@ namespace WalletWasabi.Tests.UnitTests.Clients
{
private volatile bool _disposedValue = false; // To detect redundant calls
- public Uri DestinationUri => new Uri("DestinationUri");
+ public Uri DestinationUri => new Uri("https://payment.server.org/pj");
public Func<Uri> DestinationUriAction => () => DestinationUri;
@@ -20,38 +20,30 @@ namespace WalletWasabi.Tests.UnitTests.Clients
public bool IsTorUsed => true;
- public Func<HttpMethod, string, string[], Task<HttpResponseMessage>> OnSendAsync_Method { get; set; }
- public Func<HttpMethod, string, string, Task<HttpResponseMessage>> OnSendAsync { get; set; }
+ public Func<HttpMethod, string, string[], string, Task<HttpResponseMessage>> OnSendAsync { get; set; }
public async Task<HttpResponseMessage> SendAsync(HttpMethod method, string relativeUri, HttpContent content = null, CancellationToken cancel = default)
{
- if (string.IsNullOrWhiteSpace(relativeUri))
- {
- return await OnSendAsync(method, "", await content.ReadAsStringAsync());
- }
- else
- {
+ var body = (content is {})
+ ? await content.ReadAsStringAsync()
+ : "";
var sepPos = relativeUri.IndexOf('?');
var action = relativeUri[..sepPos];
var parameters = relativeUri[(sepPos + 1)..].Split('&', StringSplitOptions.RemoveEmptyEntries);
- return await OnSendAsync_Method(method, action, parameters);
- }
+ return await OnSendAsync(method, action, parameters, body);
}
public async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancel = default)
{
var relativeUri = request.RequestUri?.ToString()?.Replace(TorSocks5EndPoint.ToEndpointString(), "");
- if (string.IsNullOrWhiteSpace(relativeUri))
- {
- return await OnSendAsync(request.Method, "", await request.Content.ReadAsStringAsync());
- }
- else
- {
+ var body = (request.Content is {})
+ ? await request.Content.ReadAsStringAsync()
+ : "";
+
var sepPos = relativeUri.IndexOf('?');
var action = relativeUri[..sepPos];
var parameters = relativeUri[(sepPos + 1)..].Split('&', StringSplitOptions.RemoveEmptyEntries);
- return await OnSendAsync_Method(request.Method, action, parameters);
- }
+ return await OnSendAsync(request.Method, action, parameters, body);
}
#region IDisposable Support

MODIFY
WalletWasabi.Tests/UnitTests/Clients/WasabiClientTests.cs
WalletWasabi.Tests/UnitTests/Clients/WasabiClientTests.cs
@@ -20,7 +20,7 @@ namespace WalletWasabi.Tests.UnitTests.Clients
{
var mempool = Enumerable.Range(0, 1_100).Select(_ => CreateTransaction()).ToArray();
- Task<HttpResponseMessage> FakeServerCode(HttpMethod method, string action, string[] parameters)
+ Task<HttpResponseMessage> FakeServerCode(HttpMethod method, string action, string[] parameters, string body)
{
Assert.True(parameters.Length <= 10);
var requestedTxId = parameters.Select(p => uint256.Parse(p[(p.IndexOf('=') + 1)..]));
@@ -32,7 +32,7 @@ namespace WalletWasabi.Tests.UnitTests.Clients
};
var torHttpClient = new MockTorHttpClient();
- torHttpClient.OnSendAsync_Method = FakeServerCode;
+ torHttpClient.OnSendAsync = FakeServerCode;
var client = new WasabiClient(torHttpClient);
Assert.Empty(WasabiClient.TransactionCache);
@@ -58,7 +58,7 @@ namespace WalletWasabi.Tests.UnitTests.Clients
Assert.Subset(WasabiClient.TransactionCache.Keys.ToHashSet(), txs.TakeLast(1_000).Select(x => x.GetHash()).ToHashSet());
// Requests transactions that are already in the cache
- torHttpClient.OnSendAsync_Method = (verb, action, parameters) =>
+ torHttpClient.OnSendAsync = (verb, action, parameters, body) =>
Task.FromException<HttpResponseMessage>(
new InvalidOperationException("The transaction should already be in the client cache. Http request was unexpected."));
@@ -67,7 +67,7 @@ namespace WalletWasabi.Tests.UnitTests.Clients
Assert.Equal(expectedTobeCachedTxId, txs.Last().GetHash());
// Requests fails with Bad Request
- torHttpClient.OnSendAsync_Method = (verb, action, parameters) =>
+ torHttpClient.OnSendAsync = (verb, action, parameters, body) =>
{
var response = new HttpResponseMessage(HttpStatusCode.BadRequest);
response.Content = new StringContent("\"Some RPC problem...\"");

MODIFY
WalletWasabi.Tests/UnitTests/Transactions/PayjoinTests.cs
WalletWasabi.Tests/UnitTests/Transactions/PayjoinTests.cs
@@ -360,11 +360,11 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
Assert.Single(tx.Transaction.Transaction.Inputs);
}
- private static Func<HttpMethod, string, string, Task<HttpResponseMessage>> PayjoinServer(Func<PSBT, PSBT> transformPsbt = null, HttpStatusCode statusCode = HttpStatusCode.OK)
+ private static Func<HttpMethod, string, string[], string, Task<HttpResponseMessage>> PayjoinServer(Func<PSBT, PSBT> transformPsbt = null, HttpStatusCode statusCode = HttpStatusCode.OK)
{
if (transformPsbt is { })
{
- return new Func<HttpMethod, string, string, Task<HttpResponseMessage>>((method, path, requestBody) =>
+ return new Func<HttpMethod, string, string[], string, Task<HttpResponseMessage>>((method, path, parameters, requestBody) =>
{
var psbt = PSBT.Parse(requestBody, Network.Main);
var newPsbt = transformPsbt(psbt);
@@ -375,7 +375,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
}
else
{
- return new Func<HttpMethod, string, string, Task<HttpResponseMessage>>((method, path, requestBody) =>
+ return new Func<HttpMethod, string, string[], string, Task<HttpResponseMessage>>((method, path, parameters, requestBody) =>
{
var message = new HttpResponseMessage(statusCode);
message.ReasonPhrase = "";

MODIFY
WalletWasabi/WebClients/PayJoin/PayjoinClient.cs
WalletWasabi/WebClients/PayJoin/PayjoinClient.cs
@@ -29,6 +29,7 @@ namespace WalletWasabi.WebClients.PayJoin
// For testing only
internal PayjoinClient(ITorHttpClient httpClient)
{
+ PaymentUrl = httpClient.DestinationUri;
TorHttpClient = Guard.NotNull(nameof(httpClient), httpClient);
}
@@ -56,12 +57,7 @@ namespace WalletWasabi.WebClients.PayJoin
{
throw new ArgumentException("originalTx should have utxo information", nameof(originalTx));
}
-/*
- if (!originalTx.TryGetEstimatedFeeRate(out var originalFeeRate))
- {
- throw new ArgumentException("signedPSBT should have utxo information", nameof(originalTx));
- }
- */
+
var originalFee = originalTx.GetFee();
optionalParameters.MaxAdditionalFeeContribution =
// By default, we want to keep same fee rate and a single additional input

Fix and simplify tests