public void GenesisEpochFullAttestationsNoRewards() { // Arrange IServiceProvider testServiceProvider = TestSystem.BuildTestServiceProvider(); BeaconState state = TestState.PrepareTestState(testServiceProvider); InitialValues initialValues = testServiceProvider.GetService <IOptions <InitialValues> >().Value; TimeParameters timeParameters = testServiceProvider.GetService <IOptions <TimeParameters> >().Value; BeaconChainUtility beaconChainUtility = testServiceProvider.GetService <BeaconChainUtility>(); var attestations = new List <Attestation>(); for (Slot slot = Slot.Zero; slot < timeParameters.SlotsPerEpoch - new Slot(1); slot += new Slot(1)) { // create an attestation for each slot if (slot < timeParameters.SlotsPerEpoch) { Attestation attestation = TestAttestation.GetValidAttestation(testServiceProvider, state, slot, CommitteeIndex.None, signed: true); attestations.Add(attestation); } // fill each created slot in state after inclusion delay if (slot >= timeParameters.MinimumAttestationInclusionDelay) { Slot index = slot - timeParameters.MinimumAttestationInclusionDelay; Attestation includeAttestation = attestations[(int)(ulong)index]; TestAttestation.AddAttestationsToState(testServiceProvider, state, new[] { includeAttestation }, state.Slot); } TestState.NextSlot(testServiceProvider, state); } // ensure has not cross the epoch boundary Epoch stateEpoch = beaconChainUtility.ComputeEpochAtSlot(state.Slot); stateEpoch.ShouldBe(initialValues.GenesisEpoch); BeaconState preState = BeaconState.Clone(state); // Act RunProcessRewardsAndPenalties(testServiceProvider, state); // Assert for (int index = 0; index < preState.Validators.Count; index++) { state.Balances[index].ShouldBe(preState.Balances[index], $"Balance {index}"); } }
private static IList <Attestation> PrepareStateWithFullAttestations(IServiceProvider testServiceProvider, BeaconState state) { TimeParameters timeParameters = testServiceProvider.GetService <IOptions <TimeParameters> >().Value; InitialValues initialValues = testServiceProvider.GetService <IOptions <InitialValues> >().Value; BeaconChainUtility beaconChainUtility = testServiceProvider.GetService <BeaconChainUtility>(); var attestations = new List <Attestation>(); ulong maxSlot = timeParameters.SlotsPerEpoch + timeParameters.MinimumAttestationInclusionDelay; for (Slot slot = Slot.Zero; slot < maxSlot; slot += new Slot(1)) { // create an attestation for each slot in epoch if (slot < timeParameters.SlotsPerEpoch) { Attestation attestation = TestAttestation.GetValidAttestation(testServiceProvider, state, Slot.None, CommitteeIndex.None, signed: true); attestations.Add(attestation); } // fill each created slot in state after inclusion delay if (slot >= timeParameters.MinimumAttestationInclusionDelay) { Slot index = slot - timeParameters.MinimumAttestationInclusionDelay; Attestation includeAttestation = attestations[(int)(ulong)index]; TestAttestation.AddAttestationsToState(testServiceProvider, state, new[] { includeAttestation }, state.Slot); } TestState.NextSlot(testServiceProvider, state); } Epoch stateEpoch = beaconChainUtility.ComputeEpochAtSlot(state.Slot); stateEpoch.ShouldBe(initialValues.GenesisEpoch + Epoch.One); state.PreviousEpochAttestations.Count.ShouldBe((int)timeParameters.SlotsPerEpoch); return(attestations); }