public void Wiggle_has_no_min_value() { Queue <int> randoms = new Queue <int>(new List <int> { Clique.WiggleTime / 2, Clique.WiggleTime, Clique.WiggleTime * 2, Clique.WiggleTime * 3 }); ICryptoRandom cryptoRandom = Substitute.For <ICryptoRandom>(); cryptoRandom.NextInt(Arg.Any <int>()).Returns(ci => randoms.Dequeue()); Snapshot snapshot = new Snapshot(1, Keccak.Zero, new SortedList <Address, long>(AddressComparer.Instance) { { TestItem.AddressA, 1 }, { TestItem.AddressB, 2 }, { TestItem.AddressC, 3 }, { TestItem.AddressD, 4 } }); ISnapshotManager snapshotManager = Substitute.For <ISnapshotManager>(); snapshotManager.GetOrCreateSnapshot(Arg.Any <long>(), Arg.Any <Keccak>()).Returns(snapshot); WiggleRandomizer randomizer = new WiggleRandomizer(cryptoRandom, snapshotManager); BlockHeader header1 = Build.A.BlockHeader.WithNumber(1).TestObject; BlockHeader header2 = Build.A.BlockHeader.WithNumber(2).TestObject; BlockHeader header3 = Build.A.BlockHeader.WithNumber(3).TestObject; int wiggle = randomizer.WiggleFor(header1); Assert.AreEqual(Clique.WiggleTime / 2, wiggle); wiggle = randomizer.WiggleFor(header2); Assert.AreEqual(Clique.WiggleTime, wiggle); wiggle = randomizer.WiggleFor(header3); Assert.AreEqual(Clique.WiggleTime * 2, wiggle); }
public void Wiggle_is_fine() { Queue <int> randoms = new Queue <int>(new List <int> { 100, 600, 1000, 2000, 50 }); ICryptoRandom cryptoRandom = Substitute.For <ICryptoRandom>(); cryptoRandom.NextInt(Arg.Any <int>()).Returns(ci => randoms.Dequeue()); Snapshot snapshot = new Snapshot(1, Keccak.Zero, new SortedList <Address, long>(AddressComparer.Instance) { { TestItem.AddressA, 1 }, { TestItem.AddressB, 2 }, { TestItem.AddressC, 3 }, { TestItem.AddressD, 4 } }); ISnapshotManager snapshotManager = Substitute.For <ISnapshotManager>(); snapshotManager.GetOrCreateSnapshot(Arg.Any <long>(), Arg.Any <Keccak>()).Returns(snapshot); WiggleRandomizer randomizer = new WiggleRandomizer(cryptoRandom, snapshotManager); BlockHeader header1 = Build.A.BlockHeader.WithNumber(1).TestObject; for (int i = 0; i < 5; i++) { Assert.AreEqual(100, randomizer.WiggleFor(header1)); } }
public void Returns_zero_for_in_turn_blocks() { Queue <int> randoms = new Queue <int>(new List <int> { Consensus.Clique.Clique.WiggleTime / 2, Consensus.Clique.Clique.WiggleTime, Consensus.Clique.Clique.WiggleTime * 2, Consensus.Clique.Clique.WiggleTime * 3 }); ICryptoRandom cryptoRandom = Substitute.For <ICryptoRandom>(); cryptoRandom.NextInt(Arg.Any <int>()).Returns(ci => randoms.Dequeue()); Snapshot snapshot = new Snapshot(1, Keccak.Zero, new SortedList <Address, long>(AddressComparer.Instance) { { TestItem.AddressA, 1 }, { TestItem.AddressB, 2 }, { TestItem.AddressC, 3 }, { TestItem.AddressD, 4 } }); ISnapshotManager snapshotManager = Substitute.For <ISnapshotManager>(); snapshotManager.GetOrCreateSnapshot(Arg.Any <long>(), Arg.Any <Keccak>()).Returns(snapshot); WiggleRandomizer randomizer = new WiggleRandomizer(cryptoRandom, snapshotManager); BlockHeader header1 = Build.A.BlockHeader.WithNumber(1).WithDifficulty(Consensus.Clique.Clique.DifficultyInTurn).TestObject; int wiggle = randomizer.WiggleFor(header1); Assert.AreEqual(0, wiggle); }