Skip to content

Commit

Permalink
Fix range check
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyeh committed Apr 5, 2024
1 parent 5c18dcf commit b468645
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit b468645

Please sign in to comment.