Use mocked CoinJoinClient
MODIFY
WalletWasabi.Tests/Helpers/WabiSabiFactory.cs
WalletWasabi.Tests/Helpers/WabiSabiFactory.cs
@@ -3,25 +3,27 @@ using NBitcoin;
using NBitcoin.Crypto;
using NBitcoin.RPC;
using System.Collections.Generic;
+using System.Collections.Immutable;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using WalletWasabi.BitcoinCore.Rpc;
+using WalletWasabi.Blockchain.Keys;
using WalletWasabi.Blockchain.TransactionOutputs;
using WalletWasabi.Crypto;
using WalletWasabi.Crypto.Randomness;
using WalletWasabi.Crypto.ZeroKnowledge;
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.Client.RoundStateAwaiters;
using WalletWasabi.WabiSabi.Crypto;
using WalletWasabi.WabiSabi.Crypto.CredentialRequesting;
using WalletWasabi.WabiSabi.Models;
using WalletWasabi.WabiSabi.Models.MultipartyTransaction;
using WalletWasabi.Wallets;
+using WalletWasabi.WebClients.Wasabi;
namespace WalletWasabi.Tests.Helpers;
@@ -268,4 +270,43 @@ public static class WabiSabiFactory
var smartCoin2 = BitcoinFactory.CreateSmartCoin(BitcoinFactory.CreateHdPubKey(km), Money.Coins(2m));
return (keyChain, smartCoin1, smartCoin2);
}
+
+ public static CoinJoinClient CreateTestCoinJoinClient(
+ IWasabiHttpClientFactory httpClientFactory,
+ KeyManager keyManager,
+ RoundStateUpdater roundStateUpdater)
+ {
+ return CreateTestCoinJoinClient(
+ httpClientFactory,
+ new KeyChain(keyManager, new Kitchen("")),
+ new InternalDestinationProvider(keyManager),
+ roundStateUpdater);
+ }
+
+ public static CoinJoinClient CreateTestCoinJoinClient(
+ IWasabiHttpClientFactory httpClientFactory,
+ IKeyChain keyChain,
+ IDestinationProvider destinationProvider,
+ RoundStateUpdater roundStateUpdater)
+ {
+ var mock = new Mock<CoinJoinClient>(
+ httpClientFactory,
+ keyChain,
+ destinationProvider,
+ roundStateUpdater,
+ int.MaxValue,
+ true,
+ TimeSpan.Zero,
+ TimeSpan.Zero);
+
+ mock.Setup(m => m.GetScheduledDates(It.IsAny<int>(), It.IsAny<DateTimeOffset>(), It.IsAny<TimeSpan?>()))
+ .Returns((int howMany, DateTimeOffset endTime, TimeSpan maximumRequestDelay) =>
+ {
+ var now = DateTimeOffset.UtcNow;
+ return Enumerable.Repeat(now, howMany).ToImmutableList();
+ });
+ mock.CallBase = true;
+
+ return mock.Object;
+ }
}

MODIFY
WalletWasabi.Tests/UnitTests/WabiSabi/Integration/Participant.cs
WalletWasabi.Tests/UnitTests/WabiSabi/Integration/Participant.cs
@@ -8,6 +8,7 @@ using WalletWasabi.Blockchain.Keys;
using WalletWasabi.Blockchain.TransactionOutputs;
using WalletWasabi.Blockchain.Transactions;
using WalletWasabi.Models;
+using WalletWasabi.Tests.Helpers;
using WalletWasabi.WabiSabi.Client;
using WalletWasabi.WabiSabi.Client.RoundStateAwaiters;
using WalletWasabi.WabiSabi.Models;
@@ -75,12 +76,7 @@ internal class Participant
using var roundStateUpdater = new RoundStateUpdater(TimeSpan.FromSeconds(3), apiClient);
await roundStateUpdater.StartAsync(cancellationToken).ConfigureAwait(false);
- var coinJoinClient = new CoinJoinClient(
- HttpClientFactory,
- Wallet,
- Wallet,
- roundStateUpdater,
- consolidationMode: true);
+ var coinJoinClient = WabiSabiFactory.CreateTestCoinJoinClient(HttpClientFactory, Wallet, Wallet, roundStateUpdater);
static HdPubKey CreateHdPubKey(ExtPubKey extPubKey)
{

MODIFY
WalletWasabi.Tests/UnitTests/WabiSabi/Integration/WabiSabiHttpApiIntegrationTests.cs
WalletWasabi.Tests/UnitTests/WabiSabi/Integration/WabiSabiHttpApiIntegrationTests.cs
@@ -5,7 +5,6 @@ using NBitcoin;
using System.IO;
using System.Linq;
using System.Net.Http;
-using System.Reactive.Disposables;
using System.Threading;
using System.Threading.Tasks;
using WalletWasabi.BitcoinCore.Rpc;
@@ -21,7 +20,6 @@ using WalletWasabi.WabiSabi.Client;
using WalletWasabi.WabiSabi.Client.RoundStateAwaiters;
using WalletWasabi.WabiSabi.Models;
using WalletWasabi.WabiSabi.Models.MultipartyTransaction;
-using WalletWasabi.Wallets;
using WalletWasabi.WebClients.Wasabi;
using Xunit;
using Xunit.Abstractions;
@@ -158,11 +156,7 @@ public class WabiSabiHttpApiIntegrationTests : IClassFixture<WabiSabiApiApplicat
await roundStateUpdater.StartAsync(CancellationToken.None);
- var coinJoinClient = new CoinJoinClient(mockHttpClientFactory.Object,
- new KeyChain(keyManager, new Kitchen("")),
- new InternalDestinationProvider(keyManager),
- roundStateUpdater,
- consolidationMode: true);
+ var coinJoinClient = WabiSabiFactory.CreateTestCoinJoinClient(mockHttpClientFactory.Object, keyManager, roundStateUpdater);
// Run the coinjoin client task.
Assert.True((await coinJoinClient.StartCoinJoinAsync(coins, cts.Token)).SuccessfulBroadcast);
@@ -266,11 +260,7 @@ public class WabiSabiHttpApiIntegrationTests : IClassFixture<WabiSabiApiApplicat
var roundState = await roundStateUpdater.CreateRoundAwaiter(roundState => roundState.Phase == Phase.InputRegistration, cts.Token);
- var coinJoinClient = new CoinJoinClient(mockHttpClientFactory.Object,
- new KeyChain(keyManager1, new Kitchen("")),
- new InternalDestinationProvider(keyManager1),
- roundStateUpdater,
- consolidationMode: true);
+ var coinJoinClient = WabiSabiFactory.CreateTestCoinJoinClient(mockHttpClientFactory.Object, keyManager1, roundStateUpdater);
// Run the coinjoin client task.
var coinJoinTask = Task.Run(async () => await coinJoinClient.StartCoinJoinAsync(coins, cts.Token).ConfigureAwait(false), cts.Token);
@@ -298,11 +288,7 @@ public class WabiSabiHttpApiIntegrationTests : IClassFixture<WabiSabiApiApplicat
.Setup(factory => factory.NewHttpClientWithCircuitPerRequest())
.Returns(nonSigningHttpClient);
- var badCoinJoinClient = new CoinJoinClient(mockNonSigningHttpClientFactory.Object,
- new KeyChain(keyManager2, new Kitchen("")),
- new InternalDestinationProvider(keyManager2),
- roundStateUpdater,
- consolidationMode: true);
+ var badCoinJoinClient = WabiSabiFactory.CreateTestCoinJoinClient(mockNonSigningHttpClientFactory.Object, keyManager2, roundStateUpdater);
var badCoinsTask = Task.Run(async () => await badCoinJoinClient.StartRoundAsync(badCoins, roundState, cts.Token).ConfigureAwait(false), cts.Token);

MODIFY
WalletWasabi/WabiSabi/Client/CoinJoinClient.cs
WalletWasabi/WabiSabi/Client/CoinJoinClient.cs
@@ -359,7 +359,7 @@ public class CoinJoinClient
await Task.WhenAll(tasks).ConfigureAwait(false);
}
- private ImmutableList<DateTimeOffset> GetScheduledDates(int howMany, DateTimeOffset endTime, TimeSpan? maximumRequestDelay = null)
+ internal virtual ImmutableList<DateTimeOffset> GetScheduledDates(int howMany, DateTimeOffset endTime, TimeSpan? maximumRequestDelay = null)
{
var remainingTime = endTime - DateTimeOffset.UtcNow;

Use mocked CoinJoinClient