private void RunProcessRewardsAndPenalties(IServiceProvider testServiceProvider, BeaconState state)
 {
     TestProcessUtility.RunEpochProcessingWith(testServiceProvider, state, TestProcessStep.ProcessRewardsAndPenalties);
 }
Exemplo n.º 2
0
 private void RunProcessRegistryUpdates(IServiceProvider testServiceProvider, BeaconState state)
 {
     TestProcessUtility.RunEpochProcessingWith(testServiceProvider, state, TestProcessStep.ProcessRegistryUpdates);
 }
Exemplo n.º 3
0
        public void EffectiveBalanceHysteresis()
        {
            // Arrange
            var testServiceProvider = TestSystem.BuildTestServiceProvider();
            var state = TestState.PrepareTestState(testServiceProvider);

            //# Prepare state up to the final-updates.
            //# Then overwrite the balances, we only want to focus to be on the hysteresis based changes.
            TestProcessUtility.RunEpochProcessingTo(testServiceProvider, state, TestProcessStep.ProcessFinalUpdates);

            var gweiValues = testServiceProvider.GetService <IOptions <GweiValues> >().Value;

            var beaconChainUtility    = testServiceProvider.GetService <BeaconChainUtility>();
            var beaconStateAccessor   = testServiceProvider.GetService <BeaconStateAccessor>();
            var beaconStateTransition = testServiceProvider.GetService <BeaconStateTransition>();

            // Set some edge cases for balances
            var maximum       = gweiValues.MaximumEffectiveBalance;
            var minimum       = gweiValues.EjectionBalance;
            var increment     = gweiValues.EffectiveBalanceIncrement;
            var halfIncrement = increment / 2;
            var one           = new Gwei(1);

            var testCases = new[] {
                new EffectiveBalanceCase(maximum, maximum, maximum, "as-is"),
                new EffectiveBalanceCase(maximum, maximum - one, maximum - increment, "round down, step lower"),
                new EffectiveBalanceCase(maximum, maximum + one, maximum, "round down"),
                new EffectiveBalanceCase(maximum, maximum - increment, maximum - increment, "exactly 1 step lower"),
                new EffectiveBalanceCase(maximum, maximum - increment - one, maximum - (increment * 2), "just 1 over 1 step lower"),
                new EffectiveBalanceCase(maximum, maximum - increment + one, maximum - increment, "close to 1 step lower"),
                new EffectiveBalanceCase(minimum, minimum + (halfIncrement * 3), minimum, "bigger balance, but not high enough"),
                new EffectiveBalanceCase(minimum, minimum + (halfIncrement * 3) + one, minimum + increment, "bigger balance, high enough, but small step"),
                new EffectiveBalanceCase(minimum, minimum + (halfIncrement * 4) - one, minimum + increment, "bigger balance, high enough, close to double step"),
                new EffectiveBalanceCase(minimum, minimum + (halfIncrement * 4), minimum + (increment * 2), "exact two step balance increment"),
                new EffectiveBalanceCase(minimum, minimum + (halfIncrement * 4) + one, minimum + (increment * 2), "over two steps, round down"),
            };

            var currentEpoch = beaconStateAccessor.GetCurrentEpoch(state);

            for (var index = 0; index < testCases.Length; index++)
            {
                var validator = state.Validators[index];
                var isActive  = beaconChainUtility.IsActiveValidator(validator, currentEpoch);
                isActive.ShouldBeTrue();

                var testCase = testCases[index];
                validator.SetEffectiveBalance(testCase.PreEffective);
                var validatorIndex = new ValidatorIndex((ulong)index);
                state.SetBalance(validatorIndex, testCase.Balance);
            }

            // Act
            beaconStateTransition.ProcessFinalUpdates(state);

            // Assert
            for (var index = 0; index < testCases.Length; index++)
            {
                var testCase  = testCases[index];
                var validator = state.Validators[index];
                validator.EffectiveBalance.ShouldBe(testCase.PostEffective, testCase.Name);
            }
        }