Skip to content

Commit

Permalink
Test isCloseToInSync method
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyeh committed Apr 5, 2024
1 parent fe1f79b commit 5c18dcf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ public void onSyncStateChanged(final boolean isInSync, final boolean isOptimisti
gossipForkManager.onOptimisticHeadChanged(isOptimistic);
}

private boolean isCloseToInSync() {
@VisibleForTesting
boolean isCloseToInSync() {
final UInt64 currentEpoch = recentChainData.getCurrentEpoch().orElseThrow();
final int maxSeedLookahead = spec.getSpecConfig(currentEpoch).getMaxSeedLookahead();
final int slotsPerEpoch = spec.slotsPerEpoch(currentEpoch);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,22 @@ void onSyncStateChanged_shouldNotResultInMultipleSubscriptions() {
verify(eventChannels, times(1)).subscribe(eq(BlockGossipChannel.class), any());
}

@Test
void isCloseToInSync_shouldCalculateDistanceWithSeedWhenFar() {
// Current slot is a long way beyond the chain head
storageSystem.chainUpdater().setCurrentSlot(UInt64.valueOf(50));
final boolean closeToInSync = network.isCloseToInSync();
assertThat(closeToInSync).isFalse();
}

@Test
void isCloseToInSync_shouldCalculateDistanceWithSeedWhenClose() {
// Current slot is beyond the chain head, but less than maxSeedLookahead distance
storageSystem.chainUpdater().setCurrentSlot(UInt64.valueOf(30));
final boolean closeToInSync = network.isCloseToInSync();
assertThat(closeToInSync).isTrue();
}

@SuppressWarnings("unchecked")
private ArgumentCaptor<Iterable<Integer>> subnetIdCaptor() {
return ArgumentCaptor.forClass(Iterable.class);
Expand Down

0 comments on commit 5c18dcf

Please sign in to comment.