Fixing the Tests WIP
MODIFY
WalletWasabi.Tests/Helpers/ArenaBuilder.cs
WalletWasabi.Tests/Helpers/ArenaBuilder.cs
@@ -6,6 +6,7 @@ using WalletWasabi.BitcoinCore.Rpc;
using WalletWasabi.WabiSabi.Backend;
using WalletWasabi.WabiSabi.Backend.Banning;
using WalletWasabi.WabiSabi.Backend.Rounds;
+using WalletWasabi.WabiSabi.Backend.Rounds.CoinJoinStorage;
namespace WalletWasabi.Tests.Helpers
{
@@ -29,7 +30,7 @@ namespace WalletWasabi.Tests.Helpers
IRPCClient rpc = Rpc ?? WabiSabiFactory.CreatePreconfiguredRpcClient().Object;
Network network = Network ?? Network.Main;
- Arena arena = new(period, network, config, rpc, prison);
+ Arena arena = new(period, network, config, rpc, prison, new InMemoryCoinJoinIdStore());
foreach (var round in rounds)
{

MODIFY
WalletWasabi.Tests/Helpers/WabiSabiFactory.cs
WalletWasabi.Tests/Helpers/WabiSabiFactory.cs
@@ -15,6 +15,7 @@ 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;
using WalletWasabi.WabiSabi.Client;
using WalletWasabi.WabiSabi.Crypto;
using WalletWasabi.WabiSabi.Crypto.CredentialRequesting;
@@ -109,7 +110,7 @@ namespace WalletWasabi.Tests.Helpers
public static async Task<Arena> CreateAndStartArenaAsync(WabiSabiConfig cfg, IMock<IRPCClient> mockRpc, params Round[] rounds)
{
- Arena arena = new(TimeSpan.FromHours(1), Network.Main, cfg, mockRpc.Object, new Prison());
+ Arena arena = new(TimeSpan.FromHours(1), Network.Main, cfg, mockRpc.Object, new Prison(), new InMemoryCoinJoinIdStore(Enumerable.Empty<uint256>()));
foreach (var round in rounds)
{
arena.Rounds.Add(round);

MODIFY
WalletWasabi.Tests/UnitTests/WabiSabi/Backend/RoundCreationTests.cs
WalletWasabi.Tests/UnitTests/WabiSabi/Backend/RoundCreationTests.cs
@@ -7,6 +7,7 @@ using WalletWasabi.Tests.Helpers;
using WalletWasabi.WabiSabi.Backend;
using WalletWasabi.WabiSabi.Backend.Banning;
using WalletWasabi.WabiSabi.Backend.Rounds;
+using WalletWasabi.WabiSabi.Backend.Rounds.CoinJoinStorage;
using Xunit;
namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend
@@ -25,7 +26,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend
FeeRate = new FeeRate(10m)
});
- using Arena arena = new(TimeSpan.FromSeconds(1), Network.Main, cfg, mockRpc, new Prison());
+ using Arena arena = new(TimeSpan.FromSeconds(1), Network.Main, cfg, mockRpc, new Prison(), new InMemoryCoinJoinIdStore());
Assert.Empty(arena.Rounds);
await arena.StartAsync(CancellationToken.None);
await arena.TriggerAndWaitRoundAsync(TimeSpan.FromSeconds(21));
@@ -46,7 +47,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend
FeeRate = new FeeRate(10m)
});
- using Arena arena = new(TimeSpan.FromSeconds(1), Network.Main, cfg, mockRpc, new Prison());
+ using Arena arena = new(TimeSpan.FromSeconds(1), Network.Main, cfg, mockRpc, new Prison(), new InMemoryCoinJoinIdStore());
Assert.Empty(arena.Rounds);
await arena.StartAsync(CancellationToken.None);
await arena.TriggerAndWaitRoundAsync(TimeSpan.FromSeconds(21));
@@ -71,7 +72,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend
FeeRate = new FeeRate(10m)
});
- using Arena arena = new(TimeSpan.FromSeconds(1), Network.Main, cfg, mockRpc, new Prison());
+ using Arena arena = new(TimeSpan.FromSeconds(1), Network.Main, cfg, mockRpc, new Prison(), new InMemoryCoinJoinIdStore());
Assert.Empty(arena.Rounds);
await arena.StartAsync(CancellationToken.None);
await arena.TriggerAndWaitRoundAsync(TimeSpan.FromSeconds(21));

MODIFY
WalletWasabi.Tests/UnitTests/WabiSabi/Integration/WabiSabiHttpApiIntegrationTests.cs
WalletWasabi.Tests/UnitTests/WabiSabi/Integration/WabiSabiHttpApiIntegrationTests.cs
@@ -13,6 +13,7 @@ using WalletWasabi.Tor.Socks5.Pool.Circuits;
using WalletWasabi.WabiSabi.Backend;
using WalletWasabi.WabiSabi.Backend.Models;
using WalletWasabi.WabiSabi.Backend.Rounds;
+using WalletWasabi.WabiSabi.Backend.Rounds.CoinJoinStorage;
using WalletWasabi.WabiSabi.Client;
using WalletWasabi.WabiSabi.Models;
using WalletWasabi.WabiSabi.Models.MultipartyTransaction;
@@ -110,18 +111,24 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Integration
{
MaxInputCountByRound = inputCount,
StandardInputRegistrationTimeout = TimeSpan.FromSeconds(10)
- });
+ }
+ );
+ // Emulate that the first coin is coming from a CoinJoin.
+ services.AddScoped(s => new InMemoryCoinJoinIdStore(new[] { coins.First().Coin.Outpoint.Hash }));
});
}).CreateClient();
// Create the coinjoin client
var apiClient = _apiApplicationFactory.CreateWabiSabiHttpApiClient(httpClient);
+
var mockHttpClientFactory = new Mock<IBackendHttpClientFactory>();
mockHttpClientFactory
.Setup(factory => factory.NewBackendHttpClient(It.IsAny<Mode>()))
+
.Returns(new HttpClientWrapper(httpClient));
using var roundStateUpdater = new RoundStateUpdater(TimeSpan.FromSeconds(1), apiClient);
+
await roundStateUpdater.StartAsync(CancellationToken.None);
var kitchen = new Kitchen();

MODIFY
WalletWasabi/WabiSabi/Backend/Rounds/Arena.cs
WalletWasabi/WabiSabi/Backend/Rounds/Arena.cs
@@ -24,6 +24,7 @@ namespace WalletWasabi.WabiSabi.Backend.Rounds
WabiSabiConfig config,
IRPCClient rpc,
Prison prison,
+ InMemoryCoinJoinIdStore inMemoryCoinJoinIdStore,
CoinJoinTransactionArchiver? archiver = null) : base(period)
{
Network = network;
@@ -32,7 +33,7 @@ namespace WalletWasabi.WabiSabi.Backend.Rounds
Prison = prison;
TransactionArchiver = archiver;
Random = new SecureRandom();
- InMemoryCoinJoinIdStore = new InMemoryCoinJoinIdStore(Enumerable.Empty<uint256>());
+ InMemoryCoinJoinIdStore = inMemoryCoinJoinIdStore;
}
public HashSet<Round> Rounds { get; } = new();

MODIFY
WalletWasabi/WabiSabi/Backend/Rounds/CoinJoinStorage/InMemoryCoinJoinIdStore.cs
WalletWasabi/WabiSabi/Backend/Rounds/CoinJoinStorage/InMemoryCoinJoinIdStore.cs
@@ -16,6 +16,10 @@ namespace WalletWasabi.WabiSabi.Backend.Rounds.CoinJoinStorage
CoinJoinIds = new ConcurrentDictionary<uint256, bool>(coinJoinHashes.ToDictionary(x => x, x => true));
}
+ public InMemoryCoinJoinIdStore() : this(Enumerable.Empty<uint256>())
+ {
+ }
+
public ConcurrentDictionary<uint256, bool> CoinJoinIds { get; }
public bool Contains(uint256 hash)

MODIFY
WalletWasabi/WabiSabi/CoordinatorParameters.cs
WalletWasabi/WabiSabi/CoordinatorParameters.cs
@@ -30,6 +30,11 @@ namespace WalletWasabi.WabiSabi
/// </summary>
public string PrisonFilePath => Path.Combine(CoordinatorDataDir, "Prison.txt");
+ /// <summary>
+ /// File that is storing the hashes of WabiSabi CoinJoins.
+ /// </summary>
+ public string CoinJoinIdStoreFilePath => Path.Combine(CoordinatorDataDir, "CoinJoinIdStore.txt");
+
/// <summary>
/// Runtime adjustable configuration of the coordinator.
/// </summary>

MODIFY
WalletWasabi/WabiSabi/WabiSabiCoordinator.cs
WalletWasabi/WabiSabi/WabiSabiCoordinator.cs
using Microsoft.Extensions.Hosting;
+using NBitcoin;
using System.IO;
+using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using WalletWasabi.BitcoinCore.Rpc;
@@ -22,7 +24,10 @@ namespace WalletWasabi.WabiSabi
ConfigWatcher = new(parameters.ConfigChangeMonitoringPeriod, Config, () => Logger.LogInfo("WabiSabi configuration has changed."));
CoinJoinTransactionArchiver transactionArchiver = new(Path.Combine(parameters.CoordinatorDataDir, "CoinJoinTransactions"));
- Arena = new(parameters.RoundProgressSteppingPeriod, rpc.Network, Config, rpc, Warden.Prison, transactionArchiver);
+
+ var inMemoryCoinJoinIdStore = InMemoryCoinJoinIdStore.LoadFromFile(parameters.CoinJoinIdStoreFilePath);
+
+ Arena = new(parameters.RoundProgressSteppingPeriod, rpc.Network, Config, rpc, Warden.Prison, inMemoryCoinJoinIdStore, transactionArchiver);
}
public ConfigWatcher ConfigWatcher { get; }

Fixing the Tests WIP