@Test void emptyPoolShouldReturnEmptyList() { OperationStateTransitionValidator<ProposerSlashing> validator = mock(OperationStateTransitionValidator.class); OperationPool<ProposerSlashing> pool = new OperationPool<>(ProposerSlashing.class, validator); when(validator.validate(any(), any())).thenReturn(Optional.empty()); assertThat(pool.getItemsForBlock(state)).isEmpty(); }
public SSZList<T> getItemsForBlock(BeaconState stateAtBlockSlot) { SSZMutableList<T> itemsToPutInBlock = SSZList.createMutable(clazz, MAX_NUMBER_OF_ELEMENTS_IN_BLOCK.get(clazz)); Iterator<T> iter = operations.iterator(); int count = 0; int numberOfElementsToGet = MAX_NUMBER_OF_ELEMENTS_IN_BLOCK.get(clazz); while (count < numberOfElementsToGet && iter.hasNext()) { T item = iter.next(); if (operationValidator.validate(stateAtBlockSlot, item).isEmpty()) { itemsToPutInBlock.add(item); count++; } } return itemsToPutInBlock; }
OperationPool { public SSZList<T> getItemsForBlock(BeaconState stateAtBlockSlot) { SSZMutableList<T> itemsToPutInBlock = SSZList.createMutable(clazz, MAX_NUMBER_OF_ELEMENTS_IN_BLOCK.get(clazz)); Iterator<T> iter = operations.iterator(); int count = 0; int numberOfElementsToGet = MAX_NUMBER_OF_ELEMENTS_IN_BLOCK.get(clazz); while (count < numberOfElementsToGet && iter.hasNext()) { T item = iter.next(); if (operationValidator.validate(stateAtBlockSlot, item).isEmpty()) { itemsToPutInBlock.add(item); count++; } } return itemsToPutInBlock; } }
OperationPool { public SSZList<T> getItemsForBlock(BeaconState stateAtBlockSlot) { SSZMutableList<T> itemsToPutInBlock = SSZList.createMutable(clazz, MAX_NUMBER_OF_ELEMENTS_IN_BLOCK.get(clazz)); Iterator<T> iter = operations.iterator(); int count = 0; int numberOfElementsToGet = MAX_NUMBER_OF_ELEMENTS_IN_BLOCK.get(clazz); while (count < numberOfElementsToGet && iter.hasNext()) { T item = iter.next(); if (operationValidator.validate(stateAtBlockSlot, item).isEmpty()) { itemsToPutInBlock.add(item); count++; } } return itemsToPutInBlock; } OperationPool(Class<T> clazz, OperationStateTransitionValidator<T> operationValidator); }
OperationPool { public SSZList<T> getItemsForBlock(BeaconState stateAtBlockSlot) { SSZMutableList<T> itemsToPutInBlock = SSZList.createMutable(clazz, MAX_NUMBER_OF_ELEMENTS_IN_BLOCK.get(clazz)); Iterator<T> iter = operations.iterator(); int count = 0; int numberOfElementsToGet = MAX_NUMBER_OF_ELEMENTS_IN_BLOCK.get(clazz); while (count < numberOfElementsToGet && iter.hasNext()) { T item = iter.next(); if (operationValidator.validate(stateAtBlockSlot, item).isEmpty()) { itemsToPutInBlock.add(item); count++; } } return itemsToPutInBlock; } OperationPool(Class<T> clazz, OperationStateTransitionValidator<T> operationValidator); SSZList<T> getItemsForBlock(BeaconState stateAtBlockSlot); void add(T item); void addAll(SSZList<T> items); void removeAll(SSZList<T> items); }
OperationPool { public SSZList<T> getItemsForBlock(BeaconState stateAtBlockSlot) { SSZMutableList<T> itemsToPutInBlock = SSZList.createMutable(clazz, MAX_NUMBER_OF_ELEMENTS_IN_BLOCK.get(clazz)); Iterator<T> iter = operations.iterator(); int count = 0; int numberOfElementsToGet = MAX_NUMBER_OF_ELEMENTS_IN_BLOCK.get(clazz); while (count < numberOfElementsToGet && iter.hasNext()) { T item = iter.next(); if (operationValidator.validate(stateAtBlockSlot, item).isEmpty()) { itemsToPutInBlock.add(item); count++; } } return itemsToPutInBlock; } OperationPool(Class<T> clazz, OperationStateTransitionValidator<T> operationValidator); SSZList<T> getItemsForBlock(BeaconState stateAtBlockSlot); void add(T item); void addAll(SSZList<T> items); void removeAll(SSZList<T> items);  }