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 _)); }
private static Prison DeserializePrison(string prisonFilePath) { IoHelpers.EnsureContainingDirectoryExists(prisonFilePath); var inmates = new List <Inmate>(); if (File.Exists(prisonFilePath)) { try { foreach (var inmate in File.ReadAllLines(prisonFilePath).Select(Inmate.FromString)) { inmates.Add(inmate); } } catch (Exception ex) { Logger.LogError(ex); Logger.LogWarning($"Deleting {prisonFilePath}"); File.Delete(prisonFilePath); } } var prison = new Prison(inmates); var(noted, banned) = prison.CountInmates(); if (noted > 0) { Logger.LogInfo($"{noted} noted UTXOs are found in prison."); } if (banned > 0) { Logger.LogInfo($"{banned} banned UTXOs are found in prison."); } return(prison); }
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 _)); }