Exemplo n.º 1
0
        private async Task RunOnAttestation(IServiceProvider testServiceProvider, BeaconState state, IStore store, Attestation attestation, bool expectValid)
        {
            MiscellaneousParameters miscellaneousParameters = testServiceProvider.GetService <IOptions <MiscellaneousParameters> >().Value;
            MaxOperationsPerBlock   maxOperationsPerBlock   = testServiceProvider.GetService <IOptions <MaxOperationsPerBlock> >().Value;

            IForkChoice forkChoice = testServiceProvider.GetService <IForkChoice>();

            if (!expectValid)
            {
                Should.Throw <Exception>(async() =>
                {
                    await forkChoice.OnAttestationAsync(store, attestation);
                });
                return;
            }

            BeaconStateAccessor beaconStateAccessor = testServiceProvider.GetService <BeaconStateAccessor>();
            IndexedAttestation  indexedAttestation  = beaconStateAccessor.GetIndexedAttestation(state, attestation);
            await forkChoice.OnAttestationAsync(store, attestation);

            IEnumerable <ValidatorIndex> attestingIndices = beaconStateAccessor.GetAttestingIndices(state, attestation.Data, attestation.AggregationBits);
            ValidatorIndex firstAttestingIndex            = attestingIndices.First();
            LatestMessage  latestMessage = (await store.GetLatestMessageAsync(firstAttestingIndex, true)) !;

            latestMessage.Epoch.ShouldBe(attestation.Data.Target.Epoch);
            latestMessage.Root.ShouldBe(attestation.Data.BeaconBlockRoot);
        }
        public static void SignAttestation(IServiceProvider testServiceProvider, BeaconState state, Attestation attestation)
        {
            BeaconStateAccessor beaconStateAccessor = testServiceProvider.GetService <BeaconStateAccessor>();

            IReadOnlyList <ValidatorIndex> participants = beaconStateAccessor.GetAttestingIndices(state, attestation.Data, attestation.AggregationBits);
            BlsSignature signature = SignAggregateAttestation(testServiceProvider, state, attestation.Data, participants);

            attestation.SetSignature(signature);
        }