Move GetMockMinimalRpc() to BitcoinFactory
MODIFY
WalletWasabi.Backend/Filters/ExceptionTranslateFilter.cs
WalletWasabi.Backend/Filters/ExceptionTranslateFilter.cs
@@ -14,8 +14,7 @@ namespace WalletWasabi.Backend.Filters
var exception = context.Exception.InnerException ?? context.Exception;
var exceptionMessage = exception.Message;
- context.Result = new JsonResult(
- exception switch
+ var error = exception switch
{
WabiSabiProtocolException e => new Error(
Type: "wabisabi-protocol-violation",
@@ -25,8 +24,9 @@ namespace WalletWasabi.Backend.Filters
Type: "unknown",
ErrorCode: "0",
Description: e.Message)
- }
- )
+ };
+
+ context.Result = new JsonResult(error)
{
StatusCode = (int)HttpStatusCode.InternalServerError
};

MODIFY
WalletWasabi.Tests/Helpers/BitcoinFactory.cs
WalletWasabi.Tests/Helpers/BitcoinFactory.cs
using NBitcoin;
+using NBitcoin.RPC;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
+using System.Threading.Tasks;
using WalletWasabi.Blockchain.Analysis;
using WalletWasabi.Blockchain.Analysis.Clustering;
using WalletWasabi.Blockchain.Keys;
using WalletWasabi.Blockchain.TransactionOutputs;
using WalletWasabi.Blockchain.Transactions;
using WalletWasabi.Models;
+using WalletWasabi.Tests.UnitTests;
namespace WalletWasabi.Tests.Helpers
{
@@ -114,5 +117,29 @@ namespace WalletWasabi.Tests.Helpers
return key.PubKey.WitHash.ScriptPubKey;
}
}
+
+ // Creates and configure an fake RPC client used to simulate the
+ // interaction with our bitcoin full node RPC server.
+ public static MockRpcClient GetMockMinimalRpc()
+ {
+ var mockRpc = new MockRpcClient();
+ mockRpc.OnGetMempoolInfoAsync = () => Task.FromResult(
+ new MemPoolInfo
+ {
+ MemPoolMinFee = 0.00001000, // 1 s/b (default value)
+ Histogram = Array.Empty<FeeRateGroup>()
+ });
+
+ mockRpc.OnEstimateSmartFeeAsync = (target, mode) => Task.FromResult(
+ new EstimateSmartFeeResponse()
+ {
+ Blocks = target,
+ FeeRate = new FeeRate(Money.Satoshis(5000))
+ });
+
+ mockRpc.OnGetTxOutAsync = (_, _, _) => null;
+
+ return mockRpc;
+ }
}
}

MODIFY
WalletWasabi.Tests/RegressionTests/WabiSabi/BackgroundServiceStarter.cs
WalletWasabi.Tests/RegressionTests/WabiSabi/BackgroundServiceStarter.cs
@@ -12,7 +12,7 @@ namespace WalletWasabi.Tests.RegressionTests.WabiSabi
// see: https://stackoverflow.com/a/51314147/627071
public class BackgroundServiceStarter<T> : IHostedService where T : IHostedService
{
- readonly T backgroundService;
+ private readonly T backgroundService;
public BackgroundServiceStarter(T backgroundService)
{

MODIFY
WalletWasabi.Tests/RegressionTests/WabiSabi/WabiSabiApiApplicationFactory.cs
WalletWasabi.Tests/RegressionTests/WabiSabi/WabiSabiApiApplicationFactory.cs
@@ -3,19 +3,15 @@ using System.Linq;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
-using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.AspNetCore.TestHost;
-using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using NBitcoin;
-using NBitcoin.RPC;
using WalletWasabi.BitcoinCore.Rpc;
using WalletWasabi.Crypto.Randomness;
using WalletWasabi.Tests.Helpers;
-using WalletWasabi.Tests.UnitTests;
using WalletWasabi.WabiSabi.Backend;
using WalletWasabi.WabiSabi.Backend.Banning;
using WalletWasabi.WabiSabi.Backend.PostRequests;
@@ -46,7 +42,7 @@ namespace WalletWasabi.Tests.RegressionTests.WabiSabi
services.AddSingleton<Arena>();
services.AddSingleton<ArenaRequestHandler>();
services.AddScoped<Network>(_ => Network.Main);
- services.AddScoped<IRPCClient>(_ => GetMockRpc());
+ services.AddScoped<IRPCClient>(_ => BitcoinFactory.GetMockMinimalRpc());
services.AddScoped<Prison>();
services.AddScoped<WabiSabiConfig>();
services.AddScoped(typeof(TimeSpan), _ => TimeSpan.FromSeconds(2));
@@ -70,29 +66,5 @@ namespace WalletWasabi.Tests.RegressionTests.WabiSabi
public WabiSabiHttpApiClient CreateWabiSabiHttpApiClient(HttpClient? httpClient = null) =>
new(new HttpClientWrapper(httpClient ?? CreateClient()));
-
- // Creates and configure an fake RPC client used to simulate the
- // interaction with our bitcoin full node RPC server.
- private static MockRpcClient GetMockRpc()
- {
- var mockRpc = new MockRpcClient();
- mockRpc.OnGetMempoolInfoAsync = () => Task.FromResult(
- new MemPoolInfo
- {
- MemPoolMinFee = 0.00001000, // 1 s/b (default value)
- Histogram = Array.Empty<FeeRateGroup>()
- });
-
- mockRpc.OnEstimateSmartFeeAsync = (target, mode) => Task.FromResult(
- new EstimateSmartFeeResponse()
- {
- Blocks = target,
- FeeRate = new FeeRate(Money.Satoshis(5000))
- });
-
- mockRpc.OnGetTxOutAsync = (_, _, _) => null;
-
- return mockRpc;
- }
}
}

MODIFY
WalletWasabi.Tests/RegressionTests/WabiSabi/WabiSabiHttpApiIntegrationTests.cs
WalletWasabi.Tests/RegressionTests/WabiSabi/WabiSabiHttpApiIntegrationTests.cs
-using System;
using System.Linq;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using NBitcoin;
-using NBitcoin.RPC;
using WalletWasabi.BitcoinCore.Rpc;
using WalletWasabi.Tests.Helpers;
-using WalletWasabi.Tests.UnitTests;
using WalletWasabi.WabiSabi.Backend.Models;
using WalletWasabi.WabiSabi.Models.MultipartyTransaction;
using Xunit;
@@ -32,6 +29,7 @@ namespace WalletWasabi.Tests.RegressionTests.WabiSabi
var apiClient = await _apiApplicationFactory.CreateArenaClientAsync();
var rounds = await apiClient.GetStatusAsync(CancellationToken.None);
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.
var nonExistingOutPoint = new OutPoint();
@@ -56,7 +54,7 @@ namespace WalletWasabi.Tests.RegressionTests.WabiSabi
{
builder.ConfigureServices(services =>
{
- var rpc = GetMockRpc();
+ var rpc = BitcoinFactory.GetMockMinimalRpc();
rpc.OnGetTxOutAsync = (_, _, _) => new ()
{
Confirmations = 101,
@@ -76,29 +74,5 @@ namespace WalletWasabi.Tests.RegressionTests.WabiSabi
Assert.NotEqual(uint256.Zero, aliceId);
}
-
- // Creates and configure an fake RPC client used to simulate the
- // interaction with our bitcoin full node RPC server.
- private static MockRpcClient GetMockRpc()
- {
- var mockRpc = new MockRpcClient();
- mockRpc.OnGetMempoolInfoAsync = () => Task.FromResult(
- new MemPoolInfo
- {
- MemPoolMinFee = 0.00001000, // 1 s/b (default value)
- Histogram = Array.Empty<FeeRateGroup>()
- });
-
- mockRpc.OnEstimateSmartFeeAsync = (target, mode) => Task.FromResult(
- new EstimateSmartFeeResponse()
- {
- Blocks = target,
- FeeRate = new FeeRate(Money.Satoshis(5000))
- });
-
- mockRpc.OnGetTxOutAsync = (_, _, _) => null;
-
- return mockRpc;
- }
}
}

Move GetMockMinimalRpc() to BitcoinFactory