Exemplo n.º 1
0
        public async Task NonUniqueInputsAsync()
        {
            MockArena      arena = new();
            WabiSabiConfig cfg   = new();
            var            round = WabiSabiFactory.CreateRound(cfg);

            arena.OnTryGetRound = _ => round;
            var inputSigPair = WabiSabiFactory.CreateInputRoundSignaturePair();

            await using PostRequestHandler handler = new(cfg, new Prison(), arena, new MockRpcClient());
            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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        public async Task InputBannedAsync()
        {
            MockArena arena  = new();
            Prison    prison = new();
            var       pair   = WabiSabiFactory.CreateInputRoundSignaturePair();

            prison.Punish(pair.Input, Punishment.Banned, Guid.NewGuid());
            WabiSabiConfig cfg   = new();
            var            round = WabiSabiFactory.CreateRound(cfg);

            arena.OnTryGetRound = _ => round;

            await using PostRequestHandler handler = new(cfg, prison, arena, new MockRpcClient());
            var req = WabiSabiFactory.CreateInputsRegistrationRequest(pair, round);
            var ex  = await Assert.ThrowsAsync <WabiSabiProtocolException>(async() => await handler.RegisterInputAsync(req));

            Assert.Equal(WabiSabiProtocolErrorCode.InputBanned, ex.ErrorCode);
        }
Exemplo n.º 4
0
        public async Task InputCantBeNotedAsync()
        {
            Prison prison = new();
            var    pair   = WabiSabiFactory.CreateInputRoundSignaturePair();

            prison.Punish(pair.Input, Punishment.Noted, Guid.NewGuid());
            WabiSabiConfig cfg   = new() { AllowNotedInputRegistration = false };
            var            round = WabiSabiFactory.CreateRound(cfg);

            using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(cfg, round);

            await using ArenaRequestHandler 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);

            await arena.StopAsync(CancellationToken.None);
        }
Exemplo n.º 5
0
        public async Task InputWhitelistedAsync()
        {
            MockArena      arena = new();
            var            pair  = WabiSabiFactory.CreateInputRoundSignaturePair();
            WabiSabiConfig cfg   = new();
            var            round = WabiSabiFactory.CreateRound(cfg);

            round.Alices.Add(new Alice(pair.Input));
            Round blameRound = new(round);

            arena.OnTryGetRound = _ => blameRound;

            await using PostRequestHandler handler = new(cfg, new Prison(), arena, new MockRpcClient());
            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);
            }
        }
Exemplo n.º 6
0
        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);
        }