From b468645a166cf57226b364f20fdda21b1527b912 Mon Sep 17 00:00:00 2001 From: courtneyeh Date: Fri, 5 Apr 2024 13:41:53 +1100 Subject: [PATCH] Fix range check --- .../eth2/ActiveEth2P2PNetworkTest.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/ActiveEth2P2PNetworkTest.java b/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/ActiveEth2P2PNetworkTest.java index ea8c8a9ab95..853d2c1b5ca 100644 --- a/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/ActiveEth2P2PNetworkTest.java +++ b/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/ActiveEth2P2PNetworkTest.java @@ -256,17 +256,26 @@ void onSyncStateChanged_shouldNotResultInMultipleSubscriptions() { } @Test - void isCloseToInSync_shouldCalculateDistanceWithSeedWhenFar() { + void isCloseToInSync_shouldCalculateWhenDistanceOutOfRange() { + final UInt64 currentEpoch = storageSystem.combinedChainDataClient().getCurrentEpoch(); + final int distance = + spec.getSpecConfig(currentEpoch).getMaxSeedLookahead() * spec.slotsPerEpoch(currentEpoch); + // Current slot is a long way beyond the chain head - storageSystem.chainUpdater().setCurrentSlot(UInt64.valueOf(50)); + storageSystem.chainUpdater().setCurrentSlot(UInt64.valueOf(distance + 1)); + final boolean closeToInSync = network.isCloseToInSync(); assertThat(closeToInSync).isFalse(); } @Test - void isCloseToInSync_shouldCalculateDistanceWithSeedWhenClose() { + void isCloseToInSync_shouldCalculateWhenDistanceInRange() { + final UInt64 currentEpoch = storageSystem.combinedChainDataClient().getCurrentEpoch(); + final int distance = + spec.getSpecConfig(currentEpoch).getMaxSeedLookahead() * spec.slotsPerEpoch(currentEpoch); + // Current slot is beyond the chain head, but less than maxSeedLookahead distance - storageSystem.chainUpdater().setCurrentSlot(UInt64.valueOf(30)); + storageSystem.chainUpdater().setCurrentSlot(UInt64.valueOf(distance)); final boolean closeToInSync = network.isCloseToInSync(); assertThat(closeToInSync).isTrue(); }