コード例 #1
0
    public async Task WrongPhaseAsync()
    {
        WabiSabiConfig cfg   = new();
        Round          round = WabiSabiFactory.CreateRound(cfg);

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

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

        // Refresh the Arena States because of vsize manipulation.
        await arena.TriggerAndWaitRoundAsync(TimeSpan.FromSeconds(21));

        round.Alices.Add(WabiSabiFactory.CreateAlice(round));

        foreach (Phase phase in Enum.GetValues(typeof(Phase)))
        {
            if (phase != Phase.OutputRegistration)
            {
                var req = WabiSabiFactory.CreateOutputRegistrationRequest(round);
                round.SetPhase(phase);
                var ex = await Assert.ThrowsAsync <WrongPhaseException>(async() => await arena.RegisterOutputAsync(req, CancellationToken.None));

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

        await arena.StopAsync(CancellationToken.None);
    }
コード例 #2
0
    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();

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

        round.Alices.Add(WabiSabiFactory.CreateAlice(round));

        foreach (Phase phase in Enum.GetValues(typeof(Phase)))
        {
            if (phase != Phase.OutputRegistration)
            {
                var req = WabiSabiFactory.CreateOutputRegistrationRequest(round);
                round.SetPhase(phase);
                var ex = await Assert.ThrowsAsync <WrongPhaseException>(async() => await arena.RegisterOutputAsync(req, CancellationToken.None));

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

        await arena.StopAsync(CancellationToken.None);
    }
コード例 #3
0
        public async Task WrongPhaseAsync()
        {
            WabiSabiConfig cfg = new();

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

            await using ArenaRequestHandler handler = new(cfg, new Prison(), arena, new MockRpcClient());
            await arena.TriggerAndWaitRoundAsync(TimeSpan.FromSeconds(21)).ConfigureAwait(false);

            var round = arena.Rounds.First();

            round.Alices.Add(WabiSabiFactory.CreateAlice());

            foreach (Phase phase in Enum.GetValues(typeof(Phase)))
            {
                if (phase != Phase.OutputRegistration)
                {
                    var req = WabiSabiFactory.CreateOutputRegistrationRequest(round);
                    round.SetPhase(phase);
                    var ex = await Assert.ThrowsAsync <WabiSabiProtocolException>(async() => await handler.RegisterOutputAsync(req, CancellationToken.None));

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

            await arena.StopAsync(CancellationToken.None);
        }
コード例 #4
0
        public async Task RoundNotFoundAsync()
        {
            using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync();

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

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

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

        using Arena arena = await ArenaBuilder.Default.CreateAndStartAsync();

        var req = WabiSabiFactory.CreateOutputRegistrationRequest(nonExistingRound);
        var ex  = await Assert.ThrowsAsync <WabiSabiProtocolException>(async() => await arena.RegisterOutputAsync(req, CancellationToken.None));

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

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

        round.SetPhase(Phase.OutputRegistration);
        round.Alices.Add(WabiSabiFactory.CreateAlice(round));
        using Arena arena = await ArenaBuilder.From(cfg).CreateAndStartAsync(round);

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

        Assert.NotEmpty(round.Bobs);

        await arena.StopAsync(CancellationToken.None);
    }
コード例 #7
0
    public async Task NotEnoughFundsAsync()
    {
        WabiSabiConfig cfg   = new() { MinRegistrableAmount = Money.Coins(2) };
        var            round = WabiSabiFactory.CreateRound(cfg);

        round.SetPhase(Phase.OutputRegistration);
        round.Alices.Add(WabiSabiFactory.CreateAlice(Money.Coins(1), round));
        using Arena arena = await ArenaBuilder.From(cfg).CreateAndStartAsync(round);

        var req = WabiSabiFactory.CreateOutputRegistrationRequest(round);

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

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

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

        round.SetPhase(Phase.OutputRegistration);
        round.Alices.Add(WabiSabiFactory.CreateAlice(round));
        using Arena arena = await ArenaBuilder.From(cfg).CreateAndStartAsync(round);

        var req = WabiSabiFactory.CreateOutputRegistrationRequest(round, vsize: 30);

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

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

        await arena.StopAsync(CancellationToken.None);
    }
コード例 #9
0
        public async Task TooMuchFundsAsync()
        {
            WabiSabiConfig cfg   = new() { MaxRegistrableAmount = Money.Coins(1.999m) };           // TODO migrate to MultipartyTransactionParameters
            var            round = WabiSabiFactory.CreateRound(cfg);

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

            var req = WabiSabiFactory.CreateOutputRegistrationRequest(round);

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

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

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

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

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

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

            Assert.NotEmpty(round.Bobs);

            await arena.StopAsync(CancellationToken.None);
        }
コード例 #11
0
        public async Task ScriptNotAllowedAsync()
        {
            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 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));

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

            await arena.StopAsync(CancellationToken.None);
        }
コード例 #12
0
        public async Task IncorrectRequestedVsizeCredentialsAsync()
        {
            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, vsize: 30);

            var ex = await Assert.ThrowsAsync <WabiSabiProtocolException>(async() => await handler.RegisterOutputAsync(req));

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

            await arena.StopAsync(CancellationToken.None);
        }
コード例 #13
0
        public async Task TooMuchFundsAsync()
        {
            WabiSabiConfig cfg   = new() { MaxRegistrableAmount = Money.Coins(1.999m) };
            var            round = WabiSabiFactory.CreateRound(cfg);

            round.SetPhase(Phase.OutputRegistration);
            round.Alices.Add(WabiSabiFactory.CreateAlice(value: Money.Coins(2)));
            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 ex = await Assert.ThrowsAsync <WabiSabiProtocolException>(async() => await handler.RegisterOutputAsync(req));

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

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

        round.MaxVsizeAllocationPerAlice += 13;
        using Arena arena = await ArenaBuilder.From(cfg).CreateAndStartAsync(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);
    }
コード例 #15
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);
    }
コード例 #16
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);
        }