Separate blame tests from normal tests
MODIFY
WalletWasabi.Tests/Helpers/WabiSabiFactory.cs
WalletWasabi.Tests/Helpers/WabiSabiFactory.cs
@@ -322,5 +322,19 @@ namespace WalletWasabi.Tests.Helpers
RoundParameters parameters = new(cfg, round.Network, round.Random, round.FeeRate, blameOf: round);
return new(parameters);
}
+
+ public static MockRpcClient CreateMockRpc(Key? key = null)
+ {
+ MockRpcClient rpc = new();
+
+ rpc.OnGetTxOutAsync = (_, _, _) => new()
+ {
+ Confirmations = 1,
+ ScriptPubKeyType = "witness_v0_keyhash",
+ TxOut = new(Money.Coins(1), key?.PubKey.GetSegwitAddress(Network.Main).ScriptPubKey ?? Script.Empty)
+ };
+
+ return rpc;
+ }
}
}

MODIFY
WalletWasabi.Tests/UnitTests/MockRpcClient.cs
WalletWasabi.Tests/UnitTests/MockRpcClient.cs
@@ -7,7 +7,7 @@ using WalletWasabi.BitcoinCore.Rpc.Models;
namespace WalletWasabi.Tests.UnitTests
{
- internal class MockRpcClient : IRPCClient
+ public class MockRpcClient : IRPCClient
{
public Func<Task<uint256>> OnGetBestBlockHashAsync { get; set; }
public Func<uint256, int, bool, GetTxOutResponse?> OnGetTxOutAsync { get; set; }

MODIFY
WalletWasabi.Tests/UnitTests/WabiSabi/Backend/RegisterInputTests.cs
WalletWasabi.Tests/UnitTests/WabiSabi/Backend/RegisterInputTests.cs
@@ -28,20 +28,6 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend
Assert.True(minAliceDeadline <= alice.Deadline);
}
- private static MockRpcClient GetMockRpc(Key? key = null)
- {
- MockRpcClient rpc = new();
-
- rpc.OnGetTxOutAsync = (_, _, _) => new()
- {
- Confirmations = 1,
- ScriptPubKeyType = "witness_v0_keyhash",
- TxOut = new(Money.Coins(1), key?.PubKey.GetSegwitAddress(Network.Main).ScriptPubKey ?? Script.Empty)
- };
-
- return rpc;
- }
-
[Fact]
public async Task SuccessAsync()
{
@@ -50,7 +36,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend
using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(cfg, round);
using Key key = new();
- await using PostRequestHandler handler = new(cfg, new(), arena, GetMockRpc(key));
+ await using PostRequestHandler handler = new(cfg, new(), arena, WabiSabiFactory.CreateMockRpc(key));
var req = WabiSabiFactory.CreateInputsRegistrationRequest(key, round);
var minAliceDeadline = DateTimeOffset.UtcNow + cfg.ConnectionConfirmationTimeout * 0.9;
@@ -74,7 +60,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend
var preAlice = WabiSabiFactory.CreateAlice(req.InputRoundSignaturePairs);
round.Alices.Add(preAlice);
- await using PostRequestHandler handler = new(cfg, new(), arena, GetMockRpc(key));
+ await using PostRequestHandler handler = new(cfg, new(), arena, WabiSabiFactory.CreateMockRpc(key));
var minAliceDeadline = DateTimeOffset.UtcNow + cfg.ConnectionConfirmationTimeout * 0.9;
var resp = await handler.RegisterInputAsync(req);
AssertSingleAliceSuccessfullyRegistered(round, minAliceDeadline, resp);
@@ -97,7 +83,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend
var preAlice = WabiSabiFactory.CreateAlice(req.InputRoundSignaturePairs);
anotherRound.Alices.Add(preAlice);
- await using PostRequestHandler handler = new(cfg, new(), arena, GetMockRpc(key));
+ await using PostRequestHandler handler = new(cfg, new(), arena, WabiSabiFactory.CreateMockRpc(key));
var minAliceDeadline = DateTimeOffset.UtcNow + cfg.ConnectionConfirmationTimeout * 0.9;
var resp = await handler.RegisterInputAsync(req);
AssertSingleAliceSuccessfullyRegistered(round, minAliceDeadline, resp);
@@ -112,7 +98,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend
using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync();
using Key key = new();
- await using PostRequestHandler handler = new(new(), new(), arena, GetMockRpc(key));
+ await using PostRequestHandler handler = new(new(), new(), arena, WabiSabiFactory.CreateMockRpc(key));
var req = WabiSabiFactory.CreateInputsRegistrationRequest();
var ex = await Assert.ThrowsAsync<WabiSabiProtocolException>(async () => await handler.RegisterInputAsync(req));
Assert.Equal(WabiSabiProtocolErrorCode.RoundNotFound, ex.ErrorCode);
@@ -129,7 +115,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend
using Key key = new();
var req = WabiSabiFactory.CreateInputsRegistrationRequest(key, round);
- await using PostRequestHandler handler = new(cfg, new(), arena, GetMockRpc(key));
+ await using PostRequestHandler handler = new(cfg, new(), arena, WabiSabiFactory.CreateMockRpc(key));
foreach (Phase phase in Enum.GetValues(typeof(Phase)))
{
if (phase != Phase.InputRegistration)
@@ -152,7 +138,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend
using Key key = new();
var req = WabiSabiFactory.CreateInputsRegistrationRequest(key, round);
- await using PostRequestHandler handler = new(cfg, new(), arena, GetMockRpc(key));
+ await using PostRequestHandler handler = new(cfg, new(), arena, WabiSabiFactory.CreateMockRpc(key));
await arena.TriggerAndWaitRoundAsync(TimeSpan.FromSeconds(21));
round.Alices.Add(WabiSabiFactory.CreateAlice());
@@ -173,7 +159,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend
using Key key = new();
var req = WabiSabiFactory.CreateInputsRegistrationRequest(key, round);
- await using PostRequestHandler handler = new(cfg, new(), arena, GetMockRpc(key));
+ await using PostRequestHandler handler = new(cfg, new(), arena, WabiSabiFactory.CreateMockRpc(key));
await arena.TriggerAndWaitRoundAsync(TimeSpan.FromSeconds(21));
arena.Rounds.Add(round.Id, round);
@@ -192,7 +178,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend
using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(cfg);
using Key key = new();
- await using PostRequestHandler handler = new(cfg, new(), arena, GetMockRpc(key));
+ await using PostRequestHandler handler = new(cfg, new(), arena, WabiSabiFactory.CreateMockRpc(key));
await arena.TriggerAndWaitRoundAsync(TimeSpan.FromSeconds(21));
var round = arena.Rounds.First().Value;
var req = WabiSabiFactory.CreateInputsRegistrationRequest(key, round);
@@ -213,7 +199,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend
using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(cfg, round);
var inputSigPair = WabiSabiFactory.CreateInputRoundSignaturePair();
- await using PostRequestHandler handler = new(cfg, new(), arena, GetMockRpc());
+ await using PostRequestHandler handler = new(cfg, new(), arena, WabiSabiFactory.CreateMockRpc());
var req = WabiSabiFactory.CreateInputsRegistrationRequest(new[] { inputSigPair, inputSigPair }, round);
var ex = await Assert.ThrowsAsync<WabiSabiProtocolException>(async () => await handler.RegisterInputAsync(req));
Assert.Equal(WabiSabiProtocolErrorCode.NonUniqueInputs, ex.ErrorCode);
@@ -229,7 +215,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend
using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(cfg, round);
using Key key = new();
- await using PostRequestHandler handler = new(cfg, new(), arena, GetMockRpc(key));
+ await using PostRequestHandler handler = new(cfg, new(), arena, WabiSabiFactory.CreateMockRpc(key));
var req = WabiSabiFactory.CreateInputsRegistrationRequest(WabiSabiFactory.CreateInputRoundSignaturePairs(4), round);
var ex = await Assert.ThrowsAsync<WabiSabiProtocolException>(async () => await handler.RegisterInputAsync(req));
Assert.Equal(WabiSabiProtocolErrorCode.TooManyInputs, ex.ErrorCode);
@@ -246,7 +232,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend
WabiSabiConfig cfg = new();
var round = WabiSabiFactory.CreateRound(cfg);
using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(cfg, round);
- await using PostRequestHandler handler = new(cfg, prison, arena, GetMockRpc());
+ await using PostRequestHandler handler = new(cfg, prison, arena, WabiSabiFactory.CreateMockRpc());
var req = WabiSabiFactory.CreateInputsRegistrationRequest(pair, round);
var ex = await Assert.ThrowsAsync<WabiSabiProtocolException>(async () => await handler.RegisterInputAsync(req));
Assert.Equal(WabiSabiProtocolErrorCode.InputBanned, ex.ErrorCode);
@@ -264,7 +250,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend
var round = WabiSabiFactory.CreateRound(cfg);
using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(cfg, round);
- await using PostRequestHandler handler = new(cfg, prison, arena, GetMockRpc());
+ await using PostRequestHandler handler = new(cfg, prison, arena, WabiSabiFactory.CreateMockRpc());
var req = WabiSabiFactory.CreateInputsRegistrationRequest(pair, round);
var ex = await Assert.ThrowsAnyAsync<Exception>(async () => await handler.RegisterInputAsync(req));
if (ex is WabiSabiProtocolException wspex)
@@ -285,7 +271,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend
var round = WabiSabiFactory.CreateRound(cfg);
using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(cfg, round);
- await using PostRequestHandler handler = new(cfg, prison, arena, GetMockRpc());
+ await using PostRequestHandler handler = new(cfg, prison, arena, WabiSabiFactory.CreateMockRpc());
var req = WabiSabiFactory.CreateInputsRegistrationRequest(pair, round);
var ex = await Assert.ThrowsAsync<WabiSabiProtocolException>(async () => await handler.RegisterInputAsync(req));
Assert.Equal(WabiSabiProtocolErrorCode.InputBanned, ex.ErrorCode);
@@ -293,66 +279,6 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend
await arena.StopAsync(CancellationToken.None);
}
- [Fact]
- public async Task InputNotWhitelistedAsync()
- {
- WabiSabiConfig cfg = new();
- var round = WabiSabiFactory.CreateRound(cfg);
- round.Alices.Add(WabiSabiFactory.CreateAlice());
- Round blameRound = WabiSabiFactory.CreateBlameRound(round, cfg);
- using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(cfg, round, blameRound);
- using Key key = new();
-
- await using PostRequestHandler handler = new(cfg, new(), arena, GetMockRpc(key));
- var req = WabiSabiFactory.CreateInputsRegistrationRequest(blameRound);
- var ex = await Assert.ThrowsAsync<WabiSabiProtocolException>(async () => await handler.RegisterInputAsync(req));
- Assert.Equal(WabiSabiProtocolErrorCode.InputNotWhitelisted, ex.ErrorCode);
-
- await arena.StopAsync(CancellationToken.None);
- }
-
- [Fact]
- public async Task InputWhitelistedAsync()
- {
- var pair = WabiSabiFactory.CreateInputRoundSignaturePair();
- WabiSabiConfig cfg = new();
- var round = WabiSabiFactory.CreateRound(cfg);
- round.Alices.Add(WabiSabiFactory.CreateAlice(pair));
- Round blameRound = WabiSabiFactory.CreateBlameRound(round, cfg);
- using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(cfg, round, blameRound);
-
- await using PostRequestHandler handler = new(cfg, new(), arena, GetMockRpc());
- var req = WabiSabiFactory.CreateInputsRegistrationRequest(pair, blameRound);
-
- var ex = await Assert.ThrowsAnyAsync<Exception>(async () => await handler.RegisterInputAsync(req));
- if (ex is WabiSabiProtocolException wspex)
- {
- Assert.NotEqual(WabiSabiProtocolErrorCode.InputNotWhitelisted, wspex.ErrorCode);
- }
-
- await arena.StopAsync(CancellationToken.None);
- }
-
- [Fact]
- public async Task InputWhitelistedButBannedAsync()
- {
- Prison prison = new();
- var pair = WabiSabiFactory.CreateInputRoundSignaturePair();
- prison.Punish(pair.Input, Punishment.Banned, Guid.NewGuid());
- WabiSabiConfig cfg = new();
- var round = WabiSabiFactory.CreateRound(cfg);
- round.Alices.Add(WabiSabiFactory.CreateAlice(pair));
- Round blameRound = WabiSabiFactory.CreateBlameRound(round, cfg);
- using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(cfg, round, blameRound);
-
- await using PostRequestHandler handler = new(cfg, prison, arena, GetMockRpc());
- var req = WabiSabiFactory.CreateInputsRegistrationRequest(pair, blameRound);
- var ex = await Assert.ThrowsAsync<WabiSabiProtocolException>(async () => await handler.RegisterInputAsync(req));
- Assert.Equal(WabiSabiProtocolErrorCode.InputBanned, ex.ErrorCode);
-
- await arena.StopAsync(CancellationToken.None);
- }
-
[Fact]
public async Task InputSpentAsync()
{
@@ -439,7 +365,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend
using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(cfg, round);
using Key key = new();
- await using PostRequestHandler handler = new(cfg, new(), arena, GetMockRpc(key));
+ await using PostRequestHandler handler = new(cfg, new(), arena, WabiSabiFactory.CreateMockRpc(key));
var req = WabiSabiFactory.CreateInputsRegistrationRequest(round);
var ex = await Assert.ThrowsAsync<WabiSabiProtocolException>(async () => await handler.RegisterInputAsync(req));
Assert.Equal(WabiSabiProtocolErrorCode.WrongRoundSignature, ex.ErrorCode);
@@ -455,7 +381,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend
using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(cfg, round);
using Key key = new();
- await using PostRequestHandler handler = new(cfg, new(), arena, GetMockRpc(key));
+ await using PostRequestHandler handler = new(cfg, new(), arena, WabiSabiFactory.CreateMockRpc(key));
var req = WabiSabiFactory.CreateInputsRegistrationRequest(key, round);
var ex = await Assert.ThrowsAsync<WabiSabiProtocolException>(async () => await handler.RegisterInputAsync(req));
Assert.Equal(WabiSabiProtocolErrorCode.NotEnoughFunds, ex.ErrorCode);
@@ -471,7 +397,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend
using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(cfg, round);
using Key key = new();
- await using PostRequestHandler handler = new(cfg, new(), arena, GetMockRpc(key));
+ await using PostRequestHandler handler = new(cfg, new(), arena, WabiSabiFactory.CreateMockRpc(key));
var req = WabiSabiFactory.CreateInputsRegistrationRequest(key, round);
var ex = await Assert.ThrowsAsync<WabiSabiProtocolException>(async () => await handler.RegisterInputAsync(req));
Assert.Equal(WabiSabiProtocolErrorCode.TooMuchFunds, ex.ErrorCode);
@@ -487,7 +413,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend
using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(cfg, round);
using Key key = new();
- await using PostRequestHandler handler = new(cfg, new(), arena, GetMockRpc(key));
+ await using PostRequestHandler handler = new(cfg, new(), arena, WabiSabiFactory.CreateMockRpc(key));
var req = WabiSabiFactory.CreateInputsRegistrationRequest(key, round);
var ex = await Assert.ThrowsAsync<WabiSabiProtocolException>(async () => await handler.RegisterInputAsync(req));
Assert.Equal(WabiSabiProtocolErrorCode.TooMuchWeight, ex.ErrorCode);
@@ -510,7 +436,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend
round.Alices.Add(anotherAlice);
round.SetPhase(Phase.ConnectionConfirmation);
- await using PostRequestHandler handler = new(cfg, new(), arena, GetMockRpc(key));
+ await using PostRequestHandler handler = new(cfg, new(), arena, WabiSabiFactory.CreateMockRpc(key));
var ex = await Assert.ThrowsAsync<WabiSabiProtocolException>(async () => await handler.RegisterInputAsync(req));
Assert.Equal(WabiSabiProtocolErrorCode.WrongPhase, ex.ErrorCode);
@@ -533,7 +459,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend
anotherRound.Alices.Add(preAlice);
anotherRound.SetPhase(Phase.ConnectionConfirmation);
- await using PostRequestHandler handler = new(cfg, new(), arena, GetMockRpc(key));
+ await using PostRequestHandler handler = new(cfg, new(), arena, WabiSabiFactory.CreateMockRpc(key));
var ex = await Assert.ThrowsAsync<WabiSabiProtocolException>(async () => await handler.RegisterInputAsync(req));
Assert.Equal(WabiSabiProtocolErrorCode.AliceAlreadyRegistered, ex.ErrorCode);

ADD
WalletWasabi.Tests/UnitTests/WabiSabi/Backend/RegisterInputToBlameRoundTests.cs
+using NBitcoin;
+using NBitcoin.RPC;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+using WalletWasabi.Tests.Helpers;
+using WalletWasabi.WabiSabi.Backend;
+using WalletWasabi.WabiSabi.Backend.Banning;
+using WalletWasabi.WabiSabi.Backend.Models;
+using WalletWasabi.WabiSabi.Backend.PostRequests;
+using WalletWasabi.WabiSabi.Backend.Rounds;
+using WalletWasabi.WabiSabi.Models;
+using Xunit;
+
+namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend
+{
+ public class RegisterInputToBlameRoundTests
+ {
+ [Fact]
+ public async Task InputNotWhitelistedAsync()
+ {
+ WabiSabiConfig cfg = new();
+ var round = WabiSabiFactory.CreateRound(cfg);
+ round.Alices.Add(WabiSabiFactory.CreateAlice());
+ Round blameRound = WabiSabiFactory.CreateBlameRound(round, cfg);
+ using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(cfg, round, blameRound);
+ using Key key = new();
+
+ await using PostRequestHandler handler = new(cfg, new(), arena, WabiSabiFactory.CreateMockRpc(key));
+ var req = WabiSabiFactory.CreateInputsRegistrationRequest(blameRound);
+ var ex = await Assert.ThrowsAsync<WabiSabiProtocolException>(async () => await handler.RegisterInputAsync(req));
+ Assert.Equal(WabiSabiProtocolErrorCode.InputNotWhitelisted, ex.ErrorCode);
+
+ await arena.StopAsync(CancellationToken.None);
+ }
+
+ [Fact]
+ public async Task InputWhitelistedAsync()
+ {
+ var pair = WabiSabiFactory.CreateInputRoundSignaturePair();
+ WabiSabiConfig cfg = new();
+ var round = WabiSabiFactory.CreateRound(cfg);
+ round.Alices.Add(WabiSabiFactory.CreateAlice(pair));
+ Round blameRound = WabiSabiFactory.CreateBlameRound(round, cfg);
+ using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(cfg, round, blameRound);
+
+ await using PostRequestHandler handler = new(cfg, new(), arena, WabiSabiFactory.CreateMockRpc());
+ var req = WabiSabiFactory.CreateInputsRegistrationRequest(pair, blameRound);
+
+ var ex = await Assert.ThrowsAnyAsync<Exception>(async () => await handler.RegisterInputAsync(req));
+ if (ex is WabiSabiProtocolException wspex)
+ {
+ Assert.NotEqual(WabiSabiProtocolErrorCode.InputNotWhitelisted, wspex.ErrorCode);
+ }
+
+ await arena.StopAsync(CancellationToken.None);
+ }
+
+ [Fact]
+ public async Task InputWhitelistedButBannedAsync()
+ {
+ Prison prison = new();
+ var pair = WabiSabiFactory.CreateInputRoundSignaturePair();
+ prison.Punish(pair.Input, Punishment.Banned, Guid.NewGuid());
+ WabiSabiConfig cfg = new();
+ var round = WabiSabiFactory.CreateRound(cfg);
+ round.Alices.Add(WabiSabiFactory.CreateAlice(pair));
+ Round blameRound = WabiSabiFactory.CreateBlameRound(round, cfg);
+ using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(cfg, round, blameRound);
+
+ await using PostRequestHandler handler = new(cfg, prison, arena, WabiSabiFactory.CreateMockRpc());
+ var req = WabiSabiFactory.CreateInputsRegistrationRequest(pair, blameRound);
+ var ex = await Assert.ThrowsAsync<WabiSabiProtocolException>(async () => await handler.RegisterInputAsync(req));
+ Assert.Equal(WabiSabiProtocolErrorCode.InputBanned, ex.ErrorCode);
+
+ await arena.StopAsync(CancellationToken.None);
+ }
+ }
+}

Separate blame tests from normal tests