@@ -81,6 +81,10 @@ public class ActiveEth2P2PNetworkTest {
81
81
private Fork altairFork ;
82
82
private Bytes32 genesisValidatorsRoot ;
83
83
84
+ private final int maxFollowDistanceSlots =
85
+ spec .getGenesisSpecConfig ().getMaxSeedLookahead ()
86
+ * spec .slotsPerEpoch (storageSystem .combinedChainDataClient ().getCurrentEpoch ());
87
+
84
88
@ BeforeEach
85
89
public void setup () {
86
90
when (discoveryNetwork .start ()).thenReturn (SafeFuture .completedFuture (null ));
@@ -255,6 +259,41 @@ void onSyncStateChanged_shouldNotResultInMultipleSubscriptions() {
255
259
verify (eventChannels , times (1 )).subscribe (eq (BlockGossipChannel .class ), any ());
256
260
}
257
261
262
+ @ Test
263
+ void isCloseToInSync_shouldCalculateWhenDistanceOutOfRange () {
264
+ storageSystem .chainUpdater ().setCurrentSlot (UInt64 .valueOf (maxFollowDistanceSlots + 1 ));
265
+ assertThat (network .isCloseToInSync ()).isFalse ();
266
+ }
267
+
268
+ @ Test
269
+ void isCloseToInSync_shouldCalculateWhenDistanceInRange () {
270
+ storageSystem .chainUpdater ().setCurrentSlot (UInt64 .valueOf (maxFollowDistanceSlots ));
271
+ assertThat (network .isCloseToInSync ()).isTrue ();
272
+ }
273
+
274
+ @ Test
275
+ void isCloseToInSync_shouldReturnFalseWhenEmptyCurrentEpoch () {
276
+ final StorageSystem storageSystem = InMemoryStorageSystemBuilder .buildDefault ();
277
+ final RecentChainData recentChainData = storageSystem .recentChainData ();
278
+ final ActiveEth2P2PNetwork network =
279
+ new ActiveEth2P2PNetwork (
280
+ spec ,
281
+ asyncRunner ,
282
+ discoveryNetwork ,
283
+ peerManager ,
284
+ gossipForkManager ,
285
+ eventChannels ,
286
+ recentChainData ,
287
+ attestationSubnetService ,
288
+ syncCommitteeSubnetService ,
289
+ gossipEncoding ,
290
+ gossipConfigurator ,
291
+ processedAttestationSubscriptionProvider ,
292
+ true );
293
+
294
+ assertThat (network .isCloseToInSync ()).isFalse ();
295
+ }
296
+
258
297
@ SuppressWarnings ("unchecked" )
259
298
private ArgumentCaptor <Iterable <Integer >> subnetIdCaptor () {
260
299
return ArgumentCaptor .forClass (Iterable .class );
0 commit comments