Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdi-aouadi committed Aug 1, 2024
1 parent 5d70c3b commit fdc8a57
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ public SafeFuture<Optional<ObjectAndMetaData<Attestation>>> createAggregate(
attestation,
spec.atSlot(attestation.getData().getSlot()).getMilestone(),
false,
true,
false,
false)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -717,17 +717,18 @@ public void createSyncCommitteeContribution() {
@Test
public void createAggregate_shouldReturnAggregateFromAttestationPool() {
final AttestationData attestationData = dataStructureUtil.randomAttestationData();
final Optional<Attestation> aggregate = Optional.of(dataStructureUtil.randomAttestation());
final Attestation aggregate = dataStructureUtil.randomAttestation();
when(attestationPool.createAggregateFor(
eq(attestationData.hashTreeRoot()), eq(Optional.empty())))
.thenReturn(aggregate.map(attestation -> ValidatableAttestation.from(spec, attestation)));
.thenReturn(Optional.of(ValidatableAttestation.from(spec, aggregate)));

assertThat(
validatorApiHandler.createAggregate(
aggregate.get().getData().getSlot(),
attestationData.hashTreeRoot(),
Optional.empty()))
.isCompletedWithValue(aggregate);
aggregate.getData().getSlot(), attestationData.hashTreeRoot(), Optional.empty()))
.isCompletedWithValue(
Optional.of(
new ObjectAndMetaData<>(
aggregate, spec.getGenesisSpec().getMilestone(), false, false, false)));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import tech.pegasys.teku.beaconrestapi.AbstractMigratedBeaconHandlerTest;
import tech.pegasys.teku.infrastructure.async.SafeFuture;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.datastructures.metadata.ObjectAndMetaData;
import tech.pegasys.teku.spec.datastructures.operations.Attestation;

class GetAggregateAttestationTest extends AbstractMigratedBeaconHandlerTest {
Expand All @@ -52,7 +53,11 @@ public void shouldReturnAttestationInformation() throws JsonProcessingException
Attestation attestation = dataStructureUtil.randomAttestation();
when(validatorDataProvider.createAggregate(
eq(UInt64.valueOf(1)), eq(attestationDataRoot), eq(Optional.empty())))
.thenReturn(SafeFuture.completedFuture(Optional.of(attestation)));
.thenReturn(
SafeFuture.completedFuture(
Optional.of(
new ObjectAndMetaData<>(
attestation, spec.getGenesisSpec().getMilestone(), false, false, false))));

handler.handleRequest(request);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@
import tech.pegasys.teku.infrastructure.metrics.StubMetricsSystem;
import tech.pegasys.teku.infrastructure.metrics.TekuMetricCategory;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.SpecMilestone;
import tech.pegasys.teku.spec.TestSpecFactory;
import tech.pegasys.teku.spec.datastructures.genesis.GenesisData;
import tech.pegasys.teku.spec.datastructures.metadata.ObjectAndMetaData;
import tech.pegasys.teku.spec.datastructures.operations.Attestation;
import tech.pegasys.teku.spec.datastructures.operations.AttestationData;
import tech.pegasys.teku.spec.datastructures.operations.SignedAggregateAndProof;
Expand Down Expand Up @@ -208,7 +210,8 @@ public static Stream<Arguments> getDataRequestArguments() {
channel.createAggregate(
attestationData.getSlot(), attestationData.hashTreeRoot(), Optional.empty()),
BeaconNodeRequestLabels.CREATE_AGGREGATE_METHOD,
dataStructureUtil.randomAttestation()),
new ObjectAndMetaData<>(
dataStructureUtil.randomAttestation(), SpecMilestone.PHASE0, false, false, false)),
requestDataTest(
"createSyncCommitteeContribution",
channel ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import tech.pegasys.teku.spec.datastructures.builder.SignedValidatorRegistration;
import tech.pegasys.teku.spec.datastructures.genesis.GenesisData;
import tech.pegasys.teku.spec.datastructures.metadata.BlockContainerAndMetaData;
import tech.pegasys.teku.spec.datastructures.metadata.ObjectAndMetaData;
import tech.pegasys.teku.spec.datastructures.operations.Attestation;
import tech.pegasys.teku.spec.datastructures.operations.AttestationData;
import tech.pegasys.teku.spec.datastructures.operations.SignedAggregateAndProof;
Expand Down Expand Up @@ -699,7 +700,9 @@ private static Stream<Arguments> getRequestsUsingFailover() {
"createAggregate",
apiChannel -> apiChannel.createAggregate(slot, randomBytes32, Optional.empty()),
BeaconNodeRequestLabels.CREATE_AGGREGATE_METHOD,
Optional.of(attestation)),
Optional.of(
new ObjectAndMetaData<>(
attestation, SPEC.atSlot(slot).getMilestone(), false, false, false))),
getArguments(
"createSyncCommitteeContribution",
apiChannel -> apiChannel.createSyncCommitteeContribution(slot, 0, randomBytes32),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
import tech.pegasys.teku.spec.datastructures.builder.SignedValidatorRegistration;
import tech.pegasys.teku.spec.datastructures.genesis.GenesisData;
import tech.pegasys.teku.spec.datastructures.metadata.BlockContainerAndMetaData;
import tech.pegasys.teku.spec.datastructures.metadata.ObjectAndMetaData;
import tech.pegasys.teku.spec.datastructures.operations.AggregateAndProof;
import tech.pegasys.teku.spec.datastructures.operations.Attestation;
import tech.pegasys.teku.spec.datastructures.operations.AttestationData;
Expand Down Expand Up @@ -621,7 +622,7 @@ public void createAggregate_WhenNotFound_ReturnsEmpty() {

when(apiClient.createAggregate(eq(slot), eq(attHashTreeRoot))).thenReturn(Optional.empty());

SafeFuture<Optional<Attestation>> future =
SafeFuture<Optional<ObjectAndMetaData<Attestation>>> future =
apiHandler.createAggregate(slot, attHashTreeRoot, Optional.of(ONE));

assertThat(unwrapToOptional(future)).isEmpty();
Expand All @@ -639,10 +640,10 @@ public void createAggregate_WhenFound_ReturnsAttestation() {
when(apiClient.createAggregate(eq(slot), eq(attHashTreeRoot)))
.thenReturn(Optional.of(schemaAttestation));

SafeFuture<Optional<Attestation>> future =
SafeFuture<Optional<ObjectAndMetaData<Attestation>>> future =
apiHandler.createAggregate(slot, attHashTreeRoot, Optional.of(ONE));

assertThatSszData(unwrapToValue(future)).isEqualByAllMeansTo(attestation);
assertThatSszData(unwrapToValue(future).getData()).isEqualByAllMeansTo(attestation);
}

@Test
Expand Down

0 comments on commit fdc8a57

Please sign in to comment.