public async Task WrongPhaseAsync() { WabiSabiConfig cfg = new(); using Arena arena = await ArenaBuilder.From(cfg).CreateAndStartAsync(); await arena.TriggerAndWaitRoundAsync(TimeSpan.FromSeconds(21)); var round = arena.Rounds.First(); var req = new InputsRemovalRequest(round.Id, Guid.NewGuid()); foreach (Phase phase in Enum.GetValues(typeof(Phase))) { if (phase != Phase.InputRegistration) { round.SetPhase(phase); var ex = await Assert.ThrowsAsync <WrongPhaseException>(async() => await arena.RemoveInputAsync(req, CancellationToken.None)); Assert.Equal(WabiSabiProtocolErrorCode.WrongPhase, 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; var req = new InputsRemovalRequest(round.Id, Guid.NewGuid()); foreach (Phase phase in Enum.GetValues(typeof(Phase))) { if (phase != Phase.InputRegistration) { round.SetPhase(phase); await using ArenaRequestHandler handler = new(cfg, new Prison(), arena, new MockRpcClient()); var ex = await Assert.ThrowsAsync <WabiSabiProtocolException>(async() => await handler.RemoveInputAsync(req)); Assert.Equal(WabiSabiProtocolErrorCode.WrongPhase, ex.ErrorCode); } } await arena.StopAsync(CancellationToken.None); }
public async Task SuccessAsync() { WabiSabiConfig cfg = new(); var round = WabiSabiFactory.CreateRound(cfg); var initialRemaining = round.RemainingInputVsizeAllocation; var alice = WabiSabiFactory.CreateAlice(); round.Alices.Add(alice); Assert.True(round.RemainingInputVsizeAllocation < initialRemaining); using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(cfg, round); await using ArenaRequestHandler handler = new(cfg, new Prison(), arena, new MockRpcClient()); // There's no such alice yet, so success. var req = new InputsRemovalRequest(round.Id, Guid.NewGuid()); await handler.RemoveInputAsync(req); // There was the alice we want to remove so success. req = new InputsRemovalRequest(round.Id, alice.Id); await handler.RemoveInputAsync(req); // Ensure that removing an alice freed up the input weight // allocation from the round Assert.Equal(initialRemaining, round.RemainingInputVsizeAllocation); await arena.StopAsync(CancellationToken.None); }
public async Task RemoveInputAsync(InputsRemovalRequest request, CancellationToken cancellationToken) { using (await AsyncLock.LockAsync(cancellationToken).ConfigureAwait(false)) { var round = GetRound(request.RoundId, Phase.InputRegistration); round.Alices.RemoveAll(x => x.Id == request.AliceId); } }
public async Task RoundNotFoundAsync() { using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(); var req = new InputsRemovalRequest(uint256.Zero, Guid.NewGuid()); var ex = await Assert.ThrowsAsync <WabiSabiProtocolException>(async() => await arena.RemoveInputAsync(req, CancellationToken.None)); Assert.Equal(WabiSabiProtocolErrorCode.RoundNotFound, ex.ErrorCode); await arena.StopAsync(CancellationToken.None); }
public async Task RoundNotFoundAsync() { using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(); await using ArenaRequestHandler handler = new(new WabiSabiConfig(), new Prison(), arena, new MockRpcClient()); var req = new InputsRemovalRequest(Guid.NewGuid(), Guid.NewGuid()); var ex = await Assert.ThrowsAsync <WabiSabiProtocolException>(async() => await handler.RemoveInputAsync(req)); Assert.Equal(WabiSabiProtocolErrorCode.RoundNotFound, ex.ErrorCode); await arena.StopAsync(CancellationToken.None); }
public async Task RoundNotFoundAsync() { MockArena arena = new(); arena.OnTryGetRound = _ => null; await using PostRequestHandler handler = new(new WabiSabiConfig(), new Prison(), arena, new MockRpcClient()); var req = new InputsRemovalRequest(Guid.NewGuid(), Guid.NewGuid()); var ex = Assert.Throws <WabiSabiProtocolException>(() => handler.RemoveInput(req)); Assert.Equal(WabiSabiProtocolErrorCode.RoundNotFound, ex.ErrorCode); }
public async Task SuccessAsync() { WabiSabiConfig cfg = new(); var round = WabiSabiFactory.CreateRound(cfg); var alice = WabiSabiFactory.CreateAlice(); round.Alices.Add(alice); using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(cfg, round); await using ArenaRequestHandler handler = new(cfg, new Prison(), arena, new MockRpcClient()); // There's no such alice yet, so success. var req = new InputsRemovalRequest(round.Id, Guid.NewGuid()); await handler.RemoveInputAsync(req); // There was the alice we want to remove so success. req = new InputsRemovalRequest(round.Id, alice.Id); await handler.RemoveInputAsync(req); await arena.StopAsync(CancellationToken.None); }
public async Task WrongPhaseAsync() { MockArena arena = new(); WabiSabiConfig cfg = new(); var round = WabiSabiFactory.CreateRound(cfg); arena.OnTryGetRound = _ => round; var req = new InputsRemovalRequest(round.Id, Guid.NewGuid()); foreach (Phase phase in Enum.GetValues(typeof(Phase))) { if (phase != Phase.InputRegistration) { round.Phase = phase; await using PostRequestHandler handler = new(cfg, new Prison(), arena, new MockRpcClient()); var ex = Assert.Throws <WabiSabiProtocolException>(() => handler.RemoveInput(req)); Assert.Equal(WabiSabiProtocolErrorCode.WrongPhase, ex.ErrorCode); } } }
public async Task RemoveInputAsync(InputsRemovalRequest request, CancellationToken cancellableToken) { await Arena.RemoveInputAsync(request, cancellableToken); }
public Task RemoveInputAsync(InputsRemovalRequest request, CancellationToken cancellableToken) { return(RequestHandler.RemoveInputAsync(request, cancellableToken)); }
public Task RemoveInputAsync(InputsRemovalRequest request, CancellationToken cancellationToken) => SendAndReceiveAsync <InputsRemovalRequest>(RemoteAction.RemoveInput, request, cancellationToken);
public Task RemoveInputAsync(InputsRemovalRequest request, CancellationToken cancellationToken) => arena.RemoveInputAsync(request);