Exemplo n.º 1
0
    public void CanReleaseAfterLongBan()
    {
        var p    = new Prison();
        var id1  = BitcoinFactory.CreateUint256();
        var utxo = BitcoinFactory.CreateOutPoint();
        var past = DateTimeOffset.UtcNow - TimeSpan.FromDays(40);

        p.Punish(new Inmate(utxo, Punishment.Banned, past, id1, IsLongBan: true));

        Assert.Single(p.GetInmates());

        p.ReleaseEligibleInmates(normalBanPeriod: TimeSpan.FromSeconds(1), longBanPeriod: TimeSpan.FromDays(31));

        Assert.Empty(p.GetInmates());
    }
Exemplo n.º 2
0
        public void EmptyPrison()
        {
            var p = new Prison();

            Assert.Empty(p.GetInmates());
            Assert.Equal(0, p.CountInmates().noted);
            Assert.Equal(0, p.CountInmates().banned);
            Assert.False(p.TryGet(BitcoinFactory.CreateOutPoint(), out _));
        }
Exemplo n.º 3
0
        public void PrisonOperations()
        {
            var p = new Prison();

            var id1 = BitcoinFactory.CreateUint256();

            var utxo = BitcoinFactory.CreateOutPoint();

            p.Punish(utxo, Punishment.Noted, id1);
            Assert.Single(p.GetInmates());
            Assert.Equal(1, p.CountInmates().noted);
            Assert.Equal(0, p.CountInmates().banned);
            Assert.True(p.TryGet(utxo, out _));

            // Updates to banned.
            p.Punish(utxo, Punishment.Banned, id1);
            Assert.Single(p.GetInmates());
            Assert.Equal(0, p.CountInmates().noted);
            Assert.Equal(1, p.CountInmates().banned);
            Assert.True(p.TryGet(utxo, out _));

            // Removes.
            Assert.True(p.TryRelease(utxo, out _));
            Assert.Empty(p.GetInmates());

            // Noting twice flips to banned.
            p.Punish(utxo, Punishment.Noted, id1);
            p.Punish(utxo, Punishment.Noted, id1);
            Assert.Single(p.GetInmates());
            Assert.Equal(0, p.CountInmates().noted);
            Assert.Equal(1, p.CountInmates().banned);
            Assert.True(p.TryGet(utxo, out _));
            Assert.True(p.TryRelease(utxo, out _));

            // Updates round.
            var id2 = BitcoinFactory.CreateUint256();

            p.Punish(utxo, Punishment.Banned, id1);
            p.Punish(utxo, Punishment.Banned, id2);
            Assert.Single(p.GetInmates());
            Assert.True(p.TryGet(utxo, out var inmate));
            Assert.Equal(id2, inmate !.LastDisruptedRoundId);
            Assert.True(p.TryRelease(utxo, out _));
        }
Exemplo n.º 4
0
 public async Task SerializePrisonAsync()
 {
     IoHelpers.EnsureContainingDirectoryExists(PrisonFilePath);
     await File.WriteAllLinesAsync(PrisonFilePath, Prison.GetInmates().Select(x => x.ToString())).ConfigureAwait(false);
 }