public async Task AliceAlreadyRegisteredCrossRoundAsync() { WabiSabiConfig cfg = new(); var round = WabiSabiFactory.CreateRound(cfg); var anotherRound = WabiSabiFactory.CreateRound(cfg); using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(cfg, round, anotherRound); using Key key = new(); var req = WabiSabiFactory.CreateInputsRegistrationRequest(key, round); // Make sure an Alice have already been registered with the same input. var preAlice = WabiSabiFactory.CreateAlice(req.InputRoundSignaturePairs); anotherRound.Alices.Add(preAlice); anotherRound.SetPhase(Phase.ConnectionConfirmation); await using ArenaRequestHandler 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); await arena.StopAsync(CancellationToken.None); }
public async Task WrongPhaseAsync() { WabiSabiConfig cfg = new(); using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(cfg); await arena.TriggerAndWaitRoundAsync(TimeSpan.FromSeconds(21)).ConfigureAwait(false); var round = arena.Rounds.First().Value; using Key key = new(); var req = WabiSabiFactory.CreateInputsRegistrationRequest(key, round); await using ArenaRequestHandler handler = new(cfg, new(), arena, WabiSabiFactory.CreateMockRpc(key)); foreach (Phase phase in Enum.GetValues(typeof(Phase))) { if (phase != Phase.InputRegistration) { round.SetPhase(phase); await RegisterAndAssertWrongPhaseAsync(req, handler); } } await arena.StopAsync(CancellationToken.None); }
public async Task InputRegistrationFullWeightAsync() { WabiSabiConfig cfg = new(); var round = WabiSabiFactory.CreateRound(cfg); using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(cfg, round); using Key key = new(); await using ArenaRequestHandler handler = new(cfg, new(), arena, WabiSabiFactory.CreateMockRpc(key)); // TODO add configuration parameter round.InitialInputVsizeAllocation = (int)round.PerAliceVsizeAllocation; // Add an alice await arena.TriggerAndWaitRoundAsync(TimeSpan.FromSeconds(21)); round.Alices.Add(WabiSabiFactory.CreateAlice()); Assert.Equal(0, round.RemainingInputVsizeAllocation); // try to add an additional input var req = WabiSabiFactory.CreateInputsRegistrationRequest(key, round); var ex = await Assert.ThrowsAsync <WabiSabiProtocolException>(async() => await handler.RegisterInputAsync(req)); Assert.Equal(WabiSabiProtocolErrorCode.TooMuchTotalWeight, ex.ErrorCode); await arena.StopAsync(CancellationToken.None); }
public async Task SuccessWithAliceUpdateCrossRoundAsync() { WabiSabiConfig cfg = new(); var round = WabiSabiFactory.CreateRound(cfg); var anotherRound = WabiSabiFactory.CreateRound(cfg); using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(cfg, round, anotherRound); using Key key = new(); var req = WabiSabiFactory.CreateInputsRegistrationRequest(key, round); // Make sure an Alice have already been registered with the same input. var preAlice = WabiSabiFactory.CreateAlice(req.InputRoundSignaturePairs); anotherRound.Alices.Add(preAlice); await using ArenaRequestHandler 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); Assert.Empty(anotherRound.Alices); await arena.StopAsync(CancellationToken.None); }
public async Task RoundNotFoundAsync() { using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(); using Key key = new(); await using ArenaRequestHandler 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); await arena.StopAsync(CancellationToken.None); }
public async Task TooMuchWeightAsync() { WabiSabiConfig cfg = new() { RegistrableWeightCredentials = 1 }; var round = WabiSabiFactory.CreateRound(cfg); using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(cfg, round); using Key key = new(); await using ArenaRequestHandler 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); await arena.StopAsync(CancellationToken.None); }
public async Task TooManyInputsAsync() { WabiSabiConfig cfg = new() { MaxInputCountByAlice = 3 }; var round = WabiSabiFactory.CreateRound(cfg); using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(cfg, round); using Key key = new(); await using ArenaRequestHandler 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); await arena.StopAsync(CancellationToken.None); }
public async Task NonUniqueInputsAsync() { WabiSabiConfig cfg = new(); var round = WabiSabiFactory.CreateRound(cfg); using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(cfg, round); var inputSigPair = WabiSabiFactory.CreateInputRoundSignaturePair(); await using ArenaRequestHandler 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); await arena.StopAsync(CancellationToken.None); }
public async Task NotEnoughFundsAsync() { WabiSabiConfig cfg = new() { MinRegistrableAmount = Money.Coins(2) }; var round = WabiSabiFactory.CreateRound(cfg); using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(cfg, round); using Key key = new(); 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); await arena.StopAsync(CancellationToken.None); }
public async Task SuccessAsync() { WabiSabiConfig cfg = new(); var round = WabiSabiFactory.CreateRound(cfg); using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(cfg, round); using Key key = new(); await using ArenaRequestHandler handler = new(cfg, new(), arena, WabiSabiFactory.CreateMockRpc(key)); var req = WabiSabiFactory.CreateInputsRegistrationRequest(key, round); var minAliceDeadline = DateTimeOffset.UtcNow + cfg.ConnectionConfirmationTimeout * 0.9; var resp = await handler.RegisterInputAsync(req); AssertSingleAliceSuccessfullyRegistered(round, minAliceDeadline, resp); await arena.StopAsync(CancellationToken.None); }
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); }
public async Task InputRegistrationTimedoutAsync() { WabiSabiConfig cfg = new() { StandardInputRegistrationTimeout = TimeSpan.Zero }; var round = WabiSabiFactory.CreateRound(cfg); using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(cfg); using Key key = new(); var req = WabiSabiFactory.CreateInputsRegistrationRequest(key, round); await using ArenaRequestHandler handler = new(cfg, new(), arena, WabiSabiFactory.CreateMockRpc(key)); await arena.TriggerAndWaitRoundAsync(TimeSpan.FromSeconds(21)); arena.Rounds.Add(round.Id, round); await RegisterAndAssertWrongPhaseAsync(req, handler); Assert.Equal(Phase.InputRegistration, round.Phase); await arena.StopAsync(CancellationToken.None); }
public async Task AliceAlreadyRegisteredIntraRoundAsync() { WabiSabiConfig cfg = new(); var round = WabiSabiFactory.CreateRound(cfg); using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(cfg, round); using Key key = new(); var req = WabiSabiFactory.CreateInputsRegistrationRequest(key, round); // Make sure an Alice have already been registered with the same input. var anotherAlice = WabiSabiFactory.CreateAlice(req.InputRoundSignaturePairs); round.Alices.Add(anotherAlice); round.SetPhase(Phase.ConnectionConfirmation); await using ArenaRequestHandler handler = new(cfg, new(), arena, WabiSabiFactory.CreateMockRpc(key)); await RegisterAndAssertWrongPhaseAsync(req, handler); await arena.StopAsync(CancellationToken.None); }
public async Task InputRegistrationFullAsync() { WabiSabiConfig cfg = new() { MaxInputCountByRound = 3 }; var round = WabiSabiFactory.CreateRound(cfg); using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(cfg, round); using Key key = new(); var req = WabiSabiFactory.CreateInputsRegistrationRequest(key, round); await using ArenaRequestHandler handler = new(cfg, new(), arena, WabiSabiFactory.CreateMockRpc(key)); await arena.TriggerAndWaitRoundAsync(TimeSpan.FromSeconds(21)); round.Alices.Add(WabiSabiFactory.CreateAlice()); round.Alices.Add(WabiSabiFactory.CreateAlice(WabiSabiFactory.CreateInputRoundSignaturePairs(2))); await RegisterAndAssertWrongPhaseAsync(req, handler); Assert.Equal(Phase.InputRegistration, round.Phase); await arena.StopAsync(CancellationToken.None); }
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); }