-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
79d2ba7
commit 47ebdd1
Showing
6 changed files
with
204 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
.../test/java/tech/pegasys/teku/spec/logic/versions/deneb/util/AttestationUtilDenebTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright ConsenSys Software Inc., 2022 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package tech.pegasys.teku.spec.logic.versions.deneb.util; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static tech.pegasys.teku.infrastructure.time.TimeUtilities.secondsToMillis; | ||
|
||
import java.util.stream.Stream; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
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.SpecMilestone; | ||
import tech.pegasys.teku.spec.SpecVersion; | ||
import tech.pegasys.teku.spec.TestSpecFactory; | ||
|
||
public class AttestationUtilDenebTest { | ||
|
||
private static final SpecVersion SPEC_VERSION = | ||
TestSpecFactory.createMinimalDeneb().forMilestone(SpecMilestone.DENEB); | ||
|
||
private static final int SECONDS_PER_SLOT = SPEC_VERSION.getConfig().getSecondsPerSlot(); | ||
|
||
private final AttestationUtilDeneb attestationUtilDeneb = | ||
(AttestationUtilDeneb) SPEC_VERSION.getAttestationUtil(); | ||
|
||
@ParameterizedTest | ||
@MethodSource("provideAttestationSlotInCurrentOrPreviousEpochArguments") | ||
public void testAttestationSlotInCurrentOrPreviousEpoch( | ||
final int attestationSlot, final UInt64 currentTime, final boolean expectedResult) { | ||
final UInt64 currentTimeMillis = secondsToMillis(currentTime); | ||
// set genesisTime as 0 for simplification | ||
final UInt64 genesisTime = UInt64.ZERO; | ||
final boolean actualResult = | ||
attestationUtilDeneb.isAttestationSlotInCurrentOrPreviousEpoch( | ||
UInt64.valueOf(attestationSlot), genesisTime, currentTimeMillis); | ||
assertThat(actualResult).isEqualTo(expectedResult); | ||
} | ||
|
||
// minimal is 6 seconds per slot, 8 slots per epoch | ||
private static Stream<Arguments> provideAttestationSlotInCurrentOrPreviousEpochArguments() { | ||
return Stream.of( | ||
Arguments.of(6, getTimeForSlot(10), true), | ||
Arguments.of(6, getTimeForSlot(3), true), | ||
Arguments.of(6, getTimeForSlot(26), false), | ||
Arguments.of(10, getTimeForSlot(6), false), | ||
// testing MAXIMUM_GOSSIP_CLOCK_DISPARITY | ||
// current time is in epoch 3 and attestation slot is in the last slot of epoch 1 | ||
Arguments.of(7, getTimeForSlot(22), true), | ||
// current time is in epoch 1 and attestation slot is in the first slot of epoch 2 | ||
Arguments.of(17, getTimeForSlot(10), true)); | ||
} | ||
|
||
private static UInt64 getTimeForSlot(final int slot) { | ||
return UInt64.valueOf(slot).times(SECONDS_PER_SLOT); | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
...est/java/tech/pegasys/teku/spec/logic/versions/phase0/util/AttestationUtilPhase0Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Copyright ConsenSys Software Inc., 2022 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package tech.pegasys.teku.spec.logic.versions.phase0.util; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static tech.pegasys.teku.infrastructure.time.TimeUtilities.secondsToMillis; | ||
|
||
import java.util.stream.Stream; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
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.SpecMilestone; | ||
import tech.pegasys.teku.spec.SpecVersion; | ||
import tech.pegasys.teku.spec.TestSpecFactory; | ||
|
||
class AttestationUtilPhase0Test { | ||
|
||
private static final SpecVersion SPEC_VERSION = | ||
TestSpecFactory.createMinimalPhase0().forMilestone(SpecMilestone.PHASE0); | ||
|
||
private static final int SECONDS_PER_SLOT = SPEC_VERSION.getConfig().getSecondsPerSlot(); | ||
|
||
private final AttestationUtilPhase0 attestationUtilPhase0 = | ||
(AttestationUtilPhase0) SPEC_VERSION.getAttestationUtil(); | ||
|
||
@ParameterizedTest | ||
@MethodSource("provideCurrentTimeAfterAttestationPropagationSlotRangeArguments") | ||
public void testIsCurrentTimeAfterAttestationPropagationSlotRange( | ||
final int attestationSlot, final UInt64 currentTimeMillis, final boolean expectedResult) { | ||
// set genesisTime as 0 for simplification | ||
final UInt64 genesisTime = UInt64.ZERO; | ||
final boolean actualResult = | ||
attestationUtilPhase0.isCurrentTimeAfterAttestationPropagationSlotRange( | ||
UInt64.valueOf(attestationSlot), genesisTime, currentTimeMillis); | ||
assertThat(actualResult).isEqualTo(expectedResult); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("provideCurrentTimeBeforeMinimumAttestationBroadcastTimeArguments") | ||
public void testIsCurrentTimeBeforeMinimumAttestationBroadcastTime( | ||
final int attestationSlot, final UInt64 currentTimeMillis, final boolean expectedResult) { | ||
// set genesisTime as 0 for simplification | ||
final UInt64 genesisTime = UInt64.ZERO; | ||
final boolean actualResult = | ||
attestationUtilPhase0.isCurrentTimeBeforeMinimumAttestationBroadcastTime( | ||
UInt64.valueOf(attestationSlot), genesisTime, currentTimeMillis); | ||
assertThat(actualResult).isEqualTo(expectedResult); | ||
} | ||
|
||
// ATTESTATION_PROPAGATION_SLOT_RANGE is 32 | ||
private static Stream<Arguments> | ||
provideCurrentTimeAfterAttestationPropagationSlotRangeArguments() { | ||
return Stream.of( | ||
Arguments.of(0, getTimeForSlotInMillis(34), true), | ||
Arguments.of(0, getTimeForSlotInMillis(32), false), | ||
Arguments.of(12, getTimeForSlotInMillis(26), false), | ||
Arguments.of(12, getTimeForSlotInMillis(46), true), | ||
// testing MAXIMUM_GOSSIP_CLOCK_DISPARITY | ||
Arguments.of(12, getTimeForSlotInMillis(45).plus(500), false), | ||
Arguments.of(12, getTimeForSlotInMillis(45).plus(501), true)); | ||
} | ||
|
||
private static Stream<Arguments> | ||
provideCurrentTimeBeforeMinimumAttestationBroadcastTimeArguments() { | ||
return Stream.of( | ||
Arguments.of(0, UInt64.ZERO, false), | ||
Arguments.of(8, getTimeForSlotInMillis(7), true), | ||
Arguments.of(7, getTimeForSlotInMillis(8), false), | ||
// testing MAXIMUM_GOSSIP_CLOCK_DISPARITY | ||
Arguments.of(7, getTimeForSlotInMillis(7).minus(501), true), | ||
Arguments.of(7, getTimeForSlotInMillis(7).minus(500), false)); | ||
} | ||
|
||
private static UInt64 getTimeForSlotInMillis(final int slot) { | ||
return secondsToMillis(UInt64.valueOf(slot).times(SECONDS_PER_SLOT)); | ||
} | ||
} |