Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov committed Jul 10, 2023
1 parent 47ebdd1 commit 6f4f6bd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,38 @@
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.SpecMilestone;
import tech.pegasys.teku.spec.SpecVersion;
import tech.pegasys.teku.spec.TestSpecFactory;
import tech.pegasys.teku.spec.datastructures.operations.Attestation;
import tech.pegasys.teku.spec.util.DataStructureUtil;

class AttestationUtilPhase0Test {

private static final SpecVersion SPEC_VERSION =
TestSpecFactory.createMinimalPhase0().forMilestone(SpecMilestone.PHASE0);
private static final Spec SPEC = TestSpecFactory.createMinimalPhase0();

private static final SpecVersion SPEC_VERSION = SPEC.forMilestone(SpecMilestone.PHASE0);

private static final int SECONDS_PER_SLOT = SPEC_VERSION.getConfig().getSecondsPerSlot();

private final DataStructureUtil dataStructureUtil = new DataStructureUtil(SPEC);

private final AttestationUtilPhase0 attestationUtilPhase0 =
(AttestationUtilPhase0) SPEC_VERSION.getAttestationUtil();

@ParameterizedTest
@MethodSource("provideIsFromFarFutureArguments")
public void testIsFromFarFuture(
final int attestationSlot, final UInt64 currentTimeMillis, final boolean expectedResult) {
final Attestation attestation = dataStructureUtil.randomAttestation(attestationSlot);
// set genesisTime as 0 for simplification
final UInt64 genesisTime = UInt64.ZERO;
final boolean actualResult =
attestationUtilPhase0.isFromFarFuture(attestation, genesisTime, currentTimeMillis);
assertThat(actualResult).isEqualTo(expectedResult);
}

@ParameterizedTest
@MethodSource("provideCurrentTimeAfterAttestationPropagationSlotRangeArguments")
public void testIsCurrentTimeAfterAttestationPropagationSlotRange(
Expand All @@ -59,6 +77,15 @@ public void testIsCurrentTimeBeforeMinimumAttestationBroadcastTime(
assertThat(actualResult).isEqualTo(expectedResult);
}

// attestation is fork choice eligible in attestationSlot + 1, MAX_FUTURE_SLOT_ALLOWANCE is 3
private static Stream<Arguments> provideIsFromFarFutureArguments() {
return Stream.of(
Arguments.of(4, getTimeForSlotInMillis(2), false),
Arguments.of(5, getTimeForSlotInMillis(2), true),
Arguments.of(30, getTimeForSlotInMillis(10), true),
Arguments.of(0, getTimeForSlotInMillis(10), false));
}

// ATTESTATION_PROPAGATION_SLOT_RANGE is 32
private static Stream<Arguments>
provideCurrentTimeAfterAttestationPropagationSlotRangeArguments() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -751,8 +751,7 @@ public AttestationData randomAttestationData() {
}

public AttestationData randomAttestationData(final UInt64 slot) {
return new AttestationData(
slot, randomUInt64(), randomBytes32(), randomCheckpoint(), randomCheckpoint());
return randomAttestationData(slot, randomBytes32());
}

public AttestationData randomAttestationData(final UInt64 slot, final Bytes32 blockRoot) {
Expand Down

0 comments on commit 6f4f6bd

Please sign in to comment.