Skip to content

Commit

Permalink
fixed message for stateTooOldException
Browse files Browse the repository at this point in the history
I think the slot too old message was incorrect which is why it sometimes didnt make a lot of sense. added a test case too.

Signed-off-by: Paul Harris <[email protected]>
  • Loading branch information
rolfyone committed Mar 6, 2025
1 parent 9fd1641 commit 8416bda
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ public void validateStateForCommitteeQuery(final BeaconState state, final UInt64
final UInt64 oldestQueryableSlot =
miscHelpers.getEarliestQueryableSlotForBeaconCommitteeAtTargetSlot(slot);
if (state.getSlot().compareTo(oldestQueryableSlot) < 0) {
throw new StateTooOldException(slot, oldestQueryableSlot);
throw new StateTooOldException(state.getSlot(), oldestQueryableSlot);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@

import it.unimi.dsi.fastutil.ints.Int2IntMap;
import it.unimi.dsi.fastutil.ints.IntList;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.SpecVersion;
Expand Down Expand Up @@ -64,6 +68,31 @@ void succeedsWhenGetPreviousSlotReturnsGenesisSlotPlusOne() {
assertEquals(GENESIS_EPOCH.increment(), beaconStateAccessors.getPreviousEpoch(beaconState));
}

public static Stream<Arguments> validateStateForCommitteeQueryParams() {
return Stream.of(
Arguments.of(8, 15, false),
Arguments.of(21, 15, false),
Arguments.of(2, 15, false),
Arguments.of(7, 16, true));
}

@ParameterizedTest
@MethodSource("validateStateForCommitteeQueryParams")
void validateStateForCommitteeQuery(
final long stateSlot, final long querySlotLong, final boolean shouldThrow) {
final UInt64 slot = UInt64.valueOf(stateSlot);
final UInt64 querySlot = UInt64.valueOf(querySlotLong);
final BeaconState state = dataStructureUtil.randomBeaconState(slot);
if (shouldThrow) {
assertThatThrownBy(
() -> beaconStateAccessors.validateStateForCommitteeQuery(state, querySlot))
.isInstanceOf(StateTooOldException.class);
} else {
assertDoesNotThrow(
() -> beaconStateAccessors.validateStateForCommitteeQuery(state, querySlot));
}
}

@Test
void getTotalBalanceAddsAndReturnsEffectiveTotalBalancesCorrectly() {
// Data Setup
Expand Down

0 comments on commit 8416bda

Please sign in to comment.