Add end-to-end test to cover http client serialization
MODIFY
WalletWasabi.Tests/UnitTests/WabiSabi/Integration/WabiSabiHttpApiIntegrationTests.cs
WalletWasabi.Tests/UnitTests/WabiSabi/Integration/WabiSabiHttpApiIntegrationTests.cs
@@ -14,6 +14,7 @@ using WalletWasabi.Tor.Http;
using WalletWasabi.Tor.Socks5.Pool.Circuits;
using WalletWasabi.WabiSabi;
using WalletWasabi.WabiSabi.Backend;
+using WalletWasabi.WabiSabi.Backend.Banning;
using WalletWasabi.WabiSabi.Backend.Models;
using WalletWasabi.WabiSabi.Backend.Rounds;
using WalletWasabi.WabiSabi.Backend.Rounds.CoinJoinStorage;
@@ -62,6 +63,36 @@ public class WabiSabiHttpApiIntegrationTests : IClassFixture<WabiSabiApiApplicat
Assert.Equal(WabiSabiProtocolErrorCode.InputSpent, wex.ErrorCode);
}
+ [Fact]
+ public async Task RegisterBannedCoinAsync()
+ {
+ var bannedOutPoint = BitcoinFactory.CreateOutPoint();
+
+ var httpClient = _apiApplicationFactory.WithWebHostBuilder(builder =>
+ builder.ConfigureServices(services =>
+ {
+ var inmate = new Inmate(bannedOutPoint, Punishment.LongBanned, DateTimeOffset.UtcNow, uint256.One);
+ services.AddScoped<Prison>(_ => new Prison(new[] {inmate}));
+ })).CreateClient();
+
+ var apiClient = await _apiApplicationFactory.CreateArenaClientAsync(httpClient);
+ var rounds = (await apiClient.GetStatusAsync(RoundStateRequest.Empty, CancellationToken.None)).RoundStates;
+ var round = rounds.First(x => x.CoinjoinState is ConstructionState);
+
+ // If an output is not in the utxo dataset then it is not unspent, this
+ // means that the output is spent or simply doesn't even exist.
+ using var signingKey = new Key();
+ var ownershipProof = WabiSabiFactory.CreateOwnershipProof(signingKey, round.Id);
+
+ var ex = await Assert.ThrowsAsync<HttpRequestException>(async () =>
+ await apiClient.RegisterInputAsync(round.Id, bannedOutPoint, ownershipProof, CancellationToken.None));
+
+ var wex = Assert.IsType<WabiSabiProtocolException>(ex.InnerException);
+ Assert.Equal(WabiSabiProtocolErrorCode.InputLongBanned, wex.ErrorCode);
+ var inputBannedData = Assert.IsType<InputBannedExceptionData>(wex.ExceptionData);
+ Assert.True(inputBannedData.BannedUntil > DateTimeOffset.UtcNow);
+ }
+
[Theory]
[InlineData(new long[] { 10_000_000, 20_000_000, 30_000_000, 40_000_000, 100_000_000 })]
public async Task SoloCoinJoinTestAsync(long[] amounts)

MODIFY
WalletWasabi/Tor/Http/Extensions/HttpResponseMessageExtensions.cs
WalletWasabi/Tor/Http/Extensions/HttpResponseMessageExtensions.cs
@@ -9,6 +9,7 @@ using WalletWasabi.Tor.Http.Models;
using WalletWasabi.WabiSabi;
using WalletWasabi.WabiSabi.Backend.Models;
using WalletWasabi.WabiSabi.Models;
+using WalletWasabi.WabiSabi.Models.Serialization;
namespace WalletWasabi.Tor.Http.Extensions;
@@ -67,6 +68,7 @@ public static class HttpResponseMessageExtensions
var contentString = await me.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
var error = JsonConvert.DeserializeObject<Error>(contentString, new JsonSerializerSettings()
{
+ Converters = JsonSerializationOptions.Default.Settings.Converters,
Error = (_, e) => e.ErrorContext.Handled = true // Try to deserialize an Error object
});
var innerException = error switch

Add end-to-end test to cover http client serialization