Search in sources :

Example 6 with DataStructureUtil

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;
}
Also used : SyncCommittee(tech.pegasys.teku.spec.datastructures.state.SyncCommittee) Spec(tech.pegasys.teku.spec.Spec) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil)

Example 7 with DataStructureUtil

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();
}
Also used : BeaconBlockBodyLists(tech.pegasys.teku.spec.datastructures.util.BeaconBlockBodyLists) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil)

Example 8 with DataStructureUtil

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());
}
Also used : SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil)

Example 9 with DataStructureUtil

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);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) ValidateableAttestation(tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil) Test(org.junit.jupiter.api.Test)

Example 10 with DataStructureUtil

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);
}
Also used : AnchorPoint(tech.pegasys.teku.spec.datastructures.state.AnchorPoint) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil) Test(org.junit.jupiter.api.Test)

Aggregations

DataStructureUtil (tech.pegasys.teku.spec.util.DataStructureUtil)45 Test (org.junit.jupiter.api.Test)33 Spec (tech.pegasys.teku.spec.Spec)11 Checkpoint (tech.pegasys.teku.spec.datastructures.state.Checkpoint)8 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)7 Bytes32 (org.apache.tuweni.bytes.Bytes32)6 List (java.util.List)4 Bytes (org.apache.tuweni.bytes.Bytes)4 StubMetricsSystem (tech.pegasys.teku.infrastructure.metrics.StubMetricsSystem)4 Attestation (tech.pegasys.teku.spec.datastructures.operations.Attestation)4 AnchorPoint (tech.pegasys.teku.spec.datastructures.state.AnchorPoint)4 Response (okhttp3.Response)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 PostDataFailureResponse (tech.pegasys.teku.api.response.v1.beacon.PostDataFailureResponse)3 BLSSignature (tech.pegasys.teku.api.schema.BLSSignature)3 SyncCommitteeMessage (tech.pegasys.teku.api.schema.altair.SyncCommitteeMessage)3 AbstractDataBackedRestAPIIntegrationTest (tech.pegasys.teku.beaconrestapi.AbstractDataBackedRestAPIIntegrationTest)3 BLSSignature (tech.pegasys.teku.bls.BLSSignature)3 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)3 WeakSubjectivityConfig (tech.pegasys.teku.weaksubjectivity.config.WeakSubjectivityConfig)3