Write some tests
MODIFY
WalletWasabi.Tests/Helpers/WabiSabiFactory.cs
WalletWasabi.Tests/Helpers/WabiSabiFactory.cs
@@ -76,7 +76,7 @@ namespace WalletWasabi.Tests.Helpers
Blocks = target,
FeeRate = new FeeRate(10m)
});
- Arena arena = new(TimeSpan.FromSeconds(1), rounds.FirstOrDefault()?.Network ?? Network.Main, cfg ?? new WabiSabiConfig(), mockRpc);
+ Arena arena = new(TimeSpan.FromSeconds(21), rounds.FirstOrDefault()?.Network ?? Network.Main, cfg ?? new WabiSabiConfig(), mockRpc);
foreach (var round in rounds)
{
arena.Rounds.Add(round.Id, round);

MODIFY
WalletWasabi.Tests/UnitTests/WabiSabi/Backend/RegisterInputTests.cs
WalletWasabi.Tests/UnitTests/WabiSabi/Backend/RegisterInputTests.cs
@@ -171,6 +171,63 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend
await arena.StopAsync(CancellationToken.None);
}
+ [Fact]
+ public async Task InputRegistrationFullAsync()
+ {
+ WabiSabiConfig cfg = new() { MaxInputCountByRound = 3 };
+ var round = WabiSabiFactory.CreateRound(cfg);
+ using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(cfg, round);
+ MockRpcClient rpc = new();
+ using Key key = new();
+
+ rpc.OnGetTxOutAsync = (_, _, _) => new()
+ {
+ Confirmations = 1,
+ ScriptPubKeyType = "witness_v0_keyhash",
+ TxOut = new TxOut(Money.Coins(1), key.PubKey.GetSegwitAddress(Network.Main))
+ };
+
+ var req = WabiSabiFactory.CreateInputsRegistrationRequest(key, round);
+ await using PostRequestHandler handler = new(cfg, new Prison(), arena, rpc);
+
+ await arena.TriggerAndWaitRoundAsync(TimeSpan.FromSeconds(21));
+ round.Alices.Add(WabiSabiFactory.CreateAlice());
+ round.Alices.Add(WabiSabiFactory.CreateAlice(WabiSabiFactory.CreateInputRoundSignaturePairs(2)));
+ var ex = await Assert.ThrowsAsync<WabiSabiProtocolException>(async () => await handler.RegisterInputAsync(req));
+ Assert.Equal(Phase.InputRegistration, round.Phase);
+ Assert.Equal(WabiSabiProtocolErrorCode.WrongPhase, ex.ErrorCode);
+
+ await arena.StopAsync(CancellationToken.None);
+ }
+
+ [Fact]
+ public async Task InputRegistrationTimedoutAsync()
+ {
+ WabiSabiConfig cfg = new();
+ var round = WabiSabiFactory.CreateRound(cfg);
+ using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(cfg, round);
+ MockRpcClient rpc = new();
+ using Key key = new();
+
+ rpc.OnGetTxOutAsync = (_, _, _) => new()
+ {
+ Confirmations = 1,
+ ScriptPubKeyType = "witness_v0_keyhash",
+ TxOut = new TxOut(Money.Coins(1), key.PubKey.GetSegwitAddress(Network.Main))
+ };
+
+ var req = WabiSabiFactory.CreateInputsRegistrationRequest(key, round);
+ await using PostRequestHandler handler = new(cfg, new Prison(), arena, rpc);
+
+ await arena.TriggerAndWaitRoundAsync(TimeSpan.FromSeconds(21));
+ cfg.InputRegistrationTimeout = TimeSpan.Zero;
+ var ex = await Assert.ThrowsAsync<WabiSabiProtocolException>(async () => await handler.RegisterInputAsync(req));
+ Assert.Equal(Phase.InputRegistration, round.Phase);
+ Assert.Equal(WabiSabiProtocolErrorCode.WrongPhase, ex.ErrorCode);
+
+ await arena.StopAsync(CancellationToken.None);
+ }
+
[Fact]
public async Task NonUniqueInputsAsync()
{

Write some tests