use of tech.pegasys.teku.spec.datastructures.util.BeaconBlockBodyLists in project teku by ConsenSys.
the class AbstractBeaconBlockBodyTest method setUpBaseClass.
protected void setUpBaseClass(final SpecMilestone milestone, Runnable additionalSetup) {
spec = TestSpecFactory.createMinimal(milestone);
dataStructureUtil = new DataStructureUtil(spec);
BeaconBlockBodyLists blockBodyLists = BeaconBlockBodyLists.ofSpec(spec);
voluntaryExits = blockBodyLists.createVoluntaryExits(dataStructureUtil.randomSignedVoluntaryExit(), dataStructureUtil.randomSignedVoluntaryExit(), dataStructureUtil.randomSignedVoluntaryExit());
deposits = blockBodyLists.createDeposits(dataStructureUtil.randomDeposits(2).toArray(new Deposit[0]));
attestations = blockBodyLists.createAttestations(dataStructureUtil.randomAttestation(), dataStructureUtil.randomAttestation(), dataStructureUtil.randomAttestation());
attesterSlashings = blockBodyLists.createAttesterSlashings(dataStructureUtil.randomAttesterSlashing());
proposerSlashings = blockBodyLists.createProposerSlashings(dataStructureUtil.randomProposerSlashing(), dataStructureUtil.randomProposerSlashing(), dataStructureUtil.randomProposerSlashing());
graffiti = dataStructureUtil.randomBytes32();
eth1Data = dataStructureUtil.randomEth1Data();
randaoReveal = dataStructureUtil.randomSignature();
additionalSetup.run();
defaultBlockBody = createDefaultBlockBody();
blockBodySchema = defaultBlockBody.getSchema();
}
use of tech.pegasys.teku.spec.datastructures.util.BeaconBlockBodyLists in project teku by ConsenSys.
the class BlockFactoryTest method assertBlockCreated.
private BeaconBlock assertBlockCreated(final int blockSlot, final Spec spec) throws EpochProcessingException, SlotProcessingException, StateTransitionException {
final UInt64 newSlot = UInt64.valueOf(blockSlot);
final DataStructureUtil dataStructureUtil = new DataStructureUtil(spec);
final BeaconBlockBodyLists blockBodyLists = BeaconBlockBodyLists.ofSpec(spec);
final RecentChainData recentChainData = MemoryOnlyRecentChainData.create(spec);
final BeaconChainUtil beaconChainUtil = BeaconChainUtil.create(spec, 1, recentChainData);
final SszList<Deposit> deposits = blockBodyLists.createDeposits();
final SszList<Attestation> attestations = blockBodyLists.createAttestations();
final SszList<AttesterSlashing> attesterSlashings = blockBodyLists.createAttesterSlashings();
final SszList<ProposerSlashing> proposerSlashings = blockBodyLists.createProposerSlashings();
final SszList<SignedVoluntaryExit> voluntaryExits = blockBodyLists.createVoluntaryExits();
if (spec.getGenesisSpec().getMilestone().isGreaterThanOrEqualTo(SpecMilestone.BELLATRIX)) {
executionPayload = SchemaDefinitionsBellatrix.required(spec.getGenesisSpec().getSchemaDefinitions()).getExecutionPayloadSchema().getDefault();
} else {
executionPayload = null;
}
final Bytes32 graffiti = dataStructureUtil.randomBytes32();
final BlockFactory blockFactory = new BlockFactory(spec, new BlockOperationSelectorFactory(spec, attestationsPool, attesterSlashingPool, proposerSlashingPool, voluntaryExitPool, syncCommitteeContributionPool, depositProvider, eth1DataCache, graffiti, forkChoiceNotifier, executionEngine));
when(depositProvider.getDeposits(any(), any())).thenReturn(deposits);
when(attestationsPool.getAttestationsForBlock(any(), any(), any())).thenReturn(attestations);
when(attesterSlashingPool.getItemsForBlock(any(), any(), any())).thenReturn(attesterSlashings);
when(proposerSlashingPool.getItemsForBlock(any(), any(), any())).thenReturn(proposerSlashings);
when(voluntaryExitPool.getItemsForBlock(any(), any(), any())).thenReturn(voluntaryExits);
when(eth1DataCache.getEth1Vote(any())).thenReturn(ETH1_DATA);
when(forkChoiceNotifier.getPayloadId(any(), any())).thenReturn(SafeFuture.completedFuture(Optional.of(Bytes8.fromHexStringLenient("0x0"))));
when(executionEngine.getPayload(any(), any())).thenReturn(SafeFuture.completedFuture(executionPayload));
beaconChainUtil.initializeStorage();
final BLSSignature randaoReveal = dataStructureUtil.randomSignature();
final Bytes32 bestBlockRoot = recentChainData.getBestBlockRoot().orElseThrow();
final BeaconState blockSlotState = recentChainData.retrieveStateAtSlot(new SlotAndBlockRoot(UInt64.valueOf(blockSlot), bestBlockRoot)).join().orElseThrow();
when(syncCommitteeContributionPool.createSyncAggregateForBlock(newSlot, bestBlockRoot)).thenAnswer(invocation -> createEmptySyncAggregate(spec));
final BeaconBlock block = blockFactory.createUnsignedBlock(blockSlotState, newSlot, randaoReveal, Optional.empty());
assertThat(block).isNotNull();
assertThat(block.getSlot()).isEqualTo(newSlot);
assertThat(block.getBody().getRandaoReveal()).isEqualTo(randaoReveal);
assertThat(block.getBody().getEth1Data()).isEqualTo(ETH1_DATA);
assertThat(block.getBody().getDeposits()).isEqualTo(deposits);
assertThat(block.getBody().getAttestations()).isEqualTo(attestations);
assertThat(block.getBody().getAttesterSlashings()).isEqualTo(attesterSlashings);
assertThat(block.getBody().getProposerSlashings()).isEqualTo(proposerSlashings);
assertThat(block.getBody().getVoluntaryExits()).isEqualTo(voluntaryExits);
assertThat(block.getBody().getGraffiti()).isEqualTo(graffiti);
return block;
}
Aggregations