@@ -348,47 +348,6 @@ mod tests {
348348 assert_eq ! ( actual_complete. 0 , expected_complete) ;
349349 }
350350
351- #[ tokio:: test]
352- async fn get_by_head_returns_cached_values_when_cache_is_populated ( ) {
353- let pubkey1 = test_pubkey ( 1 ) ;
354- let validator = test_validator_datum ( 1 , & pubkey1, ValidatorStatus :: ActiveOngoing ) ;
355- let eth2_cl = EthBeaconNodeApiClient :: with_base_url ( "http://0.0.0.0" )
356- . expect ( "Failed to create client" ) ;
357- let cache = ValidatorCache :: new ( eth2_cl, vec ! [ pubkey1. clone( ) ] ) ;
358- {
359- // Manually populate the cache with test data
360- let mut state = cache. 0 . state . lock ( ) . unwrap ( ) ;
361-
362- let mut active_map = HashMap :: new ( ) ;
363- active_map. insert ( 1 , pubkey1) ;
364-
365- let mut complete_map = HashMap :: new ( ) ;
366- complete_map. insert ( 1 , validator. clone ( ) ) ;
367-
368- state. active = Some ( ActiveValidators ( active_map) ) ;
369- state. complete = Some ( CompleteValidators ( complete_map) ) ;
370- } ;
371-
372- let ( active, complete) = cache
373- . get_by_head ( )
374- . await
375- . expect ( "`get_by_head` succeeds when cache is populated" ) ;
376-
377- // Verify the returned active validators
378- {
379- assert_eq ! ( active. len( ) , 1 ) ;
380- assert ! ( active. contains_key( & 1 ) ) ;
381- assert_eq ! ( active. get( & 1 ) , Some ( & pubkey1) ) ;
382- }
383-
384- // Verify the returned complete validators
385- {
386- assert_eq ! ( complete. len( ) , 1 ) ;
387- assert ! ( complete. contains_key( & 1 ) ) ;
388- assert_eq ! ( complete. get( & 1 ) , Some ( & validator) ) ;
389- }
390- }
391-
392351 #[ tokio:: test]
393352 async fn get_by_head_returns_error_when_request_fails ( ) {
394353 // Create a mock server that returns a 404 error
@@ -421,107 +380,6 @@ mod tests {
421380 }
422381 }
423382
424- #[ tokio:: test]
425- async fn get_by_head_populates_cache_on_successful_request ( ) {
426- let pubkey1 = test_pubkey ( 1 ) ;
427- let pubkey2 = test_pubkey ( 2 ) ;
428- let pubkey3 = test_pubkey ( 3 ) ;
429-
430- let datum1 = test_validator_datum ( 1 , & pubkey1, ValidatorStatus :: ActiveOngoing ) ;
431- let datum2 = test_validator_datum ( 2 , & pubkey2, ValidatorStatus :: ActiveExiting ) ;
432- let datum3 = test_validator_datum ( 3 , & pubkey3, ValidatorStatus :: PendingQueued ) ;
433-
434- let validators = vec ! [ datum1. clone( ) , datum2. clone( ) , datum3. clone( ) ] ;
435-
436- // Create a mock server with successful response
437- let mock_server = MockServer :: start ( ) . await ;
438- Mock :: given ( method ( "POST" ) )
439- . and ( path_regex ( r"/eth/v1/beacon/states/head/validators" ) )
440- . respond_with (
441- ResponseTemplate :: new ( 200 ) . set_body_json ( success_response_body ( validators) ) ,
442- )
443- . expect ( 1 )
444- . mount ( & mock_server)
445- . await ;
446-
447- let eth2_cl = EthBeaconNodeApiClient :: with_base_url ( mock_server. uri ( ) )
448- . expect ( "Failed to create client" ) ;
449-
450- let cache = ValidatorCache :: new (
451- eth2_cl,
452- vec ! [ pubkey1. clone( ) , pubkey2. clone( ) , pubkey3. clone( ) ] ,
453- ) ;
454-
455- // Verify cache is initially empty
456- {
457- let state = cache. 0 . state . lock ( ) . unwrap ( ) ;
458- assert ! ( state. active. is_none( ) ) ;
459- assert ! ( state. complete. is_none( ) ) ;
460- }
461-
462- let ( active, complete) = cache. get_by_head ( ) . await . expect ( "`get_by_head` succeeds" ) ;
463-
464- // Verify returned active validators (only active statuses)
465- {
466- assert_eq ! ( active. len( ) , 2 , "Should have 2 active validators" ) ;
467- assert_eq ! ( active. get( & 1 ) , Some ( & pubkey1) ) ;
468- assert_eq ! ( active. get( & 2 ) , Some ( & pubkey2) ) ;
469- }
470-
471- // Verify returned complete validators (all validators)
472- {
473- assert_eq ! ( complete. len( ) , 3 , "Should have 3 complete validators" ) ;
474- assert_eq ! ( complete. get( & 1 ) , Some ( & datum1) ) ;
475- assert_eq ! ( complete. get( & 2 ) , Some ( & datum2) ) ;
476- assert_eq ! ( complete. get( & 3 ) , Some ( & datum3) ) ;
477- }
478-
479- // Verify cache is now populated
480- {
481- let state = cache. 0 . state . lock ( ) . unwrap ( ) ;
482- assert_eq ! ( state. active, Some ( active) ) ;
483- assert_eq ! ( state. complete, Some ( complete) ) ;
484- }
485- }
486-
487- #[ tokio:: test]
488- async fn test_get_by_head_second_call_uses_cache ( ) {
489- let pubkey1 = test_pubkey ( 1 ) ;
490- let datum = test_validator_datum ( 100 , & pubkey1, ValidatorStatus :: ActiveOngoing ) ;
491- let validators = vec ! [ datum] ;
492-
493- // Create a mock server that tracks request count
494- let mock_server = MockServer :: start ( ) . await ;
495- Mock :: given ( method ( "POST" ) )
496- . and ( path_regex ( r"/eth/v1/beacon/states/head/validators" ) )
497- . respond_with (
498- ResponseTemplate :: new ( 200 ) . set_body_json ( success_response_body ( validators) ) ,
499- )
500- . expect ( 1 ) // Should only be called once
501- . mount ( & mock_server)
502- . await ;
503-
504- let eth2_cl = EthBeaconNodeApiClient :: with_base_url ( mock_server. uri ( ) )
505- . expect ( "Failed to create client" ) ;
506-
507- let cache = ValidatorCache :: new ( eth2_cl, vec ! [ pubkey1] ) ;
508-
509- // First call - should hit the server
510- let ( active1, complete1) = cache. get_by_head ( ) . await . expect ( "`get_by_head` succeeds" ) ;
511-
512- // Second call - should use cache (no server request)
513- let ( active2, complete2) = cache. get_by_head ( ) . await . expect ( "``get_by_head` succeeds" ) ;
514-
515- // Both results should be equal, and the same as the cached values
516- assert_eq ! ( active1, active2) ;
517- assert_eq ! ( complete1, complete2) ;
518- {
519- let state = cache. 0 . state . lock ( ) . unwrap ( ) ;
520- assert_eq ! ( state. active, Some ( active1) ) ;
521- assert_eq ! ( state. complete, Some ( complete1) ) ;
522- }
523- }
524-
525383 fn test_pubkey ( seed : u8 ) -> PubKey {
526384 let mut bytes = [ 0u8 ; 48 ] ;
527385 bytes[ 0 ] = seed;
0 commit comments