use of tech.pegasys.teku.spec.util.DataStructureUtil in project teku by ConsenSys.
the class ChainDataProviderTest method setupAltairState.
private ChainDataProvider setupAltairState() {
final Spec altair = TestSpecFactory.createMinimalAltair();
final DataStructureUtil dataStructureUtil = new DataStructureUtil(altair);
final ChainDataProvider provider = new ChainDataProvider(altair, recentChainData, mockCombinedChainDataClient);
final SszList<tech.pegasys.teku.spec.datastructures.state.Validator> validators = dataStructureUtil.randomSszList(dataStructureUtil.getBeaconStateSchema().getValidatorsSchema(), 16, dataStructureUtil::randomValidator);
final SyncCommittee currentSyncCommittee = dataStructureUtil.randomSyncCommittee(validators);
final tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState internalState = dataStructureUtil.stateBuilderAltair().validators(validators).currentSyncCommittee(currentSyncCommittee).build();
final tech.pegasys.teku.storage.client.ChainHead chainHead = tech.pegasys.teku.storage.client.ChainHead.create(StateAndBlockSummary.create(internalState));
when(mockCombinedChainDataClient.getChainHead()).thenReturn(Optional.of(chainHead));
return provider;
}
use of tech.pegasys.teku.spec.util.DataStructureUtil 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.util.DataStructureUtil in project teku by ConsenSys.
the class BeaconBlocksByRootIntegrationTest method largeBlockSequence.
private List<SignedBeaconBlock> largeBlockSequence(final int count) {
DataStructureUtil dataStructureUtil = new DataStructureUtil();
final SignedBeaconBlock parent = peerStorage.chainBuilder().getLatestBlockAndState().getBlock();
List<SignedBlockAndState> newBlocks = dataStructureUtil.randomSignedBlockAndStateSequence(parent, count, true);
newBlocks.forEach(peerStorage.chainUpdater()::saveBlock);
return newBlocks.stream().map(SignedBlockAndState::getBlock).collect(Collectors.toList());
}
use of tech.pegasys.teku.spec.util.DataStructureUtil in project teku by ConsenSys.
the class AttestationGossipManagerTest method onNewAttestation_afterMatchingAssignment.
@Test
public void onNewAttestation_afterMatchingAssignment() {
// Create a new DataStructureUtil so that generated attestations are not subject to change
// when access to the global DataStructureUtil changes
DataStructureUtil dataStructureUtil = new DataStructureUtil(spec);
final Attestation attestation = dataStructureUtil.randomAttestation(3);
final Attestation attestation2 = spec.getGenesisSchemaDefinitions().getAttestationSchema().create(dataStructureUtil.randomBitlist(), dataStructureUtil.randomAttestationData(UInt64.valueOf(13)), dataStructureUtil.randomSignature());
final int subnetId = computeSubnetId(attestation);
// Sanity check the attestations are for the same subnet
assertThat(computeSubnetId(attestation2)).isEqualTo(subnetId);
// Setup committee assignment
attestationGossipManager.subscribeToSubnetId(subnetId);
// Post new attestation
final Bytes serialized = gossipEncoding.encode(attestation);
attestationGossipManager.onNewAttestation(ValidateableAttestation.from(spec, attestation));
verify(gossipNetwork).gossip(getSubnetTopic(subnetId), serialized);
// We should process attestations for different committees on the same subnet
final Bytes serialized2 = gossipEncoding.encode(attestation2);
attestationGossipManager.onNewAttestation(ValidateableAttestation.from(spec, attestation2));
verify(gossipNetwork).gossip(getSubnetTopic(subnetId), serialized2);
}
use of tech.pegasys.teku.spec.util.DataStructureUtil in project teku by ConsenSys.
the class WeakSubjectivityInitializerTest method validateInitialAnchor_forGenesisAfterGenesisSlot.
@Test
public void validateInitialAnchor_forGenesisAfterGenesisSlot() {
final DataStructureUtil dataStructureUtil = new DataStructureUtil(spec);
final AnchorPoint anchor = dataStructureUtil.randomAnchorPoint(0);
// Should not throw
initializer.validateInitialAnchor(anchor, UInt64.valueOf(10), spec);
}
Aggregations