public void ActivationQueueSorting() { // Arrange IServiceProvider testServiceProvider = TestSystem.BuildTestServiceProvider(); BeaconState state = TestState.PrepareTestState(testServiceProvider); ChainConstants chainConstants = testServiceProvider.GetService <ChainConstants>(); BeaconStateAccessor beaconStateAccessor = testServiceProvider.GetService <BeaconStateAccessor>(); int mockActivations = 10; Epoch currentEpoch = beaconStateAccessor.GetCurrentEpoch(state); for (int index = 0; index < mockActivations; index++) { MockDeposit(testServiceProvider, state, index); state.Validators[index].SetEligible(currentEpoch + Epoch.One); } // eligibility must be finalized state.SetFinalizedCheckpoint(new Checkpoint(currentEpoch + new Epoch(2), Root.Zero)); // give the last priority over the others state.Validators[mockActivations - 1].SetEligible(currentEpoch); // make sure we are hitting the churn int churnLimit = (int)beaconStateAccessor.GetValidatorChurnLimit(state); mockActivations.ShouldBeGreaterThan(churnLimit); // Act RunProcessRegistryUpdates(testServiceProvider, state); // Assert //# the first got in as second state.Validators[0].ActivationEpoch.ShouldNotBe(chainConstants.FarFutureEpoch); //# the prioritized got in as first state.Validators[mockActivations - 1].ActivationEpoch.ShouldNotBe(chainConstants.FarFutureEpoch); //# the second last is at the end of the queue, and did not make the churn, //# hence is not assigned an activation_epoch yet. state.Validators[mockActivations - 2].ActivationEpoch.ShouldBe(chainConstants.FarFutureEpoch); //# the one at churn_limit - 1 did not make it, it was out-prioritized state.Validators[churnLimit - 1].ActivationEpoch.ShouldBe(chainConstants.FarFutureEpoch); //# but the the one in front of the above did state.Validators[churnLimit - 2].ActivationEpoch.ShouldNotBe(chainConstants.FarFutureEpoch); }