Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov committed Apr 4, 2024
1 parent 58da8af commit f6852dd
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@ public class ValidatorIndexCacheTest {
@SuppressWarnings("unchecked")
final Cache<BLSPublicKey, Integer> cache = mock(Cache.class);

@Test
public void shouldReturnEmptyIfValidatorIndexIsNotConsistentWithNumberOfValidatorsInState() {
final SszList<Validator> validators = state.getValidators();
final int latestFinalizedIndex = NUMBER_OF_VALIDATORS - 1;
final ValidatorIndexCache validatorIndexCache = new ValidatorIndexCache();
validatorIndexCache.updateLatestFinalizedIndex(state);

final BLSPublicKey publicKey = validators.get(latestFinalizedIndex).getPublicKey();
// cache eagerly the last validator public key
validatorIndexCache.invalidateWithNewValue(publicKey, latestFinalizedIndex);

// state with one less validator
final BeaconState state = dataStructureUtil.randomBeaconState(NUMBER_OF_VALIDATORS - 1);

Check notice

Code scanning / CodeQL

Possible confusion of local and field Note test

Confusing name: method
shouldReturnEmptyIfValidatorIndexIsNotConsistentWithNumberOfValidatorsInState
also refers to field
state
(without qualifying it with 'this').

assertThat(validatorIndexCache.getValidatorIndex(state, publicKey)).isEmpty();
}

@Test
public void shouldScanFinalizedStateAndCache() {
final SszList<Validator> validators = state.getValidators();
Expand Down

0 comments on commit f6852dd

Please sign in to comment.