Assert InputRegistration phase
MODIFY
WalletWasabi.Tests/UnitTests/WabiSabi/Backend/InputRegistrationTests.cs
WalletWasabi.Tests/UnitTests/WabiSabi/Backend/InputRegistrationTests.cs
@@ -6,6 +6,7 @@ using System.Threading.Tasks;
using WalletWasabi.WabiSabi.Backend;
using WalletWasabi.WabiSabi.Backend.Banning;
using WalletWasabi.WabiSabi.Backend.PostRequests;
+using WalletWasabi.WabiSabi.Backend.Rounds;
using WalletWasabi.WabiSabi.Models;
using Xunit;
@@ -16,10 +17,10 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend
[Fact]
public async Task RoundNotFoundAsync()
{
- var rc = new MockRoundCollection();
- rc.OnTryGetRound = (roundId) => null;
+ var arena = new MockArena();
+ arena.OnTryGetRound = (roundId) => null;
- await using PostRequestHandler handler = new(new WabiSabiConfig(), new Prison(), rc);
+ await using PostRequestHandler handler = new(new WabiSabiConfig(), new Prison(), arena);
var req = new InputsRegistrationRequest(
Guid.NewGuid(),
null!,
@@ -27,5 +28,28 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend
null!);
Assert.Throws<InvalidOperationException>(() => handler.RegisterInput(req));
}
+
+ [Fact]
+ public async Task WrongPhaseAsync()
+ {
+ var arena = new MockArena();
+ var round = new Round();
+ arena.OnTryGetRound = (roundId) => round;
+
+ foreach (Phase phase in Enum.GetValues(typeof(Phase)))
+ {
+ if (phase != Phase.InputRegistration)
+ {
+ round.Phase = phase;
+ await using PostRequestHandler handler = new(new WabiSabiConfig(), new Prison(), arena);
+ var req = new InputsRegistrationRequest(
+ round.Id,
+ null!,
+ null!,
+ null!);
+ Assert.Throws<InvalidOperationException>(() => handler.RegisterInput(req));
+ }
+ }
+ }
}
}

RENAME
WalletWasabi.Tests/UnitTests/WabiSabi/Backend/MockRoundCollection.cs
WalletWasabi.Tests/UnitTests/WabiSabi/Backend/MockArena.cs
@@ -8,7 +8,7 @@ using WalletWasabi.WabiSabi.Backend.Rounds;
namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend
{
- public class MockRoundCollection : IRoundCollection
+ public class MockArena : IArena
{
public Func<Guid, Round?> OnTryGetRound { get; set; } = (roundId) => null;

MODIFY
WalletWasabi.Tests/UnitTests/WabiSabi/Backend/RequestHandlerDisposeTests.cs
WalletWasabi.Tests/UnitTests/WabiSabi/Backend/RequestHandlerDisposeTests.cs
@@ -16,7 +16,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend
[Fact]
public async Task DisposeGuardAsync()
{
- PostRequestHandler handler = new(new WabiSabiConfig(), new Prison(), new MockRoundCollection());
+ PostRequestHandler handler = new(new WabiSabiConfig(), new Prison(), new MockArena());
await handler.DisposeAsync();
Assert.Throws<ObjectDisposedException>(() => handler.RegisterInput(null!));
}

MODIFY
WalletWasabi/WabiSabi/Backend/PostRequests/PostRequestHandler.cs
WalletWasabi/WabiSabi/Backend/PostRequests/PostRequestHandler.cs
@@ -13,11 +13,11 @@ namespace WalletWasabi.WabiSabi.Backend.PostRequests
{
public class PostRequestHandler : IAsyncDisposable
{
- public PostRequestHandler(WabiSabiConfig config, Prison prison, IRoundCollection roundCollection)
+ public PostRequestHandler(WabiSabiConfig config, Prison prison, IArena arena)
{
Config = config;
Prison = prison;
- RoundCollection = roundCollection;
+ Arena = arena;
}
private bool DisposeStarted { get; set; } = false;
@@ -25,17 +25,21 @@ namespace WalletWasabi.WabiSabi.Backend.PostRequests
private AbandonedTasks RunningRequests { get; } = new();
public WabiSabiConfig Config { get; }
public Prison Prison { get; }
- public IRoundCollection RoundCollection { get; }
+ public IArena Arena { get; }
public InputsRegistrationResponse RegisterInput(InputsRegistrationRequest request)
{
DisposeGuard();
using (RunningTasks.RememberWith(RunningRequests))
{
- if (!RoundCollection.TryGetRound(request.RoundId, out Round round))
+ if (!Arena.TryGetRound(request.RoundId, out var round))
{
throw new InvalidOperationException("Round not found.");
}
+ if (round.Phase != Phase.InputRegistration)
+ {
+ throw new InvalidOperationException("Wrong phase.");
+ }
throw new NotImplementedException();
}

RENAME
WalletWasabi/WabiSabi/Backend/Rounds/RoundCollection.cs
WalletWasabi/WabiSabi/Backend/Rounds/Arena.cs
@@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace WalletWasabi.WabiSabi.Backend.Rounds
{
- public class RoundCollection : IRoundCollection
+ public class Arena : IArena
{
public bool TryGetRound(Guid roundId, [NotNullWhen(true)] out Round? round)
{

RENAME
WalletWasabi/WabiSabi/Backend/Rounds/IRoundCollection.cs
WalletWasabi/WabiSabi/Backend/Rounds/IArena.cs
@@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace WalletWasabi.WabiSabi.Backend.Rounds
{
- public interface IRoundCollection
+ public interface IArena
{
public bool TryGetRound(Guid roundId, [NotNullWhen(true)] out Round? round);
}

ADD
WalletWasabi/WabiSabi/Backend/Rounds/Phase.cs
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WalletWasabi.WabiSabi.Backend.Rounds
+{
+ public enum Phase
+ {
+ InputRegistration,
+ ConnectionConfirmation,
+ OutputRegistration,
+ TransactionSigning
+ }
+}

MODIFY
WalletWasabi/WabiSabi/Backend/Rounds/Round.cs
WalletWasabi/WabiSabi/Backend/Rounds/Round.cs
@@ -8,5 +8,7 @@ namespace WalletWasabi.WabiSabi.Backend.Rounds
{
public class Round
{
+ public Guid Id { get; } = Guid.NewGuid();
+ public Phase Phase { get; set; } = Phase.InputRegistration;
}
}

MODIFY
WalletWasabi/WabiSabi/WabiSabiCoordinator.cs
WalletWasabi/WabiSabi/WabiSabiCoordinator.cs
@@ -33,7 +33,7 @@ namespace WalletWasabi.WabiSabi
public CoordinatorParameters Parameters { get; }
public PostRequestHandler Postman { get; }
- public RoundCollection Rounds { get; }
+ public Arena Rounds { get; }
public string WorkDir => Parameters.CoordinatorDataDir;
public Prison Prison => Warden.Prison;

Assert InputRegistration phase