Search in sources :

Example 1 with DataStructureUtil

use of tech.pegasys.teku.spec.util.DataStructureUtil in project teku by ConsenSys.

the class DepositProviderTest method setup.

void setup(final int maxDeposits) {
    when(state.getSlot()).thenReturn(UInt64.valueOf(1234));
    SpecConfig specConfig = SpecConfigLoader.loadConfig("minimal", b -> b.maxDeposits(maxDeposits));
    spec = TestSpecFactory.createPhase0(specConfig);
    depositUtil = new DepositUtil(spec);
    dataStructureUtil = new DataStructureUtil(spec);
    depositProvider = new DepositProvider(new StubMetricsSystem(), recentChainData, eth1DataCache, spec);
    depositMerkleTree = new OptimizedMerkleTree(spec.getGenesisSpecConfig().getDepositContractTreeDepth());
    mockStateEth1DataVotes();
    createDepositEvents(40);
    randomEth1Data = dataStructureUtil.randomEth1Data();
}
Also used : DepositUtil(tech.pegasys.teku.spec.datastructures.util.DepositUtil) OptimizedMerkleTree(tech.pegasys.teku.spec.datastructures.util.OptimizedMerkleTree) StubMetricsSystem(tech.pegasys.teku.infrastructure.metrics.StubMetricsSystem) SpecConfig(tech.pegasys.teku.spec.config.SpecConfig) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil)

Example 2 with DataStructureUtil

use of tech.pegasys.teku.spec.util.DataStructureUtil in project teku by ConsenSys.

the class TerminalPowBlockMonitorTest method setUpCommon.

private void setUpCommon(Consumer<BellatrixBuilder> bellatrixBuilder) {
    spec = TestSpecFactory.createBellatrix(SpecConfigLoader.loadConfig("minimal", phase0Builder -> phase0Builder.altairBuilder(altairBuilder -> altairBuilder.altairForkEpoch(UInt64.ZERO)).bellatrixBuilder(bellatrixBuilder)));
    dataStructureUtil = new DataStructureUtil(spec);
    storageSystem = InMemoryStorageSystemBuilder.buildDefault(spec);
    storageSystem.chainUpdater().initializeGenesis(false);
    recentChainData = storageSystem.recentChainData();
    localTransitionConfiguration = new TransitionConfiguration(spec.getGenesisSpecConfig().toVersionBellatrix().orElseThrow().getTerminalTotalDifficulty(), spec.getGenesisSpecConfig().toVersionBellatrix().orElseThrow().getTerminalBlockHash(), UInt64.ZERO);
    terminalPowBlockMonitor = new TerminalPowBlockMonitor(executionEngine, spec, recentChainData, forkChoiceNotifier, asyncRunner, eventLogger);
    terminalPowBlockMonitor.onNodeSyncStateChanged(true);
}
Also used : TransitionConfiguration(tech.pegasys.teku.spec.executionengine.TransitionConfiguration) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil)

Example 3 with DataStructureUtil

use of tech.pegasys.teku.spec.util.DataStructureUtil in project teku by ConsenSys.

the class RpcResponseDecoderTest method beaconState.

private BeaconState beaconState(final boolean usePhase0State) {
    final Spec spec = usePhase0State ? TestSpecFactory.createMinimalPhase0() : TestSpecFactory.createMinimalAltair();
    final DataStructureUtil dataStructureUtil = new DataStructureUtil(spec);
    return usePhase0State ? dataStructureUtil.stateBuilderPhase0().build() : dataStructureUtil.stateBuilderAltair().build();
}
Also used : Spec(tech.pegasys.teku.spec.Spec) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil)

Example 4 with DataStructureUtil

use of tech.pegasys.teku.spec.util.DataStructureUtil in project teku by ConsenSys.

the class NodeRecordConverterTest method shouldConvertEnrForkId.

@Test
public void shouldConvertEnrForkId() {
    EnrForkId enrForkId = new DataStructureUtil().randomEnrForkId();
    Bytes encodedForkId = enrForkId.sszSerialize();
    final Optional<DiscoveryPeer> result = convertNodeRecordWithFields(new EnrField(EnrField.IP_V6, IPV6_LOCALHOST), new EnrField(EnrField.TCP_V6, 1234), new EnrField(ETH2_ENR_FIELD, encodedForkId));
    assertThat(result).contains(new DiscoveryPeer(PUB_KEY, new InetSocketAddress("::1", 1234), Optional.of(enrForkId), ATTNETS, SYNCNETS));
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) DiscoveryPeer(tech.pegasys.teku.networking.p2p.discovery.DiscoveryPeer) EnrField(org.ethereum.beacon.discovery.schema.EnrField) InetSocketAddress(java.net.InetSocketAddress) EnrForkId(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.EnrForkId) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil) Test(org.junit.jupiter.api.Test)

Example 5 with DataStructureUtil

use of tech.pegasys.teku.spec.util.DataStructureUtil in project teku by ConsenSys.

the class MetricRecordingValidatorApiChannelTest method getSendDataArguments.

public static Stream<Arguments> getSendDataArguments() {
    final DataStructureUtil dataStructureUtil = new DataStructureUtil(TestSpecFactory.createMinimalAltair());
    final List<SubmitDataError> submissionErrors = List.of(new SubmitDataError(UInt64.ZERO, "Nope"));
    final List<Attestation> attestations = List.of(dataStructureUtil.randomAttestation());
    final List<SyncCommitteeMessage> syncCommitteeMessages = List.of(dataStructureUtil.randomSyncCommitteeMessage());
    final List<SignedAggregateAndProof> aggregateAndProofs = List.of(dataStructureUtil.randomSignedAggregateAndProof());
    return Stream.of(sendDataTest("sendSignedAttestations", channel -> channel.sendSignedAttestations(attestations), MetricRecordingValidatorApiChannel.PUBLISHED_ATTESTATION_COUNTER_NAME, submissionErrors), sendDataTest("sendSyncCommitteeMessages", channel -> channel.sendSyncCommitteeMessages(syncCommitteeMessages), MetricRecordingValidatorApiChannel.SYNC_COMMITTEE_SEND_MESSAGES_NAME, submissionErrors), sendDataTest("sendAggregateAndProofs", channel -> channel.sendAggregateAndProofs(aggregateAndProofs), MetricRecordingValidatorApiChannel.PUBLISHED_AGGREGATE_COUNTER_NAME, submissionErrors));
}
Also used : Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) StubMetricsSystem(tech.pegasys.teku.infrastructure.metrics.StubMetricsSystem) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) Function(java.util.function.Function) SignedAggregateAndProof(tech.pegasys.teku.spec.datastructures.operations.SignedAggregateAndProof) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) AttestationData(tech.pegasys.teku.spec.datastructures.operations.AttestationData) Assertions(org.assertj.core.api.Assertions) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) RequestOutcome(tech.pegasys.teku.validator.beaconnode.metrics.BeaconChainRequestCounter.RequestOutcome) Bytes32(org.apache.tuweni.bytes.Bytes32) GenesisData(tech.pegasys.teku.spec.datastructures.genesis.GenesisData) Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) MethodSource(org.junit.jupiter.params.provider.MethodSource) Collections.emptySet(java.util.Collections.emptySet) BLSSignature(tech.pegasys.teku.bls.BLSSignature) Collections.emptyList(java.util.Collections.emptyList) Mockito.when(org.mockito.Mockito.when) Arguments(org.junit.jupiter.params.provider.Arguments) Consumer(java.util.function.Consumer) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Stream(java.util.stream.Stream) TekuMetricCategory(tech.pegasys.teku.infrastructure.metrics.TekuMetricCategory) TestSpecFactory(tech.pegasys.teku.spec.TestSpecFactory) ValidatorApiChannel(tech.pegasys.teku.validator.api.ValidatorApiChannel) SyncCommitteeMessage(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeMessage) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil) Optional(java.util.Optional) SubmitDataError(tech.pegasys.teku.validator.api.SubmitDataError) Mockito.mock(org.mockito.Mockito.mock) SignedAggregateAndProof(tech.pegasys.teku.spec.datastructures.operations.SignedAggregateAndProof) SubmitDataError(tech.pegasys.teku.validator.api.SubmitDataError) Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) SyncCommitteeMessage(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeMessage) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil)

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