コード例 #1
0
        public async Task InputRegistrationTimedoutWithoutSufficientInputsAsync()
        {
            WabiSabiConfig cfg = new()
            {
                StandardInputRegistrationTimeout = TimeSpan.Zero,
                MaxInputCountByRound             = 4,
                MinInputCountByRoundMultiplier   = 0.5
            };
            var round = WabiSabiFactory.CreateRound(cfg);

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

            round.Alices.Add(WabiSabiFactory.CreateAlice(round));
            await arena.TriggerAndWaitRoundAsync(TimeSpan.FromSeconds(21));

            Assert.Equal(Phase.Ended, round.Phase);
            Assert.DoesNotContain(round, arena.ActiveRounds);

            await arena.StopAsync(CancellationToken.None);
        }
コード例 #2
0
        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 ArenaRequestHandler 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);
        }
コード例 #3
0
        public async Task SuccessAsync()
        {
            WabiSabiConfig cfg   = new();
            var            round = WabiSabiFactory.CreateRound(cfg);

            using Key key = new();
            var coin = WabiSabiFactory.CreateCoin(key);

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

            var minAliceDeadline = DateTimeOffset.UtcNow + cfg.ConnectionConfirmationTimeout * 0.9;
            var arenaClient      = WabiSabiFactory.CreateArenaClient(arena);
            var ownershipProof   = WabiSabiFactory.CreateOwnershipProof(key, round.Id);

            var resp = await arenaClient.RegisterInputAsync(round.Id, coin.Outpoint, ownershipProof, CancellationToken.None);

            AssertSingleAliceSuccessfullyRegistered(round, minAliceDeadline, resp);

            await arena.StopAsync(CancellationToken.None);
        }
コード例 #4
0
    public async Task InputNotWhitelistedAsync()
    {
        WabiSabiConfig cfg   = new();
        var            round = WabiSabiFactory.CreateRound(cfg);

        round.Alices.Add(WabiSabiFactory.CreateAlice(round));
        Round blameRound = WabiSabiFactory.CreateBlameRound(round, cfg);

        using Arena arena = await ArenaBuilder.From(cfg).CreateAndStartAsync(round, blameRound);

        using Key key = new();
        var mockRpc = WabiSabiFactory.CreatePreconfiguredRpcClient();

        var req = WabiSabiFactory.CreateInputRegistrationRequest(round: blameRound);
        var ex  = await Assert.ThrowsAsync <WabiSabiProtocolException>(async() => await arena.RegisterInputAsync(req, CancellationToken.None));

        Assert.Equal(WabiSabiProtocolErrorCode.InputNotWhitelisted, ex.ErrorCode);

        await arena.StopAsync(CancellationToken.None);
    }
コード例 #5
0
        public async Task NonStandardOutputAsync()
        {
            WabiSabiConfig cfg   = new();
            var            round = WabiSabiFactory.CreateRound(cfg);

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

            round.SetPhase(Phase.OutputRegistration);
            round.Alices.Add(WabiSabiFactory.CreateAlice(Money.Coins(1), round));

            var sha256Bounty = Script.FromHex("aa20000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f87");
            var req          = WabiSabiFactory.CreateOutputRegistrationRequest(round, sha256Bounty);
            var ex           = await Assert.ThrowsAsync <WabiSabiProtocolException>(async() => await arena.RegisterOutputAsync(req, CancellationToken.None));

            // The following assertion requires standardness to be checked before allowed script types
            Assert.Equal(WabiSabiProtocolErrorCode.NonStandardOutput, ex.ErrorCode);

            await arena.StopAsync(CancellationToken.None);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        public async Task NonStandardOutputAsync()
        {
            WabiSabiConfig cfg   = new();
            var            round = WabiSabiFactory.CreateRound(cfg);

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

            using Key key = new();

            var sha256Bounty = Script.FromHex("aa20000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f87");
            var req          = WabiSabiFactory.CreateOutputRegistrationRequest(round, sha256Bounty);

            await using ArenaRequestHandler handler = new(cfg, new Prison(), arena, new MockRpcClient());
            var ex = await Assert.ThrowsAsync <WabiSabiProtocolException>(async() => await handler.RegisterOutputAsync(req));

            // The following assertion requires standardness to be checked before allowed script types
            Assert.Equal(WabiSabiProtocolErrorCode.NonStandardOutput, ex.ErrorCode);

            await arena.StopAsync(CancellationToken.None);
        }
コード例 #8
0
        public async Task SuccessAsync()
        {
            WabiSabiConfig cfg   = new();
            var            round = WabiSabiFactory.CreateRound(cfg);

            round.SetPhase(Phase.OutputRegistration);
            round.Alices.Add(WabiSabiFactory.CreateAlice());
            using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(cfg, round);

            await using ArenaRequestHandler handler = new(cfg, new Prison(), arena, new MockRpcClient());

            var req  = WabiSabiFactory.CreateOutputRegistrationRequest(round);
            var resp = await handler.RegisterOutputAsync(req, CancellationToken.None);

            Assert.NotEmpty(round.Bobs);
            Assert.NotNull(resp);
            Assert.NotNull(resp.AmountCredentials);
            Assert.NotNull(resp.VsizeCredentials);

            await arena.StopAsync(CancellationToken.None);
        }
コード例 #9
0
    public async Task ScriptNotAllowedAsync()
    {
        WabiSabiConfig cfg   = new();
        var            round = WabiSabiFactory.CreateRound(cfg);

        round.MaxVsizeAllocationPerAlice = 11 + 34 + MultipartyTransactionParameters.SharedOverhead;

        using Arena arena = await ArenaBuilder.From(cfg).CreateAndStartAsync(round);

        using Key key = new();

        round.SetPhase(Phase.OutputRegistration);
        round.Alices.Add(WabiSabiFactory.CreateAlice(Money.Coins(1), round));

        var req = WabiSabiFactory.CreateOutputRegistrationRequest(round, key.PubKey.GetAddress(ScriptPubKeyType.Legacy, Network.Main).ScriptPubKey);
        var ex  = await Assert.ThrowsAsync <WabiSabiProtocolException>(async() => await arena.RegisterOutputAsync(req, CancellationToken.None));

        Assert.Equal(WabiSabiProtocolErrorCode.ScriptNotAllowed, ex.ErrorCode);

        await arena.StopAsync(CancellationToken.None);
    }
コード例 #10
0
        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);
        }
コード例 #11
0
        public async Task WrongPhaseAsync()
        {
            MockArena      arena = new();
            WabiSabiConfig cfg   = new();
            var            round = WabiSabiFactory.CreateRound(cfg);

            arena.OnTryGetRound = _ => round;

            var req = new ConnectionConfirmationRequest(round.Id, Guid.NewGuid(), null !, null !, null !, null !);

            foreach (Phase phase in Enum.GetValues(typeof(Phase)))
            {
                if (phase != Phase.InputRegistration && phase != Phase.ConnectionConfirmation)
                {
                    round.Phase = phase;
                    await using PostRequestHandler handler = new(cfg, new Prison(), arena, new MockRpcClient());
                    var ex = Assert.Throws <WabiSabiProtocolException>(() => handler.ConfirmConnection(req));
                    Assert.Equal(WabiSabiProtocolErrorCode.WrongPhase, ex.ErrorCode);
                }
            }
        }
コード例 #12
0
        public async Task InputCanBeNotedAsync()
        {
            MockArena arena  = new();
            Prison    prison = new();
            var       pair   = WabiSabiFactory.CreateInputRoundSignaturePair();

            prison.Punish(pair.Input, Punishment.Noted, 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.ThrowsAnyAsync <Exception>(async() => await handler.RegisterInputAsync(req));

            if (ex is WabiSabiProtocolException wspex)
            {
                Assert.NotEqual(WabiSabiProtocolErrorCode.InputBanned, wspex.ErrorCode);
            }
        }
コード例 #13
0
        public async Task InputWhitelistedButBannedAsync()
        {
            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);

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

            arena.OnTryGetRound = _ => blameRound;

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

            Assert.Equal(WabiSabiProtocolErrorCode.InputBanned, ex.ErrorCode);
        }
コード例 #14
0
        public async Task ScriptNotAllowedAsync()
        {
            WabiSabiConfig cfg   = new();
            var            round = WabiSabiFactory.CreateRound(cfg);

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

            using Key key = new();

            round.SetPhase(Phase.OutputRegistration);
            round.Alices.Add(WabiSabiFactory.CreateAlice(Money.Coins(1)));

            var req = WabiSabiFactory.CreateOutputRegistrationRequest(round, key.PubKey.GetAddress(ScriptPubKeyType.Legacy, Network.Main).ScriptPubKey);

            await using ArenaRequestHandler handler = new(cfg, new Prison(), arena, new MockRpcClient());
            var ex = await Assert.ThrowsAsync <WabiSabiProtocolException>(async() => await handler.RegisterOutputAsync(req, CancellationToken.None));

            Assert.Equal(WabiSabiProtocolErrorCode.ScriptNotAllowed, ex.ErrorCode);

            await arena.StopAsync(CancellationToken.None);
        }
コード例 #15
0
        public async Task InputCantBeNotedAsync()
        {
            using Key key = new();
            var outpoint = BitcoinFactory.CreateOutPoint();

            WabiSabiConfig cfg   = new() { AllowNotedInputRegistration = false };
            var            round = WabiSabiFactory.CreateRound(cfg);

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

            arena.Prison.Punish(outpoint, Punishment.Noted, uint256.One);

            var arenaClient = WabiSabiFactory.CreateArenaClient(arena);

            var ex = await Assert.ThrowsAsync <WabiSabiProtocolException>(
                async() => await arenaClient.RegisterInputAsync(round.Id, outpoint, key, CancellationToken.None));

            Assert.Equal(WabiSabiProtocolErrorCode.InputBanned, ex.ErrorCode);

            await arena.StopAsync(CancellationToken.None);
        }
コード例 #16
0
        public async Task InputSpentAsync()
        {
            using Key key = new();
            WabiSabiConfig cfg   = new();
            var            round = WabiSabiFactory.CreateRound(cfg);

            var mockRpc = new Mock <IRPCClient>();

            mockRpc.Setup(rpc => rpc.GetTxOutAsync(It.IsAny <uint256>(), It.IsAny <int>(), It.IsAny <bool>()))
            .ReturnsAsync((NBitcoin.RPC.GetTxOutResponse?)null);

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

            var arenaClient = WabiSabiFactory.CreateArenaClient(arena);

            var ex = await Assert.ThrowsAsync <WabiSabiProtocolException>(
                async() => await arenaClient.RegisterInputAsync(round.Id, BitcoinFactory.CreateOutPoint(), key, CancellationToken.None));

            Assert.Equal(WabiSabiProtocolErrorCode.InputSpent, ex.ErrorCode);

            await arena.StopAsync(CancellationToken.None);
        }
コード例 #17
0
        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);
        }
コード例 #18
0
        public async Task InputWhitelistedButBannedAsync()
        {
            Prison prison = new();
            var    pair   = WabiSabiFactory.CreateInputRoundSignaturePair();

            prison.Punish(pair.Input, Punishment.Banned, Guid.NewGuid());
            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, prison, arena, WabiSabiFactory.CreateMockRpc());
            var req = WabiSabiFactory.CreateInputsRegistrationRequest(pair, blameRound);
            var ex  = await Assert.ThrowsAsync <WabiSabiProtocolException>(async() => await handler.RegisterInputAsync(req));

            Assert.Equal(WabiSabiProtocolErrorCode.InputBanned, ex.ErrorCode);

            await arena.StopAsync(CancellationToken.None);
        }
コード例 #19
0
        public async Task InputCanBeNotedAsync()
        {
            Prison prison = new();
            var    pair   = WabiSabiFactory.CreateInputRoundSignaturePair();

            prison.Punish(pair.Input, Punishment.Noted, Guid.NewGuid());
            WabiSabiConfig cfg   = new();
            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.ThrowsAnyAsync <Exception>(async() => await handler.RegisterInputAsync(req));

            if (ex is WabiSabiProtocolException wspex)
            {
                Assert.NotEqual(WabiSabiProtocolErrorCode.InputBanned, wspex.ErrorCode);
            }

            await arena.StopAsync(CancellationToken.None);
        }
コード例 #20
0
        public async Task InputWhitelistedAsync()
        {
            WabiSabiConfig cfg   = new();
            var            round = WabiSabiFactory.CreateRound(cfg);
            var            alice = WabiSabiFactory.CreateAlice(round);

            round.Alices.Add(alice);
            Round blameRound = WabiSabiFactory.CreateBlameRound(round, cfg);

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

            var req = WabiSabiFactory.CreateInputRegistrationRequest(prevout: alice.Coin.Outpoint, round: blameRound);

            var ex = await Assert.ThrowsAnyAsync <Exception>(async() => await arena.RegisterInputAsync(req, CancellationToken.None));

            if (ex is WabiSabiProtocolException wspex)
            {
                Assert.NotEqual(WabiSabiProtocolErrorCode.InputNotWhitelisted, wspex.ErrorCode);
            }

            await arena.StopAsync(CancellationToken.None);
        }
コード例 #21
0
        public async Task WrongPhaseAsync()
        {
            MockArena      arena = new();
            WabiSabiConfig cfg   = new();
            var            round = WabiSabiFactory.CreateRound(cfg);

            arena.OnTryGetRound = _ => round;

            var req = WabiSabiFactory.CreateInputsRegistrationRequest(round);

            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 = await Assert.ThrowsAsync <WabiSabiProtocolException>(async() => await handler.RegisterInputAsync(req));

                    Assert.Equal(WabiSabiProtocolErrorCode.WrongPhase, ex.ErrorCode);
                }
            }
        }
コード例 #22
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);
            }
        }
コード例 #23
0
        public async Task SuccessWithAliceUpdateIntraRoundAsync()
        {
            WabiSabiConfig cfg   = new();
            var            round = WabiSabiFactory.CreateRound(cfg);

            using Key key = new();
            var coin = WabiSabiFactory.CreateCoin(key);

            // Make sure an Alice have already been registered with the same input.
            var preAlice = WabiSabiFactory.CreateAlice(coin, WabiSabiFactory.CreateOwnershipProof(key), round);

            round.Alices.Add(preAlice);

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

            var arenaClient = WabiSabiFactory.CreateArenaClient(arena);
            var ex          = await Assert.ThrowsAsync <WabiSabiProtocolException>(async() => await arenaClient.RegisterInputAsync(round.Id, coin.Outpoint, key, CancellationToken.None).ConfigureAwait(false));

            Assert.Equal(WabiSabiProtocolErrorCode.AliceAlreadyRegistered, ex.ErrorCode);

            await arena.StopAsync(CancellationToken.None);
        }
コード例 #24
0
        public async Task InputImmatureAsync()
        {
            WabiSabiConfig cfg   = new();
            var            round = WabiSabiFactory.CreateRound(cfg);

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

            MockRpcClient rpc = new();

            var req = WabiSabiFactory.CreateInputsRegistrationRequest(round);

            for (int i = 1; i <= 100; i++)
            {
                rpc.OnGetTxOutAsync = (_, _, _) => new() { Confirmations = i, IsCoinBase = true };

                await using ArenaRequestHandler handler = new(cfg, new(), arena, rpc);
                var ex = await Assert.ThrowsAsync <WabiSabiProtocolException>(async() => await handler.RegisterInputAsync(req));

                Assert.Equal(WabiSabiProtocolErrorCode.InputImmature, ex.ErrorCode);
            }

            await arena.StopAsync(CancellationToken.None);
        }
コード例 #25
0
        public async Task ScriptNotAllowedAsync()
        {
            MockArena      arena = new();
            WabiSabiConfig cfg   = new();
            var            round = WabiSabiFactory.CreateRound(cfg);

            arena.OnTryGetRound = _ => round;
            MockRpcClient rpc = new();

            using Key key = new();

            rpc.OnGetTxOutAsync = (_, _, _) => new GetTxOutResponse
            {
                Confirmations = 1,
                TxOut         = new TxOut(Money.Coins(1), key.PubKey.GetScriptAddress(Network.Main))
            };

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

            Assert.Equal(WabiSabiProtocolErrorCode.ScriptNotAllowed, ex.ErrorCode);
        }
コード例 #26
0
        public async Task InputImmatureAsync()
        {
            MockArena      arena = new();
            WabiSabiConfig cfg   = new();
            var            round = WabiSabiFactory.CreateRound(cfg);

            arena.OnTryGetRound = _ => round;
            MockRpcClient rpc = new();

            var req = WabiSabiFactory.CreateInputsRegistrationRequest(round);

            for (int i = 1; i <= 100; i++)
            {
                rpc.OnGetTxOutAsync = (_, _, _) => new GetTxOutResponse {
                    Confirmations = i, IsCoinBase = true
                };

                await using PostRequestHandler handler = new(cfg, new Prison(), arena, rpc);
                var ex = await Assert.ThrowsAsync <WabiSabiProtocolException>(async() => await handler.RegisterInputAsync(req));

                Assert.Equal(WabiSabiProtocolErrorCode.InputImmature, ex.ErrorCode);
            }
        }
コード例 #27
0
        public async Task InputRegistrationTimedoutAsync()
        {
            WabiSabiConfig cfg   = new() { StandardInputRegistrationTimeout = TimeSpan.Zero };
            var            round = WabiSabiFactory.CreateRound(cfg);

            using Key key = new();
            var coin = WabiSabiFactory.CreateCoin(key);

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

            await arena.TriggerAndWaitRoundAsync(TimeSpan.FromSeconds(21));

            arena.Rounds.Add(round);

            var arenaClient = WabiSabiFactory.CreateArenaClient(arena);
            var ex          = await Assert.ThrowsAsync <WabiSabiProtocolException>(
                async() => await arenaClient.RegisterInputAsync(round.Id, coin.Outpoint, key, CancellationToken.None));

            Assert.Equal(WabiSabiProtocolErrorCode.WrongPhase, ex.ErrorCode);
            Assert.Equal(Phase.InputRegistration, round.Phase);

            await arena.StopAsync(CancellationToken.None);
        }
コード例 #28
0
        public async Task IncorrectRequestedAmountCredentialsAsync()
        {
            WabiSabiConfig cfg   = new();
            var            round = WabiSabiFactory.CreateRound(cfg);

            round.SetPhase(Phase.ConnectionConfirmation);
            var alice = WabiSabiFactory.CreateAlice(round);

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

            var incorrectAmountCredentials = WabiSabiFactory.CreateRealCredentialRequests(round, Money.Coins(3), null).amountRequest;
            var req = WabiSabiFactory.CreateConnectionConfirmationRequest(round) with {
                RealAmountCredentialRequests = incorrectAmountCredentials
            };

            var ex = await Assert.ThrowsAsync <WabiSabiProtocolException>(async() => await arena.ConfirmConnectionAsync(req, CancellationToken.None));

            Assert.Equal(WabiSabiProtocolErrorCode.IncorrectRequestedAmountCredentials, ex.ErrorCode);
            Assert.False(alice.ConfirmedConnection);

            await arena.StopAsync(CancellationToken.None);
        }
コード例 #29
0
        public async Task RemoveInputAsyncTestAsync()
        {
            var config = new WabiSabiConfig();
            var round  = WabiSabiFactory.CreateRound(config);

            round.SetPhase(Phase.ConnectionConfirmation);
            var fundingTx = BitcoinFactory.CreateSmartTransaction(ownOutputCount: 1);
            var coin      = fundingTx.WalletOutputs.First().Coin;
            var alice     = new Alice(coin, new OwnershipProof(), round, Guid.NewGuid());

            round.Alices.Add(alice);
            using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(config, round);

            await using var coordinator = new ArenaRequestHandler(config, new Prison(), arena, arena.Rpc);
            var wabiSabiApi = new WabiSabiController(coordinator);
            var apiClient   = new ArenaClient(null !, null !, wabiSabiApi);

            round.SetPhase(Phase.InputRegistration);

            await apiClient.RemoveInputAsync(round.Id, alice.Id, CancellationToken.None);

            Assert.Empty(round.Alices);
        }
コード例 #30
0
        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);
        }